finished api

This commit is contained in:
Clément
2025-06-04 19:50:52 +02:00
parent 1551f6226e
commit f488f7e01d
32 changed files with 1078 additions and 30 deletions

View File

@@ -0,0 +1,27 @@
<?php
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Billet>
*/
class BilletFactory extends Factory
{
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition(): array
{
return [
'BIL_DATE' => $this->faker->date(),
'BIL_TITRE' => $this->faker->text(20),
'BIL_CONTENU' => $this->faker->text(100),
'created_at' => now(),
'updated_at' => now(),
];
}
}

View File

@@ -0,0 +1,26 @@
<?php
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Commentaires>
*/
class CommentairesFactory extends Factory
{
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition(): array
{
return [
'COM_DATE' => now(),
'COM_CONTENU' => fake()->text(200),
'billet_id' => fake()->numberBetween(1, 10),
'user_id' => fake()->numberBetween(1, 2),
];
}
}

View File

@@ -0,0 +1,33 @@
<?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('personal_access_tokens', function (Blueprint $table) {
$table->id();
$table->morphs('tokenable');
$table->string('name');
$table->string('token', 64)->unique();
$table->text('abilities')->nullable();
$table->timestamp('last_used_at')->nullable();
$table->timestamp('expires_at')->nullable();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('personal_access_tokens');
}
};

View File

@@ -0,0 +1,30 @@
<?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('billets', function (Blueprint $table) {
$table->id();
$table->date('BIL_DATE');
$table->text('BIL_TITRE');
$table->text('BIL_CONTENU');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('billets');
}
};

View File

@@ -0,0 +1,41 @@
<?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_CONTENU');
$table->unsignedBigInteger('billet_id');
$table->unsignedBigInteger('user_id');
$table->foreign('billet_id')
->references('id')
->on('billets')
->onDelete('cascade')
->onUpdate('cascade');
$table->foreign('user_id')
->references('id')
->on('users')
->onDelete('cascade')
->onUpdate('cascade');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('commentaires');
}
};

View File

@@ -0,0 +1,18 @@
<?php
namespace Database\Seeders;
use App\Models\Billet;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
class BilletSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{
Billet::factory(10)->create();
}
}

View File

@@ -0,0 +1,18 @@
<?php
namespace Database\Seeders;
use App\Models\Commentaire;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
class CommentairesSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{
Commentaire::factory(10)->create();
}
}

View File

@@ -11,13 +11,11 @@ class DatabaseSeeder extends Seeder
/**
* Seed the application's database.
*/
public function run(): void
{
// User::factory(10)->create();
public function run(): void{
User::factory()->create([
'name' => 'Test User',
'email' => 'test@example.com',
]);
// User::factory()->create([
// 'name' => 'Test User',
// 'email' => 'test@example.com',
// ]);
}
}

View File

@@ -0,0 +1,18 @@
<?php
namespace Database\Seeders;
use App\Models\User;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
class UserSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{
User::factory(2)->create();
}
}