diff --git a/app/Http/Controllers/CommentController.php b/app/Http/Controllers/CommentController.php new file mode 100644 index 0000000000000000000000000000000000000000..566d5deb17c28e6a164506fee5a54cc79b78df1e --- /dev/null +++ b/app/Http/Controllers/CommentController.php @@ -0,0 +1,17 @@ +<?php + +namespace App\Http\Controllers; + +use App\Models\Comment; +use Illuminate\Http\Request; + +class CommentController extends Controller +{ + public function index() { + $comments = Comment::all(); + + return view('comment.index', [ + 'comments' => $comments + ]); + } +} diff --git a/app/Models/Comment.php b/app/Models/Comment.php new file mode 100644 index 0000000000000000000000000000000000000000..2766b1c67e39547cb87887cfb7ac29902fe5b46f --- /dev/null +++ b/app/Models/Comment.php @@ -0,0 +1,16 @@ +<?php + +namespace App\Models; + +use Illuminate\Database\Eloquent\Factories\HasFactory; +use Illuminate\Database\Eloquent\Model; + +class Comment extends Model +{ + use HasFactory; + + protected $fillable = [ + 'author', + 'content' + ]; +} diff --git a/database/factories/CommentFactory.php b/database/factories/CommentFactory.php new file mode 100644 index 0000000000000000000000000000000000000000..c0692e71ded4d246078eb8ca68f315362a550785 --- /dev/null +++ b/database/factories/CommentFactory.php @@ -0,0 +1,24 @@ +<?php + +namespace Database\Factories; + +use Illuminate\Database\Eloquent\Factories\Factory; + +/** + * @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Comment> + */ +class CommentFactory extends Factory +{ + /** + * Define the model's default state. + * + * @return array<string, mixed> + */ + public function definition(): array + { + return [ + 'author' => fake()->name(), + 'content' => fake()->sentence(), + ]; + } +} diff --git a/database/migrations/2023_09_18_180158_create_comments_table.php b/database/migrations/2023_09_18_180158_create_comments_table.php new file mode 100644 index 0000000000000000000000000000000000000000..1934a1f9fe6a953891e5c5df708031c5a2060fa5 --- /dev/null +++ b/database/migrations/2023_09_18_180158_create_comments_table.php @@ -0,0 +1,29 @@ +<?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('comments', function (Blueprint $table) { + $table->id(); + $table->string('author'); + $table->string('content'); + $table->timestamps(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('comments'); + } +}; diff --git a/database/seeders/DatabaseSeeder.php b/database/seeders/DatabaseSeeder.php index e30fdfd96ed183b29068f8722768066bc24dd118..687e72ee1268cf14bce6e34ed1cec70ef6614f6c 100644 --- a/database/seeders/DatabaseSeeder.php +++ b/database/seeders/DatabaseSeeder.php @@ -3,6 +3,8 @@ namespace Database\Seeders; // use Illuminate\Database\Console\Seeds\WithoutModelEvents; + +use App\Models\Comment; use Illuminate\Database\Seeder; use App\Models\Post; @@ -14,5 +16,6 @@ class DatabaseSeeder extends Seeder public function run(): void { Post::factory(10)->create(); + Comment::factory(5)->create(); } } diff --git a/resources/views/comment/index.blade.php b/resources/views/comment/index.blade.php new file mode 100644 index 0000000000000000000000000000000000000000..025ebcdd9b8c658622c6c865e5ba6a958dae607a --- /dev/null +++ b/resources/views/comment/index.blade.php @@ -0,0 +1,26 @@ +@extends('base') + +@section('title', 'Commentaires du blog') + + +@section('content') + <a class="text-yellow-500 text-4xl font-bold" href="{{ route('blog.index') }}">Retour</a> + + + <h1 class="text-red-500 font-bold text-4xl">Les commentaires</h1> + @empty($comments) + <p>no comments</p> + @else + <ul> + @foreach ($comments as $comment) + <li class="mb-6"> + <p class="text-green-400 text-sm">{{ $comment->author }}</p> + <p> {{ $comment->content }}</p> + </li> + @endforeach + </ul> + + + + @endempty +@endsection diff --git a/routes/web.php b/routes/web.php index 980c6d55cfdeed10a13ec33e4c56f3b92db7f43c..812ada9a993559f9a0ed5a761524aa99671d4134 100644 --- a/routes/web.php +++ b/routes/web.php @@ -1,6 +1,7 @@ <?php use App\Http\Controllers\BlogController; +use App\Http\Controllers\CommentController; use App\Http\Controllers\ProfileController; use Illuminate\Support\Facades\Route; @@ -15,10 +16,18 @@ | */ + + Route::prefix('/')->controller(BlogController::class)->group(function () { Route::get('/', 'index')->name('blog.index'); - Route::get('/{post}', 'show')->name('blog.show'); + Route::get('/blog/{post}', 'show')->name('blog.show'); + +}); + +Route::prefix('/commentaires')->controller(CommentController::class)->group(function () { + Route::get('/', 'index')->name('comment.index'); + });