3.0: Room repository and factory.
This commit is contained in:
parent
9575f69b35
commit
1d6c509982
0
app/Domain/Device/Repositories/.gitkeep
Normal file
0
app/Domain/Device/Repositories/.gitkeep
Normal file
19
app/Domain/Room/Factories/RoomFactory.php
Normal file
19
app/Domain/Room/Factories/RoomFactory.php
Normal file
@ -0,0 +1,19 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domain\Room\Factories;
|
||||||
|
|
||||||
|
use App\Models\Room;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class RoomFactory
|
||||||
|
* @package App\Domain\Room\Factories
|
||||||
|
*/
|
||||||
|
class RoomFactory
|
||||||
|
{
|
||||||
|
public function create(string $name): Room
|
||||||
|
{
|
||||||
|
return Room::create([
|
||||||
|
'name' => $name
|
||||||
|
]);
|
||||||
|
}
|
||||||
|
}
|
0
app/Domain/Room/Repositories/.gitkeep
Normal file
0
app/Domain/Room/Repositories/.gitkeep
Normal file
12
app/Domain/Room/Repositories/RoomRepository.php
Normal file
12
app/Domain/Room/Repositories/RoomRepository.php
Normal file
@ -0,0 +1,12 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Domain\Room\Repositories;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Class RoomRepository
|
||||||
|
* @package App\Domain\Room\Repositories
|
||||||
|
*/
|
||||||
|
class RoomRepository
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
15
app/Models/Room.php
Normal file
15
app/Models/Room.php
Normal file
@ -0,0 +1,15 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace App\Models;
|
||||||
|
|
||||||
|
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||||
|
use Illuminate\Database\Eloquent\Model;
|
||||||
|
|
||||||
|
class Room extends Model
|
||||||
|
{
|
||||||
|
use HasFactory;
|
||||||
|
|
||||||
|
protected $fillable = [
|
||||||
|
'name'
|
||||||
|
];
|
||||||
|
}
|
28
database/factories/RoomFactory.php
Normal file
28
database/factories/RoomFactory.php
Normal file
@ -0,0 +1,28 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
namespace Database\Factories;
|
||||||
|
|
||||||
|
use App\Models\Room;
|
||||||
|
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||||
|
|
||||||
|
class RoomFactory extends Factory
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* The name of the factory's corresponding model.
|
||||||
|
*
|
||||||
|
* @var string
|
||||||
|
*/
|
||||||
|
protected $model = Room::class;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Define the model's default state.
|
||||||
|
*
|
||||||
|
* @return array
|
||||||
|
*/
|
||||||
|
public function definition()
|
||||||
|
{
|
||||||
|
return [
|
||||||
|
'name' => $this->faker->name
|
||||||
|
];
|
||||||
|
}
|
||||||
|
}
|
32
database/migrations/2021_01_07_183923_create_rooms_table.php
Normal file
32
database/migrations/2021_01_07_183923_create_rooms_table.php
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
|
||||||
|
class CreateRoomsTable extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function up()
|
||||||
|
{
|
||||||
|
Schema::create('rooms', function (Blueprint $table) {
|
||||||
|
$table->id();
|
||||||
|
$table->string('name')->unique();
|
||||||
|
$table->timestamps();
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*
|
||||||
|
* @return void
|
||||||
|
*/
|
||||||
|
public function down()
|
||||||
|
{
|
||||||
|
Schema::dropIfExists('rooms');
|
||||||
|
}
|
||||||
|
}
|
Loading…
Reference in New Issue
Block a user