diff --git a/laravel/app/Http/Controllers/BilletController.php b/laravel/app/Http/Controllers/BilletController.php index 14c1ccc..3db998b 100644 --- a/laravel/app/Http/Controllers/BilletController.php +++ b/laravel/app/Http/Controllers/BilletController.php @@ -39,6 +39,8 @@ class BilletController extends Controller public function show(Billet $billet) { // + $commentaires = $billet->commentaires; + return view('vBillet', compact('billet', 'commentaires')); } /** diff --git a/laravel/app/Http/Controllers/CommentaireController.php b/laravel/app/Http/Controllers/CommentaireController.php new file mode 100644 index 0000000..07a8a1d --- /dev/null +++ b/laravel/app/Http/Controllers/CommentaireController.php @@ -0,0 +1,66 @@ +|string> + */ + public function rules(): array + { + return [ + // + ]; + } +} diff --git a/laravel/app/Http/Requests/UpdateCommentaireRequest.php b/laravel/app/Http/Requests/UpdateCommentaireRequest.php new file mode 100644 index 0000000..5ab29f3 --- /dev/null +++ b/laravel/app/Http/Requests/UpdateCommentaireRequest.php @@ -0,0 +1,28 @@ +|string> + */ + public function rules(): array + { + return [ + // + ]; + } +} diff --git a/laravel/app/Models/Billet.php b/laravel/app/Models/Billet.php index 80e78a2..2fe185c 100644 --- a/laravel/app/Models/Billet.php +++ b/laravel/app/Models/Billet.php @@ -9,4 +9,17 @@ class Billet extends Model { /** @use HasFactory<\Database\Factories\BilletFactory> */ use HasFactory; + + protected $fillable = [ + 'BIL_DATE', + 'BIL_TITRE', + 'BIL_CONTENU', + 'created_at', + 'updated_at', + ]; + + public function commentaires() + { + return $this->hasMany(Commentaire::class); + } } diff --git a/laravel/app/Models/Commentaire.php b/laravel/app/Models/Commentaire.php new file mode 100644 index 0000000..ad9f701 --- /dev/null +++ b/laravel/app/Models/Commentaire.php @@ -0,0 +1,26 @@ + */ + use HasFactory; + + protected $fillable = [ + 'COM_DATE', + 'COM_AUTEUR', + 'COM_CONTENU', + 'billet_id', + 'created_at', + 'updated_at', + ]; + + public function billet() + { + return $this->belongsTo(Billet::class, 'billet_id'); + } +} \ No newline at end of file diff --git a/laravel/app/Policies/CommentairePolicy.php b/laravel/app/Policies/CommentairePolicy.php new file mode 100644 index 0000000..bf6683f --- /dev/null +++ b/laravel/app/Policies/CommentairePolicy.php @@ -0,0 +1,66 @@ + + */ +class CommentaireFactory extends Factory +{ + /** + * Define the model's default state. + * + * @return array + */ + 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(), + ]; + } +} diff --git a/laravel/database/migrations/2025_04_12_110216_create_billets_table.php b/laravel/database/migrations/2025_04_17_110216_create_billets_table.php similarity index 100% rename from laravel/database/migrations/2025_04_12_110216_create_billets_table.php rename to laravel/database/migrations/2025_04_17_110216_create_billets_table.php diff --git a/laravel/database/migrations/2025_04_17_120715_create_commentaires_table.php b/laravel/database/migrations/2025_04_17_120715_create_commentaires_table.php new file mode 100644 index 0000000..ccd8189 --- /dev/null +++ b/laravel/database/migrations/2025_04_17_120715_create_commentaires_table.php @@ -0,0 +1,36 @@ +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'); + } +}; diff --git a/laravel/database/seeders/CommentaireSeeder.php b/laravel/database/seeders/CommentaireSeeder.php new file mode 100644 index 0000000..0dddcbc --- /dev/null +++ b/laravel/database/seeders/CommentaireSeeder.php @@ -0,0 +1,20 @@ +create(); + } +} diff --git a/laravel/public/style.css b/laravel/public/style.css index 78614c2..9a8cf49 100644 --- a/laravel/public/style.css +++ b/laravel/public/style.css @@ -39,4 +39,12 @@ h1 { #txtCommentaire { width: 50%; +} + +#titreReponses { + font-size: 100%; +} + +#txtCommentaire { + width: 50%; } \ No newline at end of file diff --git a/laravel/resources/views/index.blade.php b/laravel/resources/views/index.blade.php index ea3c5c7..e846caa 100644 --- a/laravel/resources/views/index.blade.php +++ b/laravel/resources/views/index.blade.php @@ -1,31 +1,13 @@ - - - - - - Mon Blog - - -
+@extends('layout') +@section('contenu') + @foreach($billets as $billet) +
-

Mon Blog

-

Je vous souhaite la bienvenue sur ce modeste blog.

+

{{ $billet->BIL_TITRE }}

+
-
- @foreach($billets as $billet) -
-
-

{{ $billet->BIL_TITRE }}

- -
-

{{ $billet->BIL_CONTENU }}

-
-
- @endforeach -
-
- Blog réalisé avec PHP, HTML5 et CSS. -
-
- - \ No newline at end of file +

{{ $billet->BIL_CONTENU }}

+ +
+ @endforeach +@endsection \ No newline at end of file diff --git a/laravel/resources/views/layout.blade.php b/laravel/resources/views/layout.blade.php new file mode 100644 index 0000000..2cf3caa --- /dev/null +++ b/laravel/resources/views/layout.blade.php @@ -0,0 +1,23 @@ + + + + + + + Mon Blog + + +
+
+

Mon Blog

+

Je vous souhaite la bienvenue sur ce modeste blog.

+
+
+ @yield('contenu') +
+
+ Blog réalisé avec PHP, HTML5 et CSS. +
+
+ + \ No newline at end of file diff --git a/laravel/resources/views/vBillet.blade.php b/laravel/resources/views/vBillet.blade.php new file mode 100644 index 0000000..9a01b5f --- /dev/null +++ b/laravel/resources/views/vBillet.blade.php @@ -0,0 +1,24 @@ +@extends('layout') +@section('contenu') +
+
+

{{ $billet->BIL_TITRE }}

+ +
+

{{ $billet->BIL_CONTENU }}

+
+
+@if (count($commentaires) > 0) +
+

Réponses à {{ $billet->BIL_TITRE }}

+
+ @foreach($commentaires as $commentaire) +

{{ $commentaire->COM_AUTEUR }} dit :

+

{{ $commentaire->COM_CONTENU }}

+ @endforeach +@else +
+

Il n'y a pas de réponse à ce billet.

+
+@endif +@endsection \ No newline at end of file