Comments + 1N relations
This commit is contained in:
29
laravel/database/factories/CommentaireFactory.php
Normal file
29
laravel/database/factories/CommentaireFactory.php
Normal file
@@ -0,0 +1,29 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Factories;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\Factory;
|
||||
|
||||
/**
|
||||
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Commentaire>
|
||||
*/
|
||||
class CommentaireFactory extends Factory
|
||||
{
|
||||
/**
|
||||
* Define the model's default state.
|
||||
*
|
||||
* @return array<string, mixed>
|
||||
*/
|
||||
public function definition(): array
|
||||
{
|
||||
return [
|
||||
//
|
||||
'COM_DATE' => now(),
|
||||
'COM_AUTEUR' => fake()->lastName(),
|
||||
'COM_CONTENU' => fake()->text(200),
|
||||
'billet_id' => fake()->numberBetween(1,10),
|
||||
'created_at' => now(),
|
||||
'updated_at' => now(),
|
||||
];
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,36 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
return new class extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*/
|
||||
public function up(): void
|
||||
{
|
||||
Schema::create('commentaires', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->date('COM_DATE');
|
||||
$table->text('COM_AUTEUR');
|
||||
$table->text('COM_CONTENU');
|
||||
$table->unsignedBigInteger('billet_id');
|
||||
$table->foreign('billet_id')
|
||||
->references('id')
|
||||
->on('billets')
|
||||
->onDelete('cascade')
|
||||
->onUpdate('cascade');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*/
|
||||
public function down(): void
|
||||
{
|
||||
Schema::dropIfExists('commentaires');
|
||||
}
|
||||
};
|
||||
20
laravel/database/seeders/CommentaireSeeder.php
Normal file
20
laravel/database/seeders/CommentaireSeeder.php
Normal file
@@ -0,0 +1,20 @@
|
||||
<?php
|
||||
|
||||
namespace Database\Seeders;
|
||||
|
||||
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
|
||||
use Illuminate\Database\Seeder;
|
||||
use App\Models\Commentaire;
|
||||
|
||||
class CommentaireSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*/
|
||||
public function run(): void
|
||||
{
|
||||
//
|
||||
// Create 10 comments
|
||||
Commentaire::factory(10)->create();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user