Device factory, repository
This commit is contained in:
parent
1d6c509982
commit
f8c1421bdd
21
app/Domain/Device/Factories/DeviceFactory.php
Normal file
21
app/Domain/Device/Factories/DeviceFactory.php
Normal file
@ -0,0 +1,21 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Device\Factories;
|
||||
|
||||
use App\Models\Device;
|
||||
|
||||
/**
|
||||
* Class DeviceFactory
|
||||
* @package App\Domain\Device\Factories
|
||||
*/
|
||||
class DeviceFactory
|
||||
{
|
||||
public function create(string $name, ?string $description = null): Device
|
||||
{
|
||||
return Device::create([
|
||||
'name' => $name,
|
||||
'description' => $description
|
||||
]);
|
||||
}
|
||||
|
||||
}
|
12
app/Domain/Device/Repositories/DeviceRepository.php
Normal file
12
app/Domain/Device/Repositories/DeviceRepository.php
Normal file
@ -0,0 +1,12 @@
|
||||
<?php
|
||||
|
||||
namespace App\Domain\Device\Repositories;
|
||||
|
||||
/**
|
||||
* Class DeviceRepository
|
||||
* @package App\Domain\Device\Repositories
|
||||
*/
|
||||
class DeviceRepository
|
||||
{
|
||||
|
||||
}
|
13
app/Models/Device.php
Normal file
13
app/Models/Device.php
Normal file
@ -0,0 +1,13 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Device extends Model
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
protected $fillable = ['name', 'description'];
|
||||
}
|
28
database/factories/DeviceFactory.php
Normal file
28
database/factories/DeviceFactory.php
Normal file
@ -0,0 +1,28 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use App\Models\Device;
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
class DeviceFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* The name of the factory's corresponding model.
|
||||
*
|
||||
* @var string
|
||||
*/
|
||||
protected $model = Device::class;
|
||||
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array
|
||||
*/
|
||||
public function definition()
|
||||
{
|
||||
return [
|
||||
//
|
||||
];
|
||||
}
|
||||
}
|
@ -0,0 +1,33 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateDevicesTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('devices', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string('name')->unique();
|
||||
$table->string('description')->nullable();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('devices');
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user