From ef97fc059f930383c4e8d6a84f9938c6ac6143a1 Mon Sep 17 00:00:00 2001 From: Nafies Luthfi Date: Wed, 9 Jan 2019 21:09:12 +0800 Subject: [PATCH] Refactor user calendar route to controller --- app/Http/Controllers/Users/CalendarController.php | 22 ++++++++++++++++++++++ routes/web/calendar.php | 16 +++------------- 2 files changed, 25 insertions(+), 13 deletions(-) create mode 100644 app/Http/Controllers/Users/CalendarController.php diff --git a/app/Http/Controllers/Users/CalendarController.php b/app/Http/Controllers/Users/CalendarController.php new file mode 100644 index 0000000..fc30500 --- /dev/null +++ b/app/Http/Controllers/Users/CalendarController.php @@ -0,0 +1,22 @@ +user(); + + if ($user->hasRole('admin') == false) { + $projects = $user->projects()->orderBy('projects.name')->pluck('projects.name', 'projects.id'); + } else { + $projects = Project::orderBy('name')->pluck('name', 'id'); + } + + return view('users.calendar', compact('projects')); + } +} diff --git a/routes/web/calendar.php b/routes/web/calendar.php index de6229b..b3b60d1 100644 --- a/routes/web/calendar.php +++ b/routes/web/calendar.php @@ -1,18 +1,8 @@ ['web', 'auth'], 'namespace' => 'Api'], function () { +Route::group(['middleware' => ['web', 'auth'], 'namespace' => 'Users'], function () { /* - * Savety Calendar + * User Calendar Route */ - Route::get('my-calendar', ['as' => 'users.calendar', 'uses' => function () { - $user = auth()->user(); - - if ($user->hasRole('admin') == false) { - $projects = $user->projects()->orderBy('projects.name')->pluck('projects.name', 'projects.id'); - } else { - $projects = App\Entities\Projects\Project::orderBy('name')->pluck('name', 'id'); - } - - return view('users.calendar', compact('projects')); - }]); + Route::get('my-calendar', 'CalendarController@index')->name('users.calendar'); });