From 43759eeb86e33b9a1a841ce4a837f3455d7b8ff0 Mon Sep 17 00:00:00 2001 From: Bimaekap Date: Fri, 22 Sep 2023 00:30:11 +0700 Subject: [PATCH 01/10] Answer All Question --- routes/api.php | 11 +++++-- routes/web.php | 84 +++++++++++++++++++++++++++++++++----------------- 2 files changed, 64 insertions(+), 31 deletions(-) diff --git a/routes/api.php b/routes/api.php index 39ecc07c6..e3db15cd6 100644 --- a/routes/api.php +++ b/routes/api.php @@ -1,5 +1,6 @@ user(); }); -Route::group(['middleware' => 'auth:sanctum'], function() { +Route::group(['middleware' => 'auth:sanctum'], function () { // Task 12: Manage tasks with endpoint /api/v1/tasks/*****. // Keep in mind that prefix should be /api/v1. // Add ONE line to assign 5 resource routes to TaskController // Put one code line here below - + Route::prefix('api/v1')->group(function () { + Route::get('/tasks', [TaskController::class, 'index']); + Route::get('/tasks', [TaskController::class, 'create']); + Route::get('/tasks', [TaskController::class, 'store']); + Route::get('/tasks', [TaskController::class, 'show']); + Route::get('/tasks', [TaskController::class, 'edit']); + }); }); diff --git a/routes/web.php b/routes/web.php index 15508ce8d..945ba6334 100644 --- a/routes/web.php +++ b/routes/web.php @@ -1,5 +1,10 @@ 'auth'], function () { // Tasks inside that Authenticated group: - // Task 6: /app group within a group - // Add another group for routes with prefix "app" - // Put one Route Group code line here below - - // Tasks inside that /app group: - - - // Task 7: point URL /app/dashboard to a "Single Action" DashboardController - // Assign the route name "dashboard" - // Put one Route Group code line here below - + Route::get('/auth/create' , [AuthenticatedSessionController::class, 'create']); + Route::get('/auth/store' , [AuthenticatedSessionController::class, 'store']); + Route::get('/auth/destroy' , [AuthenticatedSessionController::class, 'destroy']); - // Task 8: Manage tasks with URL /app/tasks/***. - // Add ONE line to assign 7 resource routes to TaskController - // Put one code line here below +}); - // End of the /app Route Group +// Task 6: /app group within a group +// Add another group for routes with prefix "app" +// Put one Route Group code line here below +Route::prefix('/app')->group(function () { +// Tasks inside that /app group: +Route::get('/', [TaskController::class, 'index']); +Route::post('/create', [TaskController::class, 'create']); +Route::get('/store', [TaskController::class, 'store']); +Route::get('/show', [TaskController::class, 'show']); +Route::get('/edit', [TaskController::class, 'edit']); +Route::put('/update', [TaskController::class, 'update']); +Route::get('/delete', [TaskController::class, 'create']); +}) - // Task 9: /admin group within a group - // Add a group for routes with URL prefix "admin" - // Assign middleware called "is_admin" to them - // Put one Route Group code line here below +// Task 7: point URL /app/dashboard to a "Single Action" DashboardController +// Assign the route name "dashboard" +// Put one Route Group code line here below - // Tasks inside that /admin group: +Route::get('/app/dashboard', DashboardController::class)->name('dashboard'); +// Task 8: Manage tasks with URL /app/tasks/***. +// Add ONE line to assign 7 resource routes to TaskController +// Put one code line here below +Route::resource('/app/tasks', TaskController::class); +// End of the /app Route Group - // Task 10: point URL /admin/dashboard to a "Single Action" Admin/DashboardController - // Put one code line here below +// Task 9: /admin group within a group +// Add a group for routes with URL prefix "admin" +// Assign middleware called "is_admin" to them +// Put one Route Group code line here below +Route::group(['prefix' => '/admin', 'middleware' => 'is_admin'], function () { +// Tasks inside that /admin group: - // Task 11: point URL /admin/stats to a "Single Action" Admin/StatsController - // Put one code line here below +}); +// Task 10: point URL /admin/dashboard to a "Single Action" Admin/DashboardController +// Put one code line here below - // End of the /admin Route Group +Route::get('/admin/dashboard' ,Admin/DashboardController::class); +// Task 11: point URL /admin/stats to a "Single Action" Admin/StatsController +// Put one code line here below +Route::get('/admin/stats' , Admin/DashboardController::class); +// End of the /admin Route Group // End of the main Authenticated Route Group // One more task is in routes/api.php -require __DIR__.'/auth.php'; +require __DIR__ . '/auth.php'; From 2702889977a3dcbae2a6e19186bcd43f48f9b9d0 Mon Sep 17 00:00:00 2001 From: Bimaekap Date: Fri, 22 Sep 2023 00:46:54 +0700 Subject: [PATCH 02/10] Complete --- routes/web.php | 37 +++++++++++++++++++------------------ 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/routes/web.php b/routes/web.php index 945ba6334..9bc0e418d 100644 --- a/routes/web.php +++ b/routes/web.php @@ -2,6 +2,7 @@ use App\Http\Controllers\Admin\DashboardController; use App\Http\Controllers\Auth\AuthenticatedSessionController; +use App\Http\Controllers\DashboardController as ControllersDashboardController; use App\Http\Controllers\HomeController; use App\Http\Controllers\TaskController; use App\Http\Controllers\UserController; @@ -49,10 +50,9 @@ Route::group(['middleware' => 'auth'], function () { // Tasks inside that Authenticated group: - Route::get('/auth/create' , [AuthenticatedSessionController::class, 'create']); - Route::get('/auth/store' , [AuthenticatedSessionController::class, 'store']); - Route::get('/auth/destroy' , [AuthenticatedSessionController::class, 'destroy']); - + Route::get('/auth/create', [AuthenticatedSessionController::class, 'create']); + Route::get('/auth/store', [AuthenticatedSessionController::class, 'store']); + Route::get('/auth/destroy', [AuthenticatedSessionController::class, 'destroy']); }); // Task 6: /app group within a group @@ -60,22 +60,23 @@ // Put one Route Group code line here below Route::prefix('/app')->group(function () { -// Tasks inside that /app group: -Route::get('/', [TaskController::class, 'index']); -Route::post('/create', [TaskController::class, 'create']); -Route::get('/store', [TaskController::class, 'store']); -Route::get('/show', [TaskController::class, 'show']); -Route::get('/edit', [TaskController::class, 'edit']); -Route::put('/update', [TaskController::class, 'update']); -Route::get('/delete', [TaskController::class, 'create']); -}) + // Tasks inside that /app group: + Route::get('/', [TaskController::class, 'index']); + Route::post('/create', [TaskController::class, 'create']); + Route::get('/store', [TaskController::class, 'store']); + Route::get('/show', [TaskController::class, 'show']); + Route::get('/edit', [TaskController::class, 'edit']); + Route::put('/update', [TaskController::class, 'update']); + Route::get('/delete', [TaskController::class, 'create']); +}); // Task 7: point URL /app/dashboard to a "Single Action" DashboardController // Assign the route name "dashboard" // Put one Route Group code line here below - -Route::get('/app/dashboard', DashboardController::class)->name('dashboard'); +Route::group(function () { + Route::get('/app/dashboard', DashboardController::class)->name('dashboard'); +}); // Task 8: Manage tasks with URL /app/tasks/***. // Add ONE line to assign 7 resource routes to TaskController @@ -89,17 +90,17 @@ // Assign middleware called "is_admin" to them // Put one Route Group code line here below Route::group(['prefix' => '/admin', 'middleware' => 'is_admin'], function () { -// Tasks inside that /admin group: + // Tasks inside that /admin group: }); // Task 10: point URL /admin/dashboard to a "Single Action" Admin/DashboardController // Put one code line here below -Route::get('/admin/dashboard' ,Admin/DashboardController::class); +Route::get('/admin/dashboard', Admin\DashboardController::class); // Task 11: point URL /admin/stats to a "Single Action" Admin/StatsController // Put one code line here below -Route::get('/admin/stats' , Admin/DashboardController::class); +Route::get('/admin/stats', Admin\DashboardController::class); // End of the /admin Route Group // End of the main Authenticated Route Group From d0b2968729cfc44e35aa1814f661561ffb13b086 Mon Sep 17 00:00:00 2001 From: Bimaekap Date: Fri, 22 Sep 2023 01:04:03 +0700 Subject: [PATCH 03/10] three times --- routes/api.php | 10 ++-------- routes/web.php | 14 ++++---------- 2 files changed, 6 insertions(+), 18 deletions(-) diff --git a/routes/api.php b/routes/api.php index e3db15cd6..f6ac74fc1 100644 --- a/routes/api.php +++ b/routes/api.php @@ -19,16 +19,10 @@ return $request->user(); }); -Route::group(['middleware' => 'auth:sanctum'], function () { +Route::group(['prefix' => 'v1', 'namespace' => 'api/v1', 'middleware' => 'auth:sanctum'], function () { // Task 12: Manage tasks with endpoint /api/v1/tasks/*****. // Keep in mind that prefix should be /api/v1. // Add ONE line to assign 5 resource routes to TaskController // Put one code line here below - Route::prefix('api/v1')->group(function () { - Route::get('/tasks', [TaskController::class, 'index']); - Route::get('/tasks', [TaskController::class, 'create']); - Route::get('/tasks', [TaskController::class, 'store']); - Route::get('/tasks', [TaskController::class, 'show']); - Route::get('/tasks', [TaskController::class, 'edit']); - }); + Route::apiResource('tasks', TaskController::class); }); diff --git a/routes/web.php b/routes/web.php index 9bc0e418d..ce464fc72 100644 --- a/routes/web.php +++ b/routes/web.php @@ -59,15 +59,9 @@ // Add another group for routes with prefix "app" // Put one Route Group code line here below -Route::prefix('/app')->group(function () { +Route::group(['prefix' => '/app'], function () { // Tasks inside that /app group: - Route::get('/', [TaskController::class, 'index']); - Route::post('/create', [TaskController::class, 'create']); - Route::get('/store', [TaskController::class, 'store']); - Route::get('/show', [TaskController::class, 'show']); - Route::get('/edit', [TaskController::class, 'edit']); - Route::put('/update', [TaskController::class, 'update']); - Route::get('/delete', [TaskController::class, 'create']); + Route::resource('tasks', TaskController::class); }); @@ -75,8 +69,8 @@ // Assign the route name "dashboard" // Put one Route Group code line here below Route::group(function () { - Route::get('/app/dashboard', DashboardController::class)->name('dashboard'); -}); + Route::get('/app/dashboard', DashboardController::class); +})->name('dashboard'); // Task 8: Manage tasks with URL /app/tasks/***. // Add ONE line to assign 7 resource routes to TaskController From c4e6120a5178d731668874314b99a5053a583bc9 Mon Sep 17 00:00:00 2001 From: Bimaekap Date: Fri, 22 Sep 2023 01:17:25 +0700 Subject: [PATCH 04/10] update --- routes/web.php | 93 ++++++++++++++++++++++---------------------------- 1 file changed, 40 insertions(+), 53 deletions(-) diff --git a/routes/web.php b/routes/web.php index ce464fc72..2fb2416a1 100644 --- a/routes/web.php +++ b/routes/web.php @@ -37,68 +37,55 @@ Route::get('/about', function () { return view('pages.about'); -}); +})->name('about'); // Task 4: redirect the GET URL "log-in" to a URL "login" // Put one code line here below -Route::get('/log-in', function () { - return redirect('auth.login'); -}); +Route::redirect('/log-in', '/login'); // Task 5: group the following route sentences below in Route::group() // Assign middleware "auth" // Put one Route Group code line here below -Route::group(['middleware' => 'auth'], function () { - // Tasks inside that Authenticated group: - - Route::get('/auth/create', [AuthenticatedSessionController::class, 'create']); - Route::get('/auth/store', [AuthenticatedSessionController::class, 'store']); - Route::get('/auth/destroy', [AuthenticatedSessionController::class, 'destroy']); -}); - -// Task 6: /app group within a group -// Add another group for routes with prefix "app" -// Put one Route Group code line here below - -Route::group(['prefix' => '/app'], function () { - // Tasks inside that /app group: - Route::resource('tasks', TaskController::class); -}); - - -// Task 7: point URL /app/dashboard to a "Single Action" DashboardController -// Assign the route name "dashboard" -// Put one Route Group code line here below -Route::group(function () { - Route::get('/app/dashboard', DashboardController::class); -})->name('dashboard'); +Route::middleware(['auth'])->group(function () { -// Task 8: Manage tasks with URL /app/tasks/***. -// Add ONE line to assign 7 resource routes to TaskController -// Put one code line here below -Route::resource('/app/tasks', TaskController::class); -// End of the /app Route Group - - -// Task 9: /admin group within a group -// Add a group for routes with URL prefix "admin" -// Assign middleware called "is_admin" to them -// Put one Route Group code line here below -Route::group(['prefix' => '/admin', 'middleware' => 'is_admin'], function () { - // Tasks inside that /admin group: + // Tasks inside that Authenticated group: + // Task 6: /app group within a group + // Add another group for routes with prefix "app" + // Put one Route Group code line here below + + Route::prefix('app')->group(function () { + + + // Task 7: point URL /app/dashboard to a "Single Action" DashboardController + // Assign the route name "dashboard" + // Put one Route Group code line here below + Route::get('/dashboard', [DashboardController::class]); + // Task 8: Manage tasks with URL /app/tasks/***. + // Add ONE line to assign 7 resource routes to TaskController + // Put one code line here below + Route::resource('tasks', TaskController::class); + }); + // End of the /app Route Group + + // Task 9: /admin group within a group + // Add a group for routes with URL prefix "admin" + // Assign middleware called "is_admin" to them + // Put one Route Group code line here below + Route::middleware(['is_admin'])->prefix('admin')->group(function () { + // Tasks inside that /admin group: + + // Task 10: point URL /admin/dashboard to a "Single Action" Admin/DashboardController + // Put one code line here below + + Route::get('dashboard', App\Http\Controllers\Admin\DashboardController::class); + // Task 11: point URL /admin/stats to a "Single Action" Admin/StatsController + // Put one code line here below + Route::get('stats', App\Http\Controllers\Admin\StatsController::class); + // End of the /admin Route Group + }); + + // End of the main Authenticated Route Group }); - -// Task 10: point URL /admin/dashboard to a "Single Action" Admin/DashboardController -// Put one code line here below - -Route::get('/admin/dashboard', Admin\DashboardController::class); -// Task 11: point URL /admin/stats to a "Single Action" Admin/StatsController -// Put one code line here below -Route::get('/admin/stats', Admin\DashboardController::class); -// End of the /admin Route Group - -// End of the main Authenticated Route Group - // One more task is in routes/api.php require __DIR__ . '/auth.php'; From 0133d816b4c448c4b889922cc4a8e99aedbb8992 Mon Sep 17 00:00:00 2001 From: Bimaekap Date: Fri, 22 Sep 2023 01:25:12 +0700 Subject: [PATCH 05/10] update twice --- routes/api.php | 4 ++-- routes/web.php | 12 +++++------- 2 files changed, 7 insertions(+), 9 deletions(-) diff --git a/routes/api.php b/routes/api.php index f6ac74fc1..9e6117a88 100644 --- a/routes/api.php +++ b/routes/api.php @@ -19,10 +19,10 @@ return $request->user(); }); -Route::group(['prefix' => 'v1', 'namespace' => 'api/v1', 'middleware' => 'auth:sanctum'], function () { +Route::group(['middleware' => 'auth:sanctum', 'prefix' => 'v1'], function () { // Task 12: Manage tasks with endpoint /api/v1/tasks/*****. // Keep in mind that prefix should be /api/v1. // Add ONE line to assign 5 resource routes to TaskController // Put one code line here below - Route::apiResource('tasks', TaskController::class); + Route::apiResource('/tasks', \App\Http\Controllers\Api\V1\TaskController::class); }); diff --git a/routes/web.php b/routes/web.php index 2fb2416a1..7ce4d20d2 100644 --- a/routes/web.php +++ b/routes/web.php @@ -35,9 +35,7 @@ // Also, assign the route name "about" // Put one code line here below -Route::get('/about', function () { - return view('pages.about'); -})->name('about'); +Route::view('/about', 'pages.about')->name('about'); // Task 4: redirect the GET URL "log-in" to a URL "login" // Put one code line here below @@ -59,11 +57,11 @@ // Task 7: point URL /app/dashboard to a "Single Action" DashboardController // Assign the route name "dashboard" // Put one Route Group code line here below - Route::get('/dashboard', [DashboardController::class]); + Route::get('/dashboard', DashboardController::class); // Task 8: Manage tasks with URL /app/tasks/***. // Add ONE line to assign 7 resource routes to TaskController // Put one code line here below - Route::resource('tasks', TaskController::class); + Route::resource('/tasks', TaskController::class); }); // End of the /app Route Group @@ -77,10 +75,10 @@ // Task 10: point URL /admin/dashboard to a "Single Action" Admin/DashboardController // Put one code line here below - Route::get('dashboard', App\Http\Controllers\Admin\DashboardController::class); + Route::get('/dashboard', App\Http\Controllers\Admin\DashboardController::class); // Task 11: point URL /admin/stats to a "Single Action" Admin/StatsController // Put one code line here below - Route::get('stats', App\Http\Controllers\Admin\StatsController::class); + Route::get('/stats', App\Http\Controllers\Admin\StatsController::class); // End of the /admin Route Group }); From 1701565d82ba4f2e0ab740d848dfc78438a4274e Mon Sep 17 00:00:00 2001 From: Bimaekap Date: Fri, 22 Sep 2023 01:28:25 +0700 Subject: [PATCH 06/10] update third --- routes/web.php | 3 +++ 1 file changed, 3 insertions(+) diff --git a/routes/web.php b/routes/web.php index 7ce4d20d2..a3124b12e 100644 --- a/routes/web.php +++ b/routes/web.php @@ -85,5 +85,8 @@ // End of the main Authenticated Route Group }); // One more task is in routes/api.php +Route::get('/dashboard', function(){ + / +})->name('dashboard'); require __DIR__ . '/auth.php'; From c0f530146d94dbbea68a606d842c0e0c95525873 Mon Sep 17 00:00:00 2001 From: Bimaekap Date: Fri, 22 Sep 2023 01:34:09 +0700 Subject: [PATCH 07/10] update again --- routes/web.php | 8 +++----- 1 file changed, 3 insertions(+), 5 deletions(-) diff --git a/routes/web.php b/routes/web.php index a3124b12e..938e25d6f 100644 --- a/routes/web.php +++ b/routes/web.php @@ -24,6 +24,7 @@ Route::get('/', [HomeController::class, 'index']); +Route::get('/dashboard', DashboardController::class)->name('dashboard'); // Task 2: point the GET URL "/user/[name]" to the UserController method "show" // It doesn't use Route Model Binding, it expects $name as a parameter // Put one code line here below @@ -69,13 +70,13 @@ // Add a group for routes with URL prefix "admin" // Assign middleware called "is_admin" to them // Put one Route Group code line here below - Route::middleware(['is_admin'])->prefix('admin')->group(function () { + Route::group(['prefix' => 'admin', 'middleware' => 'is_admin'], function () { // Tasks inside that /admin group: // Task 10: point URL /admin/dashboard to a "Single Action" Admin/DashboardController // Put one code line here below - Route::get('/dashboard', App\Http\Controllers\Admin\DashboardController::class); + Route::get('/dashboard', App\Http\Controllers\AdminDashboardController::class); // Task 11: point URL /admin/stats to a "Single Action" Admin/StatsController // Put one code line here below Route::get('/stats', App\Http\Controllers\Admin\StatsController::class); @@ -85,8 +86,5 @@ // End of the main Authenticated Route Group }); // One more task is in routes/api.php -Route::get('/dashboard', function(){ - / -})->name('dashboard'); require __DIR__ . '/auth.php'; From 025551f8e6ca8cfcb14efcd646b353f2d49db804 Mon Sep 17 00:00:00 2001 From: Bimaekap Date: Fri, 22 Sep 2023 01:35:27 +0700 Subject: [PATCH 08/10] update again --- routes/web.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routes/web.php b/routes/web.php index 938e25d6f..896d6d516 100644 --- a/routes/web.php +++ b/routes/web.php @@ -76,7 +76,7 @@ // Task 10: point URL /admin/dashboard to a "Single Action" Admin/DashboardController // Put one code line here below - Route::get('/dashboard', App\Http\Controllers\AdminDashboardController::class); + Route::get('/dashboard', App\Http\Controllers\DashboardController::class); // Task 11: point URL /admin/stats to a "Single Action" Admin/StatsController // Put one code line here below Route::get('/stats', App\Http\Controllers\Admin\StatsController::class); From 613a1c6fa53be63751d8716fe808b3ffcfec4cae Mon Sep 17 00:00:00 2001 From: Bimaekap Date: Fri, 22 Sep 2023 01:37:26 +0700 Subject: [PATCH 09/10] update again --- routes/web.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/routes/web.php b/routes/web.php index 896d6d516..6097755d6 100644 --- a/routes/web.php +++ b/routes/web.php @@ -76,7 +76,7 @@ // Task 10: point URL /admin/dashboard to a "Single Action" Admin/DashboardController // Put one code line here below - Route::get('/dashboard', App\Http\Controllers\DashboardController::class); + Route::get('/admin/dashboard', App\Http\Controllers\DashboardController::class); // Task 11: point URL /admin/stats to a "Single Action" Admin/StatsController // Put one code line here below Route::get('/stats', App\Http\Controllers\Admin\StatsController::class); From b5a85a2f2dcea4f41767a9a90ed5554bbeb38372 Mon Sep 17 00:00:00 2001 From: Bimaekap Date: Fri, 22 Sep 2023 01:40:53 +0700 Subject: [PATCH 10/10] try again --- routes/web.php | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/routes/web.php b/routes/web.php index 6097755d6..b88a27bd9 100644 --- a/routes/web.php +++ b/routes/web.php @@ -1,8 +1,8 @@