Device factory, repository

This commit is contained in:
Romano Schoonheim 2021-01-07 10:45:25 -08:00
parent 1d6c509982
commit f8c1421bdd
6 changed files with 107 additions and 0 deletions

View 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
]);
}
}

View 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
View 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'];
}

View 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 [
//
];
}
}

View File

@ -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');
}
}