From 098bab32e9b13721c6e3743594f9e588bd33a64b Mon Sep 17 00:00:00 2001 From: Kamil Niemczycki Date: Sun, 13 Feb 2022 12:33:34 +0100 Subject: [PATCH] Project support has been updated --- app/Http/Controllers/ProjectController.php | 8 +++++--- app/Models/Project.php | 2 ++ app/Repository/ProjectRepository.php | 3 +-- .../2022_02_09_075749_create_projects_table.php | 14 ++++++++------ routes/api.php | 7 ++++--- 5 files changed, 20 insertions(+), 14 deletions(-) diff --git a/app/Http/Controllers/ProjectController.php b/app/Http/Controllers/ProjectController.php index 18f6c33..bfd13c4 100644 --- a/app/Http/Controllers/ProjectController.php +++ b/app/Http/Controllers/ProjectController.php @@ -1,5 +1,7 @@ projectRepository->all(); } - public function show() + public function show(int $project) { - + return $this->projectRepository->get($project); } } diff --git a/app/Models/Project.php b/app/Models/Project.php index 94417a0..7d7484b 100644 --- a/app/Models/Project.php +++ b/app/Models/Project.php @@ -1,5 +1,7 @@ project ->query() - ->find($id) - ->first(); + ->findOrFail($id); return new ProjectResource($project); } diff --git a/database/migrations/2022_02_09_075749_create_projects_table.php b/database/migrations/2022_02_09_075749_create_projects_table.php index 4046c37..3656eda 100644 --- a/database/migrations/2022_02_09_075749_create_projects_table.php +++ b/database/migrations/2022_02_09_075749_create_projects_table.php @@ -1,5 +1,7 @@ id(); $table->string('title', 255); - $table->json('categories'); + $table->json('categories')->nullable()->default(null); $table->string('author', 30); - $table->string('image_url', 30); - $table->dateTimeTz('release_data'); - $table->string('project_url', 255); - $table->string('project_version', 20); - $table->text('description'); + $table->string('image_url', 30)->nullable()->default(null); + $table->dateTimeTz('release_data')->nullable()->useCurrent(); + $table->string('project_url', 255)->nullable()->default(null); + $table->string('project_version', 20)->nullable()->default(null); + $table->text('description')->nullable()->default(null); $table->timestamps(); }); } diff --git a/routes/api.php b/routes/api.php index 6490cd3..58b66d3 100644 --- a/routes/api.php +++ b/routes/api.php @@ -1,6 +1,7 @@ group(function() { Route::get('{category}', 'CategoryController@showWhereSlug'); }); -Route::get('projects', 'CategoryController@index'); +Route::get('projects', 'ProjectController@index'); Route::prefix('project')->group(function() { - Route::get('{project}', 'CategoryController@showWhereSlug'); + Route::get('{project}', 'ProjectController@show'); });