From 1944414e4695b548577b569e54b14c84b110bb20 Mon Sep 17 00:00:00 2001 From: Joren Van Hocht Date: Sat, 23 May 2015 13:54:35 +0200 Subject: [PATCH] Code refactoring --- .../BlogifyGeneratePublicPartCommand.php | 8 ++- src/Commands/BlogifyMigrateCommand.php | 3 +- src/Controllers/Admin/ApiController.php | 6 +- src/Controllers/Admin/BaseController.php | 1 + .../Admin/CategoriesController.php | 4 +- src/Controllers/Admin/CommentsController.php | 8 +-- src/Controllers/Admin/PostsController.php | 60 ++++++++++--------- src/Controllers/Admin/ProfileController.php | 11 ++-- src/Controllers/Admin/TagsController.php | 17 +++--- src/Controllers/Admin/UserController.php | 25 ++++---- src/Helpers.php | 8 --- src/Middleware/BlogifyAdminAuthenticate.php | 7 ++- src/Middleware/CanEditPost.php | 8 +-- src/Middleware/CanViewPost.php | 7 +-- src/Middleware/DenyIfBeingEdited.php | 4 +- src/Middleware/HasAdminOrAuthorRole.php | 5 +- src/Middleware/IsOwner.php | 2 +- src/Middleware/ProtectedPost.php | 1 + src/Requests/CategoryRequest.php | 15 ++++- src/Requests/ProfileUpdateRequest.php | 11 +++- 20 files changed, 120 insertions(+), 91 deletions(-) diff --git a/src/Commands/BlogifyGeneratePublicPartCommand.php b/src/Commands/BlogifyGeneratePublicPartCommand.php index d6b66be..2a17456 100644 --- a/src/Commands/BlogifyGeneratePublicPartCommand.php +++ b/src/Commands/BlogifyGeneratePublicPartCommand.php @@ -126,12 +126,14 @@ private function publishTemplates($namespace) */ private function publishViews() { - $path = __DIR__."/../../../../../resources/views/blogify/templates/"; + $basepath = __DIR__."/../../../../../resources/views/blogify/"; + $path = $basepath."templates/"; + if (!file_exists($path)) mkdir($path, 775, true); foreach ($this->views as $key => $file) { - $filename = __DIR__."/../../../../../resources/views/blogify/$key.blade.php"; + $filename = $basepath . "$key.blade.php"; if (file_exists($filename)) { if ($this->confirm("File $key allready exists, do you want to override it? Y/N")) @@ -147,7 +149,7 @@ private function publishViews() foreach ($this->layouts as $key => $file) { - $filename = __DIR__."/../../../../../resources/views/blogify/templates/$key.blade.php"; + $filename = $basepath . "templates/$key.blade.php"; if (file_exists($filename)) { if ($this->confirm("File $key allready exists, do you want to override it? Y/N")) diff --git a/src/Commands/BlogifyMigrateCommand.php b/src/Commands/BlogifyMigrateCommand.php index ab9d48e..06f93a9 100644 --- a/src/Commands/BlogifyMigrateCommand.php +++ b/src/Commands/BlogifyMigrateCommand.php @@ -2,7 +2,8 @@ use Illuminate\Console\Command; -class BlogifyMigrateCommand extends Command { +class BlogifyMigrateCommand extends Command +{ /** * The console command name. diff --git a/src/Controllers/Admin/ApiController.php b/src/Controllers/Admin/ApiController.php index 286c234..c377f0e 100644 --- a/src/Controllers/Admin/ApiController.php +++ b/src/Controllers/Admin/ApiController.php @@ -49,12 +49,12 @@ public function __construct(Post $post) */ public function sort($table, $column, $order, $trashed = false, DatabaseManager $db) { - $data = $db->table( $table ); + $data = $db->table($table); // Check for trashed data $data = $trashed ? $data->whereNotNull('deleted_at') : $data->whereNull('deleted_at'); - $data = $data->orderBy($column, $order)->paginate( $this->config->items_per_page ); + $data = $data->orderBy($column, $order)->paginate($this->config->items_per_page); return $data; } @@ -74,7 +74,7 @@ public function checkIfSlugIsUnique($slug) while ($this->post->whereSlug($slug)->get()->count() > 0) { $i++; - $slug = $this->base_slug . '-' . $i; + $slug = "$this->base_slug-$i"; } return $slug; diff --git a/src/Controllers/Admin/BaseController.php b/src/Controllers/Admin/BaseController.php index 3cab8c7..36d2cd3 100644 --- a/src/Controllers/Admin/BaseController.php +++ b/src/Controllers/Admin/BaseController.php @@ -31,4 +31,5 @@ public function __construct() $this->config = objectify( config('blogify') ); $this->auth_user = $this->auth->check() ? $this->auth->user() : false; } + } diff --git a/src/Controllers/Admin/CategoriesController.php b/src/Controllers/Admin/CategoriesController.php index 198131c..b9f6373 100644 --- a/src/Controllers/Admin/CategoriesController.php +++ b/src/Controllers/Admin/CategoriesController.php @@ -123,7 +123,7 @@ public function update ($hash, CategoryRequest $request) */ public function destroy($hash) { - $category = $this->category->byHash( $hash ); + $category = $this->category->byHash($hash); $category_name = $category->name; $category->delete(); @@ -163,7 +163,7 @@ public function restore($hash) */ private function storeOrUpdateCategory($request) { - $cat = $this->category->whereName( $request->name )->first(); + $cat = $this->category->whereName($request->name)->first(); if (count($cat) > 0) { diff --git a/src/Controllers/Admin/CommentsController.php b/src/Controllers/Admin/CommentsController.php index 38548e3..421b2e9 100644 --- a/src/Controllers/Admin/CommentsController.php +++ b/src/Controllers/Admin/CommentsController.php @@ -37,11 +37,11 @@ public function __construct(Comment $comment) */ public function index($revised = "pending") { - $revised = $this->checkRevised( $revised ); + $revised = $this->checkRevised($revised); if ($revised === false) abort(404); $data = [ - 'comments' => $this->comment->byRevised( $revised )->paginate( $this->config->items_per_page ), + 'comments' => $this->comment->byRevised($revised)->paginate($this->config->items_per_page), 'revised' => $revised, ]; @@ -65,7 +65,7 @@ public function changeStatus($hash, $new_revised) $revised = $this->checkRevised( $new_revised ); if ($revised === false) abort(404); - $comment = $this->comment->byHash( $hash ); + $comment = $this->comment->byHash($hash); $comment->revised = $revised; $comment->save(); @@ -90,7 +90,7 @@ public function changeStatus($hash, $new_revised) */ private function checkRevised($revised) { - $allowed = [1 => 'pending', Ò2 => 'approved', 3 => 'disapproved']; + $allowed = [1 => 'pending', 2 => 'approved', 3 => 'disapproved']; return array_search($revised, $allowed); } diff --git a/src/Controllers/Admin/PostsController.php b/src/Controllers/Admin/PostsController.php index a5687fa..eae1d45 100644 --- a/src/Controllers/Admin/PostsController.php +++ b/src/Controllers/Admin/PostsController.php @@ -144,7 +144,15 @@ public function index($trashed = false) { $scope = 'for'.$this->auth_user->role->name; $data = [ - 'posts' => (! $trashed) ? $this->post->$scope()->orderBy('publish_date', 'DESC')->paginate($this->config->items_per_page) : $this->post->$scope()->onlyTrashed()->orderBy('publish_date', 'DESC')->paginate($this->config->items_per_page), + 'posts' => (! $trashed) ? + $this->post->$scope() + ->orderBy('publish_date', 'DESC') + ->paginate($this->config->items_per_page) + : + $this->post->$scope() + ->onlyTrashed() + ->orderBy('publish_date', 'DESC') + ->paginate($this->config->items_per_page), 'trashed' => $trashed, ]; @@ -171,10 +179,10 @@ public function create() * @param $slug * @return \Illuminate\View\View */ - public function show ( $slug ) + public function show ($slug) { $data = [ - 'post' => $this->post->bySlug( $slug ), + 'post' => $this->post->bySlug($slug), ]; if ($data['post']->count() <= 0) abort(404); @@ -190,13 +198,13 @@ public function show ( $slug ) */ public function edit($hash) { - $p = $this->post->byHash($hash); - $hash = $this->auth_user->hash; - $post = ($this->cache->has("autoSavedPost-$hash")) ? $this->buildPostObject() : $p; - $data = $this->getViewData( $post ); + $originalPost = $this->post->byHash($hash); + $hash = $this->auth_user->hash; + $post = ($this->cache->has("autoSavedPost-$hash")) ? $this->buildPostObject() : $originalPost; + $data = $this->getViewData($post); - $p->being_edited_by = $this->auth_user->id; - $p->save(); + $originalPost->being_edited_by = $this->auth_user->id; + $originalPost->save(); return view('blogify::admin.posts.form', $data); } @@ -220,7 +228,7 @@ public function store(PostRequest $request) $post = $this->storeOrUpdatePost(); - if ($this->status->byHash($this->data->status)->name == 'Pending review') $this->mailReviewer( $post ); + if ($this->status->byHash($this->data->status)->name == 'Pending review') $this->mailReviewer($post); $action = ($request->hash == '') ? 'created' : 'updated'; @@ -228,6 +236,7 @@ public function store(PostRequest $request) $message = trans('blogify::notify.success', ['model' => 'Post', 'name' => $post->title, 'action' => $action]); session()->flash('notify', ['success', $message]); + $this->cache->forget('autoSavedPost'); return redirect()->route('admin.posts.index'); @@ -242,13 +251,11 @@ public function store(PostRequest $request) public function destroy($hash) { $post = $this->post->byHash($hash); - $name = $post->title; - $post->delete(); tracert()->log('posts', $post->id, $this->auth_user->id, 'delete'); - $message = trans('blogify::notify.success', ['model' => 'Post', 'name' => $name, 'action' =>'deleted']); + $message = trans('blogify::notify.success', ['model' => 'Post', 'name' => $post->title, 'action' =>'deleted']); session()->flash('notify', ['success', $message]); return redirect()->route('admin.posts.index'); @@ -267,7 +274,7 @@ public function destroy($hash) */ public function uploadImage(ImageUploadRequest $request) { - $image_name = $this->resizeAnsSaveImage( $request->file('upload') ); + $image_name = $this->resizeAndSaveImage($request->file('upload')); $path = config()->get('app.url').'/uploads/posts/' . $image_name; $func = $request->get('CKEditorFuncNum'); $result = ""; @@ -306,10 +313,9 @@ public function cancel($hash = null) public function restore($hash) { $post = $this->post->withTrashed()->byHash($hash); - $post_title = $post->title; $post->restore(); - $message = trans('blogify::notify.success', ['model' => 'Post', 'name' => $post_title, 'action' =>'restored']); + $message = trans('blogify::notify.success', ['model' => 'Post', 'name' => $post->title, 'action' =>'restored']); session()->flash('notify', ['success', $message]); return redirect()->route('admin.posts.index'); @@ -370,7 +376,7 @@ private function getViewData($post = null) * @param $image * @return string */ - private function resizeAnsSaveImage($image) + private function resizeAndSaveImage($image) { $image_name = $this->createImageName(); $fullpath = $this->createFullImagePath($image_name, $image->getClientOriginalExtension()); @@ -501,11 +507,11 @@ private function buildPostObject() $post['short_description'] = $cached_post['short_description']; $post['content'] = $cached_post['content']; $post['publish_date'] = $cached_post['publishdate']; - $post['status_id'] = $this->status->byHash( $cached_post['status'] )->id; - $post['visibility_id'] = $this->visibility->byHash( $cached_post['visibility'] )->id; - $post['reviewer_id'] = $this->user->ByHash( $cached_post['reviewer'] )->id; - $post['category_id'] = $this->category->byHash( $cached_post['category'] )->id; - $post['tag'] = $this->buildTagsArrayForPostObject( $cached_post['tags'] ); + $post['status_id'] = $this->status->byHash($cached_post['status'])->id; + $post['visibility_id'] = $this->visibility->byHash($cached_post['visibility'])->id; + $post['reviewer_id'] = $this->user->byHash($cached_post['reviewer'])->id; + $post['category_id'] = $this->category->byHash($cached_post['category'])->id; + $post['tag'] = $this->buildTagsArrayForPostObject($cached_post['tags']); return objectify($post); } @@ -521,14 +527,14 @@ private function buildTagsArrayForPostObject($tags) { if ($tags == "") return []; - $t = []; - $tags = explode(',', $tags); + $aTags = []; + $hashes = explode(',', $tags); - foreach ($tags as $tag) + foreach ($hashes as $tag) { - array_push($t, $this->tag->byHash($tag)); + array_push($aTags, $this->tag->byHash($tag)); } - return $t; + return $aTags; } } \ No newline at end of file diff --git a/src/Controllers/Admin/ProfileController.php b/src/Controllers/Admin/ProfileController.php index 137a9d7..dbfc959 100644 --- a/src/Controllers/Admin/ProfileController.php +++ b/src/Controllers/Admin/ProfileController.php @@ -122,12 +122,12 @@ private function resizeAndSaveProfilePicture($image, $filename) $extention = $image->getClientOriginalExtension(); $fullpath = $this->config->upload_paths->profiles->profilepictures . $filename . '.' . $extention; - Image::make( $image->getRealPath() ) - ->resize( $this->config->image_sizes->profilepictures[0], $this->config->image_sizes->profilepictures[1] , function ($constraint) { + Image::make($image->getRealPath()) + ->resize($this->config->image_sizes->profilepictures[0], $this->config->image_sizes->profilepictures[1] , function ($constraint) { $constraint->aspectRatio(); $constraint->upsize(); }) - ->save( $fullpath ); + ->save($fullpath); return $fullpath; } @@ -140,10 +140,7 @@ private function resizeAndSaveProfilePicture($image, $filename) */ private function removeOldPicture($oldPicture) { - if (file_exists($oldPicture)) - { - unlink($oldPicture); - } + if (file_exists($oldPicture)) unlink($oldPicture); } } \ No newline at end of file diff --git a/src/Controllers/Admin/TagsController.php b/src/Controllers/Admin/TagsController.php index e3b30fa..737f64b 100644 --- a/src/Controllers/Admin/TagsController.php +++ b/src/Controllers/Admin/TagsController.php @@ -1,6 +1,5 @@ (! $trashed) ? $this->tag->orderBy('created_at', 'DESC')->paginate($this->config->items_per_page) : $this->tag->onlyTrashed()->orderBy('created_at', 'DESC')->paginate($this->config->items_per_page), + 'tags' => (! $trashed) ? + $this->tag->orderBy('created_at', 'DESC') + ->paginate($this->config->items_per_page) + : + $this->tag->onlyTrashed() + ->orderBy('created_at', 'DESC') + ->paginate($this->config->items_per_page), 'trashed' => $trashed, ]; @@ -137,7 +142,7 @@ public function storeOrUpdate() */ public function update($hash, TagUpdateRequest $request) { - $tag = $this->tag->byHash( $hash ); + $tag = $this->tag->byHash($hash); $tag->name = $request->tags; $tag->save(); @@ -158,12 +163,11 @@ public function update($hash, TagUpdateRequest $request) public function destroy($hash) { $tag = $this->tag->byHash($hash); - $tag_name = $tag->name; $tag->delete(); tracert()->log('tags', $tag->id, $this->auth_user->id, 'delete'); - $message = trans('blogify::notify.success', ['model' => 'Tags', 'name' => $tag_name, 'action' =>'deleted']); + $message = trans('blogify::notify.success', ['model' => 'Tags', 'name' => $tag->name, 'action' =>'deleted']); session()->flash('notify', ['success', $message]); return redirect()->route('admin.tags.index'); @@ -176,10 +180,9 @@ public function destroy($hash) public function restore($hash) { $tag = $this->tag->withTrashed()->byHash($hash); - $tag_name = $tag->name; $tag->restore(); - $message = trans('blogify::notify.success', ['model' => 'Post', 'name' => $tag_name, 'action' =>'restored']); + $message = trans('blogify::notify.success', ['model' => 'Tag', 'name' => $tag->name, 'action' =>'restored']); session()->flash('notify', ['success', $message]); return redirect()->route('admin.tags.index'); diff --git a/src/Controllers/Admin/UserController.php b/src/Controllers/Admin/UserController.php index cde61a7..230b176 100644 --- a/src/Controllers/Admin/UserController.php +++ b/src/Controllers/Admin/UserController.php @@ -65,7 +65,13 @@ public function __construct(User $user, Role $role, BlogifyMailer $mail, Hash $h public function index($trashed = false) { $data = [ - 'users' => (! $trashed) ? $this->user->orderBy('name', 'ASC')->paginate($this->config->items_per_page) : $this->user->onlyTrashed()->orderBy('name', 'ASC')->paginate($this->config->items_per_page), + 'users' => (! $trashed) ? + $this->user->orderBy('name', 'ASC') + ->paginate($this->config->items_per_page) + : + $this->user->onlyTrashed() + ->orderBy('name', 'ASC') + ->paginate($this->config->items_per_page), 'trashed' => $trashed, ]; @@ -96,7 +102,7 @@ public function edit($hash) { $data = [ 'roles' => $this->role->all(), - 'user' => $this->user->byHash( $hash ), + 'user' => $this->user->byHash($hash), ]; return view('blogify::admin.users.form', $data); @@ -114,7 +120,7 @@ public function edit($hash) */ public function store(UserRequest $request) { - $data = $this->storeOrUpdateUser( $request ); + $data = $this->storeOrUpdateUser($request); $user = $data['user']; $mail_data = [ 'user' => $data['user'], @@ -125,7 +131,7 @@ public function store(UserRequest $request) tracert()->log('users', $user->id, $this->auth_user->id); - $message = trans('blogify::notify.success', ['model' => 'User', 'name' => generateFullName($user->firstname, $user->name), 'action' =>'created']); + $message = trans('blogify::notify.success', ['model' => 'User', 'name' => $user->fullName, 'action' =>'created']); session()->flash('notify', ['success', $message]); return redirect()->route('admin.users.index'); @@ -140,7 +146,7 @@ public function store(UserRequest $request) */ public function update(UserRequest $request, $hash) { - $data = $this->storeOrUpdateUser( $request, $hash ); + $data = $this->storeOrUpdateUser($request, $hash); $user = $data['user']; $message = trans('blogify::notify.success', ['model' => 'User', 'name' => generateFullName($user->firstname, $user->name), 'action' =>'updated']); @@ -159,13 +165,11 @@ public function update(UserRequest $request, $hash) public function destroy($hash) { $user = $this->user->byHash($hash); - $name = $user->firstname . ' ' . $user->name; - $user->delete(); tracert()->log('users', $user->id, $this->auth_user->id, 'delete'); - $message = trans('blogify::notify.success', ['model' => 'User', 'name' => $name, 'action' =>'deleted']); + $message = trans('blogify::notify.success', ['model' => 'User', 'name' => $user->fullName, 'action' =>'deleted']); session()->flash('notify', ['success', $message]); return redirect()->route('admin.users.index'); @@ -178,10 +182,9 @@ public function destroy($hash) public function restore($hash) { $user = $this->user->withTrashed()->byHash($hash); - $fullname = $user->fullName; $user->restore(); - $message = trans('blogify::notify.success', ['model' => 'Post', 'name' => $fullname, 'action' =>'restored']); + $message = trans('blogify::notify.success', ['model' => 'Post', 'name' => $user->fullName, 'action' =>'restored']); session()->flash('notify', ['success', $message]); return redirect()->route('admin.users.index'); @@ -200,7 +203,7 @@ private function storeOrUpdateUser($data, $hash = null) $password = blogify()->generatePassword(); $user = new User; $user->hash = blogify()->makeUniqueHash('users', 'hash'); - $user->password = $this->hash->make( $password ); + $user->password = $this->hash->make($password); $user->username = blogify()->generateUniqueUsername( $data->name, $data->firstname ); $user->name = $data->name; $user->firstname = $data->firstname; diff --git a/src/Helpers.php b/src/Helpers.php index db070f7..a2ec7aa 100644 --- a/src/Helpers.php +++ b/src/Helpers.php @@ -13,14 +13,6 @@ function blogify() } } -if (! function_exists('generateFullName')) -{ - function generateFullName($firstname, $lastname) - { - return $firstname . ' ' . $lastname; - } -} - if (! function_exists('objectify') ) { /** diff --git a/src/Middleware/BlogifyAdminAuthenticate.php b/src/Middleware/BlogifyAdminAuthenticate.php index d9343ef..a9abe1c 100644 --- a/src/Middleware/BlogifyAdminAuthenticate.php +++ b/src/Middleware/BlogifyAdminAuthenticate.php @@ -32,11 +32,12 @@ class BlogifyAdminAuthenticate * Create a new filter instance. * * @param Guard $auth + * @param Role $role */ - public function __construct(Guard $auth) + public function __construct(Guard $auth, Role $role) { $this->auth = $auth; - $this->roles = Role::byAdminRoles()->get(); + $this->roles = $role->byAdminRoles()->get(); $this->fillAllowedRolesArray(); } @@ -80,7 +81,7 @@ private function fillAllowedRolesArray() { foreach ($this->roles as $role) { - array_push( $this->allowed_roles, $role->id ); + array_push($this->allowed_roles, $role->id); } } diff --git a/src/Middleware/CanEditPost.php b/src/Middleware/CanEditPost.php index 91f84ec..603aef7 100644 --- a/src/Middleware/CanEditPost.php +++ b/src/Middleware/CanEditPost.php @@ -3,7 +3,6 @@ use Closure; use Illuminate\Contracts\Auth\Guard; use jorenvanhocht\Blogify\Models\Post; -use Request; class CanEditPost { @@ -43,7 +42,7 @@ public function __construct(Guard $auth, Post $post) */ public function handle($request, Closure $next) { - if (! $this->checkIfUserCanEditPost()) return redirect()->route('admin.dashboard'); + if (! $this->checkIfUserCanEditPost($request)) return redirect()->route('admin.dashboard'); return $next($request); } @@ -52,11 +51,12 @@ public function handle($request, Closure $next) * Check if the user has permission * to edit the requested post * + * @param $request * @return bool */ - private function checkIfUserCanEditPost() + private function checkIfUserCanEditPost($request) { - $post = $this->post->byHash( Request::segment(3) ); + $post = $this->post->byHash($request->segment(3)); $user_id = $this->auth->user()->id; if ($user_id != $post->user_id && $user_id != $post->reviewer_id && $this->auth->user()->role->name != 'Admin') return false; diff --git a/src/Middleware/CanViewPost.php b/src/Middleware/CanViewPost.php index e82c44c..49a814b 100644 --- a/src/Middleware/CanViewPost.php +++ b/src/Middleware/CanViewPost.php @@ -3,7 +3,6 @@ use Closure; use Illuminate\Contracts\Auth\Guard; use jorenvanhocht\Blogify\Models\Post; -use Request; class CanViewPost { @@ -43,7 +42,7 @@ public function __construct(Guard $auth, Post $post) */ public function handle($request, Closure $next) { - if (! $this->checkIfUserCanViewPost()) return redirect()->route('/'); + if (! $this->checkIfUserCanViewPost($request)) return redirect()->route('/'); return $next($request); } @@ -54,9 +53,9 @@ public function handle($request, Closure $next) * * @return bool */ - private function checkIfUserCanViewPost() + private function checkIfUserCanViewPost($request) { - $post = $this->post->byHash(Request::segment(3)); + $post = $this->post->byHash($request->segment(3)); $user_id = $this->auth->user()->id; if ($post->visibility_id == 'Private') diff --git a/src/Middleware/DenyIfBeingEdited.php b/src/Middleware/DenyIfBeingEdited.php index d282fdf..13a6cc3 100644 --- a/src/Middleware/DenyIfBeingEdited.php +++ b/src/Middleware/DenyIfBeingEdited.php @@ -3,7 +3,6 @@ use App\User; use Closure; use Illuminate\Contracts\Auth\Guard; -use Request; use jorenvanhocht\Blogify\Models\Post; class DenyIfBeingEdited @@ -35,6 +34,7 @@ class DenyIfBeingEdited * * @param Guard $auth * @param Post $post + * @param User $user */ public function __construct(Guard $auth, Post $post, User $user) { @@ -52,7 +52,7 @@ public function __construct(Guard $auth, Post $post, User $user) */ public function handle($request, Closure $next) { - $hash = Request::segment(3); + $hash = $request->segment(3); $post = $this->post->byHash($hash); if ($post->being_edited_by != null && $post->being_edited_by != $this->auth->user()->id) diff --git a/src/Middleware/HasAdminOrAuthorRole.php b/src/Middleware/HasAdminOrAuthorRole.php index d2ee4fe..a470334 100644 --- a/src/Middleware/HasAdminOrAuthorRole.php +++ b/src/Middleware/HasAdminOrAuthorRole.php @@ -67,7 +67,10 @@ public function handle($request, Closure $next) */ private function fillAlowedRolesArray() { - $roles = $this->role->where('name', '<>', 'Reviewer')->where('name', '<>', 'Member')->get(); + $roles = $this->role + ->where('name', '<>', 'Reviewer') + ->where('name', '<>', 'Member') + ->get(); foreach ($roles as $role) { diff --git a/src/Middleware/IsOwner.php b/src/Middleware/IsOwner.php index 285665d..6789b9c 100644 --- a/src/Middleware/IsOwner.php +++ b/src/Middleware/IsOwner.php @@ -24,8 +24,8 @@ class IsOwner /** * Create a new filter instance. * - * @param User $user * @param Guard $auth + * @param User $user */ public function __construct(Guard $auth, User $user) { diff --git a/src/Middleware/ProtectedPost.php b/src/Middleware/ProtectedPost.php index fba12c8..04f1717 100644 --- a/src/Middleware/ProtectedPost.php +++ b/src/Middleware/ProtectedPost.php @@ -23,6 +23,7 @@ class ProtectedPost * Create a new filter instance. * * @param Guard $auth + * @param Post $post */ public function __construct(Guard $auth, Post $post) { diff --git a/src/Requests/CategoryRequest.php b/src/Requests/CategoryRequest.php index b5c1d94..b9733e0 100644 --- a/src/Requests/CategoryRequest.php +++ b/src/Requests/CategoryRequest.php @@ -6,6 +6,19 @@ class CategoryRequest extends Request { + /** + * @var Category + */ + protected $category; + + /** + * @param Category $category + */ + public function __construct(Category $category) + { + $this->category = $category; + } + /** * Determine if the user is authorized to make this request. * @@ -24,7 +37,7 @@ public function authorize() public function rules() { $segment = $this->segment(3); - $id = isset($segment) ? Category::byHash($this->segment(3))->id : 0; + $id = isset($segment) ? $this->category->byHash($this->segment(3))->id : 0; return [ 'name' => "required|unique:categories,name,$id|min:3|max:45", diff --git a/src/Requests/ProfileUpdateRequest.php b/src/Requests/ProfileUpdateRequest.php index 2c97b0b..d6fa24e 100644 --- a/src/Requests/ProfileUpdateRequest.php +++ b/src/Requests/ProfileUpdateRequest.php @@ -22,6 +22,11 @@ class ProfileUpdateRequest extends Request */ protected $hash; + /** + * @var User + */ + protected $user; + /** * Holds the id of the user * that we are trying to edit @@ -34,10 +39,12 @@ class ProfileUpdateRequest extends Request * Construct the class * * @param Guard $auth + * @param User $user */ - public function __construct(Guard $auth) + public function __construct(Guard $auth, User $user) { $this->auth = $auth; + $this->user = $user; } /** @@ -83,6 +90,6 @@ public function rules() */ private function getUserId() { - return User::byHash($this->hash)->id; + return $this->user->byHash($this->hash)->id; } }