-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add photos to items and start the relations
- Loading branch information
Showing
15 changed files
with
259 additions
and
34 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
<?php | ||
|
||
namespace App\Models; | ||
|
||
use Illuminate\Database\Eloquent\Factories\HasFactory; | ||
use Illuminate\Database\Eloquent\Model; | ||
/** | ||
* @property string name | ||
* @property string description | ||
*/ | ||
class Attribute extends Model | ||
{ | ||
use HasFactory; | ||
public function items() | ||
{ | ||
return $this->belongsToMany(Item::class, 'attribute_items'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
<?php | ||
|
||
namespace App\Models; | ||
|
||
use Illuminate\Database\Eloquent\Factories\HasFactory; | ||
use Illuminate\Database\Eloquent\Model; | ||
use Illuminate\Database\Eloquent\Relations\BelongsTo; | ||
use Illuminate\Database\Eloquent\Relations\BelongsToMany; | ||
use Illuminate\Database\Eloquent\Relations\HasMany; | ||
|
||
/** | ||
* @property string title | ||
* @property HasMany item | ||
* @property BelongsToMany attributes | ||
*/ | ||
class Controller extends Model | ||
{ | ||
use HasFactory; | ||
|
||
protected $fillable = ['title']; | ||
public function item(): BelongsTo | ||
{ | ||
return $this->belongsTo(HasMany::class, 'item_id'); | ||
} | ||
|
||
public function attributes(): BelongsToMany | ||
{ | ||
return $this->belongsToMany(Attribute::class, 'attribute_controllers'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
namespace Database\Factories; | ||
|
||
use App\Models\Attribute; | ||
use Illuminate\Database\Eloquent\Factories\Factory; | ||
use Illuminate\Support\Carbon; | ||
|
||
class AttributeFactory extends Factory | ||
{ | ||
protected $model = Attribute::class; | ||
|
||
public function definition(): array | ||
{ | ||
return [ | ||
'created_at' => Carbon::now(), | ||
'updated_at' => Carbon::now(), | ||
'name' => $this->faker->name(), | ||
'description' => $this->faker->text(), | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,22 @@ | ||
<?php | ||
|
||
namespace Database\Factories; | ||
|
||
use App\Models\Controller; | ||
use Illuminate\Database\Eloquent\Factories\Factory; | ||
use Illuminate\Support\Carbon; | ||
|
||
class ControllerFactory extends Factory | ||
{ | ||
protected $model = Controller::class; | ||
|
||
public function definition(): array | ||
{ | ||
return [ | ||
'created_at' => Carbon::now(), | ||
'updated_at' => Carbon::now(), | ||
'Name' => $this->faker->name(), | ||
'item_id' => $this->faker->randomNumber(), | ||
]; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
23 changes: 23 additions & 0 deletions
23
database/migrations/2024_05_29_081709_create_controllers_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
return new class extends Migration { | ||
public function up(): void | ||
{ | ||
Schema::create('controllers', function (Blueprint $table) { | ||
$table->id(); | ||
$table->string('name'); | ||
$table->text('description'); | ||
$table->foreignId('item_id'); | ||
$table->timestamps(); | ||
}); | ||
} | ||
|
||
public function down(): void | ||
{ | ||
Schema::dropIfExists('controllers'); | ||
} | ||
}; |
40 changes: 40 additions & 0 deletions
40
database/migrations/2024_05_29_082156_create_attributes_table.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
<?php | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
|
||
return new class extends Migration { | ||
public function up(): void | ||
{ | ||
Schema::create('attributes', function (Blueprint $table) { | ||
$table->id(); | ||
$table->string('name'); | ||
$table->string('description'); | ||
$table->timestamps(); | ||
}); | ||
|
||
//add new pivot table called attribute_items | ||
Schema::create('attribute_items', function (Blueprint $table) { | ||
$table->id(); | ||
$table->foreignId('attribute_id'); | ||
$table->foreignId('item_id'); | ||
$table->timestamps(); | ||
}); | ||
|
||
//add a new pivot table called attribute_controllers | ||
Schema::create('attribute_controllers', function (Blueprint $table) { | ||
$table->id(); | ||
$table->foreignId('attribute_id'); | ||
$table->foreignId('controller_id'); | ||
$table->timestamps(); | ||
}); | ||
} | ||
|
||
public function down(): void | ||
{ | ||
Schema::dropIfExists('attributes'); | ||
Schema::dropIfExists('attribute_items'); | ||
Schema::dropIfExists('attribute_controllers'); | ||
} | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ | |
|
||
namespace Database\Seeders; | ||
|
||
use App\Models\Item; | ||
use App\Models\User; | ||
// use Illuminate\Database\Console\Seeds\WithoutModelEvents; | ||
use Illuminate\Database\Seeder; | ||
|
@@ -19,5 +20,11 @@ public function run(): void | |
'name' => 'Test User', | ||
'email' => '[email protected]', | ||
]); | ||
|
||
Item::create([ | ||
'name' => 'Item 1', | ||
'description' => 'This is item 1', | ||
'is_actuator' => false, | ||
]); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.