Revize 344b1e53
Přidáno uživatelem Marek Zábran před asi 5 roky(ů)
app/Artefact.php | ||
---|---|---|
1 |
<?php |
|
2 | ||
3 |
namespace App; |
|
4 | ||
5 |
use Illuminate\Database\Eloquent\Model; |
|
6 | ||
7 |
class Artefact extends Model |
|
8 |
{ |
|
9 |
// Table Name |
|
10 |
protected $table = 'artafacts';//unnecessery? |
|
11 |
// Primary Key |
|
12 |
public $primaryKey = 'id';//unnecessery? |
|
13 | ||
14 |
/** |
|
15 |
* The model's default values for attributes. |
|
16 |
* |
|
17 |
* @var array |
|
18 |
*/ |
|
19 |
protected $attributes = [ |
|
20 |
'likes' => 0, |
|
21 |
]; |
|
22 | ||
23 |
/** |
|
24 |
* Indicates if the model should be timestamped. |
|
25 |
* |
|
26 |
* @var bool |
|
27 |
*/ |
|
28 |
public $timestamps = false; |
|
29 | ||
30 |
/** |
|
31 |
* Get the metadata for the artefact. |
|
32 |
*/ |
|
33 |
public function metadata() |
|
34 |
{ |
|
35 |
return $this->hasMany('App\Metadata'); |
|
36 |
} |
|
37 | ||
38 |
/** |
|
39 |
* Get the categories for the artefact. |
|
40 |
*/ |
|
41 |
public function categories() |
|
42 |
{ |
|
43 |
return $this->belongsToMany('App\Category'); |
|
44 |
} |
|
45 | ||
46 | ||
47 | ||
48 | ||
49 |
} |
app/Category.php | ||
---|---|---|
1 |
<?php |
|
2 | ||
3 |
namespace App; |
|
4 | ||
5 |
use Illuminate\Database\Eloquent\Model; |
|
6 | ||
7 |
class Category extends Model |
|
8 |
{ |
|
9 |
// Table Name |
|
10 |
protected $table = 'categories'; |
|
11 |
// Primary Key |
|
12 |
public $primaryKey = 'id';//unnecessery? |
|
13 | ||
14 | ||
15 |
/** |
|
16 |
* Indicates if the model should be timestamped. |
|
17 |
* |
|
18 |
* @var bool |
|
19 |
*/ |
|
20 |
public $timestamps = false; |
|
21 | ||
22 |
/** |
|
23 |
* Get the artefacts for the catagory. |
|
24 |
*/ |
|
25 |
public function atrefacts() |
|
26 |
{ |
|
27 |
return $this->belongsToMany('App\Artefact'); |
|
28 |
} |
|
29 | ||
30 | ||
31 |
} |
app/Metadata.php | ||
---|---|---|
1 |
<?php |
|
2 | ||
3 |
namespace App; |
|
4 | ||
5 |
use Illuminate\Database\Eloquent\Model; |
|
6 | ||
7 |
class Metadata extends Model |
|
8 |
{ |
|
9 |
// Table Name |
|
10 |
protected $table = 'metadata';//same name could make problems |
|
11 |
// Primary Key |
|
12 |
public $primaryKey = 'id';//unnecessery? |
|
13 | ||
14 |
/** |
|
15 |
* The model's default values for attributes. |
|
16 |
* |
|
17 |
* @var array |
|
18 |
*/ |
|
19 |
protected $attributes = [ |
|
20 |
'likes' => 0, |
|
21 |
]; |
|
22 | ||
23 |
/** |
|
24 |
* Indicates if the model should be timestamped. |
|
25 |
* |
|
26 |
* @var bool |
|
27 |
*/ |
|
28 |
public $timestamps = false; |
|
29 | ||
30 |
/** |
|
31 |
* Get the artafact for this single metadata. |
|
32 |
*/ |
|
33 |
public function artefact(){ |
|
34 |
return $this->belongsTo('App\Artefact'); |
|
35 |
} |
|
36 | ||
37 | ||
38 |
} |
database/migrations/CreateArtefactsTable.php | ||
---|---|---|
1 |
<?php |
|
2 | ||
3 |
use Illuminate\Database\Migrations\Migration; |
|
4 |
use Illuminate\Database\Schema\Blueprint; |
|
5 |
use Illuminate\Support\Facades\Schema; |
|
6 | ||
7 |
class CreateArtefactsTable extends Migration |
|
8 |
{ |
|
9 |
/** |
|
10 |
* Run the migrations. |
|
11 |
* |
|
12 |
* @return void |
|
13 |
*/ |
|
14 |
public function up() |
|
15 |
{ |
|
16 |
Schema::create('artefacts', function (Blueprint $table) { |
|
17 |
$table->id(); |
|
18 |
$table->string('name'); |
|
19 |
$table->string('author'); |
|
20 |
$table->string('made_in'); |
|
21 |
$table->string('publisher'); |
|
22 |
$table->integer('year'); |
|
23 |
$table->integer('pages'); |
|
24 |
$table->integer('likes'); |
|
25 |
}); |
|
26 |
} |
|
27 | ||
28 |
/** |
|
29 |
* Reverse the migrations. |
|
30 |
* |
|
31 |
* @return void |
|
32 |
*/ |
|
33 |
public function down() |
|
34 |
{ |
|
35 |
Schema::dropIfExists('artefacts'); |
|
36 |
} |
|
37 |
} |
database/migrations/CreateCategoryTable.php | ||
---|---|---|
1 |
<?php |
|
2 | ||
3 |
use Illuminate\Database\Migrations\Migration; |
|
4 |
use Illuminate\Database\Schema\Blueprint; |
|
5 |
use Illuminate\Support\Facades\Schema; |
|
6 | ||
7 |
class CreateCategoryTable extends Migration |
|
8 |
{ |
|
9 |
/** |
|
10 |
* Run the migrations. |
|
11 |
* |
|
12 |
* @return void |
|
13 |
*/ |
|
14 |
public function up() |
|
15 |
{ |
|
16 |
Schema::create('categories', function (Blueprint $table) { |
|
17 |
$table->id(); |
|
18 | ||
19 |
$table->string('nameCZ'); |
|
20 |
$table->string('nameEN'); |
|
21 |
}); |
|
22 |
} |
|
23 | ||
24 |
/** |
|
25 |
* Reverse the migrations. |
|
26 |
* |
|
27 |
* @return void |
|
28 |
*/ |
|
29 |
public function down() |
|
30 |
{ |
|
31 |
Schema::dropIfExists('categories'); |
|
32 |
} |
|
33 |
} |
database/migrations/CreateMetadataTable.php | ||
---|---|---|
1 |
<?php |
|
2 | ||
3 |
use Illuminate\Database\Migrations\Migration; |
|
4 |
use Illuminate\Database\Schema\Blueprint; |
|
5 |
use Illuminate\Support\Facades\Schema; |
|
6 | ||
7 |
class CreateMetadataTable extends Migration |
|
8 |
{ |
|
9 |
/** |
|
10 |
* Run the migrations. |
|
11 |
* |
|
12 |
* @return void |
|
13 |
*/ |
|
14 |
public function up() |
|
15 |
{ |
|
16 |
Schema::create('metadata', function (Blueprint $table) { |
|
17 |
$table->id(); |
|
18 |
$table->integer('artefact_id')->unsigned(); |
|
19 |
$table->foreign('artefact_id')->references('id')->on('artefacts'); |
|
20 | ||
21 |
$table->string('name'); |
|
22 |
$table->longText('noteCZ'); |
|
23 |
$table->longText('noteEN'); |
|
24 | ||
25 |
$table->integer('page'); |
|
26 |
$table->integer('likes'); |
|
27 |
}); |
|
28 |
} |
|
29 | ||
30 |
/** |
|
31 |
* Reverse the migrations. |
|
32 |
* |
|
33 |
* @return void |
|
34 |
*/ |
|
35 |
public function down() |
|
36 |
{ |
|
37 |
Schema::dropIfExists('metadata'); |
|
38 |
} |
|
39 |
} |
Také k dispozici: Unified diff
Vytvoření datového a objektového modelu. Netestováno!
Issue #7692 @2