Browse Source

Device factory, repository

3.0
Romano Schoonheim 1 year ago
parent
commit
f8c1421bdd
6 changed files with 107 additions and 0 deletions
  1. +21
    -0
      app/Domain/Device/Factories/DeviceFactory.php
  2. +0
    -0
      app/Domain/Device/Repositories/.gitkeep
  3. +12
    -0
      app/Domain/Device/Repositories/DeviceRepository.php
  4. +13
    -0
      app/Models/Device.php
  5. +28
    -0
      database/factories/DeviceFactory.php
  6. +33
    -0
      database/migrations/2021_01_07_184250_create_devices_table.php

+ 21
- 0
app/Domain/Device/Factories/DeviceFactory.php 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
]);
}
}

+ 0
- 0
app/Domain/Device/Repositories/.gitkeep View File


+ 12
- 0
app/Domain/Device/Repositories/DeviceRepository.php View File

@ -0,0 +1,12 @@
<?php
namespace App\Domain\Device\Repositories;
/**
* Class DeviceRepository
* @package App\Domain\Device\Repositories
*/
class DeviceRepository
{
}

+ 13
- 0
app/Models/Device.php 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'];
}

+ 28
- 0
database/factories/DeviceFactory.php 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 [
//
];
}
}

+ 33
- 0
database/migrations/2021_01_07_184250_create_devices_table.php 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');
}
}

Loading…
Cancel
Save