diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php new file mode 100644 index 00000000..169e8307 --- /dev/null +++ b/app/Http/Controllers/ProjectController.php @@ -0,0 +1,77 @@ +title('Projects - '.config('app.name')); + $projects = Project::active()->orderByDesc('start_date')->paginate(12); + + return view('projects.index', compact('projects')); + } + + /** + * Show the form for creating a new resource. + */ + public function create() + { + // + } + + /** + * Store a newly created resource in storage. + */ + public function store(Request $request) + { + // + } + + public function show($param): View + { + $project = Project::where('uuid', $param) + ->orWhere('slug', $param) + ->active() + ->firstOrFail(); + abort_if(! $project, 404); + views($project)->cooldown(60)->record(); + + seo()->title($project->title.' - Projects - '.config('app.name')); + seo()->description(strip_tags(Str::of(Str::limit($project->content, 150))->markdown())); + + return view('project.show', compact('project')); + } + + /** + * Show the form for editing the specified resource. + */ + public function edit(string $id) + { + // + } + + /** + * Update the specified resource in storage. + */ + public function update(Request $request, string $id) + { + // + } + + /** + * Remove the specified resource from storage. + */ + public function destroy(string $id) + { + // + } +} diff --git a/app/Models/Project.php b/app/Models/Project.php new file mode 100644 index 00000000..28b0f491 --- /dev/null +++ b/app/Models/Project.php @@ -0,0 +1,64 @@ +uuid = Str::uuid()->toString(); + $model->slug = Str::slug($model->title); + }); + + self::updating(function ($model) { + if (! $model->uuid) { + $model->uuid = Str::uuid()->toString(); + } + $model->slug = Str::slug($model->title); + }); + } + + protected $fillable = [ + 'title', + 'slug', + 'content', + 'repository', + 'website', + 'logo_url', + 'start_date', + 'end_date', + 'status', + ]; + + protected $casts = [ + 'start_date' => 'date', + 'end_date' => 'date', + ]; + + protected $withCount = [ + 'likes', + ]; + + public function scopeActive($query) + { + return $query->where('status', '>=', 1); + } +} diff --git a/database/factories/ProjectFactory.php b/database/factories/ProjectFactory.php new file mode 100644 index 00000000..3638b270 --- /dev/null +++ b/database/factories/ProjectFactory.php @@ -0,0 +1,31 @@ + + */ +class ProjectFactory extends Factory +{ + /** + * Define the model's default state. + * + * @return array + */ + public function definition(): array + { + return [ + 'title' => $this->faker->sentence(3), + 'content' => $this->faker->paragraph, + 'repository' => $this->faker->url, + 'website' => $this->faker->url, + 'logo_url' => $this->faker->imageUrl(), + 'start_date' => $this->faker->dateTimeBetween('-12 years', 'now'), + 'end_date' => null, + 'status' => $this->faker->numberBetween(0, 2), + ]; + } +} diff --git a/database/migrations/2024_08_27_210341_create_projects_table.php b/database/migrations/2024_08_27_210341_create_projects_table.php new file mode 100644 index 00000000..b1e8ad39 --- /dev/null +++ b/database/migrations/2024_08_27_210341_create_projects_table.php @@ -0,0 +1,40 @@ +id(); + + $table->uuid(); + $table->string('title'); + $table->string('slug'); + $table->text('content'); + $table->string('repository'); + $table->string('website'); + $table->string('logo_url'); + $table->date('start_date'); + $table->date('end_date')->nullable(); + $table->tinyInteger('status')->default(0)->comment('0: inactive, 1: active, etc'); + + $table->timestamps(); + $table->softDeletes(); + }); + } + + /** + * Reverse the migrations. + */ + public function down(): void + { + Schema::dropIfExists('projects'); + } +}; diff --git a/database/seeders/ProjectSeeder.php b/database/seeders/ProjectSeeder.php new file mode 100644 index 00000000..192a8b8f --- /dev/null +++ b/database/seeders/ProjectSeeder.php @@ -0,0 +1,17 @@ +count(20)->create(); + } +} diff --git a/resources/views/layouts/guest.blade.php b/resources/views/layouts/guest.blade.php index 3e33d352..1a755046 100644 --- a/resources/views/layouts/guest.blade.php +++ b/resources/views/layouts/guest.blade.php @@ -49,6 +49,7 @@