{"action":"closed","issue":{"url":"https://api.github.com/repos/laravel/framework/issues/16184","repository_url":"https://api.github.com/repos/laravel/framework","labels_url":"https://api.github.com/repos/laravel/framework/issues/16184/labels{/name}","comments_url":"https://api.github.com/repos/laravel/framework/issues/16184/comments","events_url":"https://api.github.com/repos/laravel/framework/issues/16184/events","html_url":"https://github.com/laravel/framework/issues/16184","id":186134527,"number":16184,"title":"Policy not working ","user":{"login":"Vocal","id":5045717,"avatar_url":"https://avatars.githubusercontent.com/u/5045717?v=3","gravatar_id":"","url":"https://api.github.com/users/Vocal","html_url":"https://github.com/Vocal","followers_url":"https://api.github.com/users/Vocal/followers","following_url":"https://api.github.com/users/Vocal/following{/other_user}","gists_url":"https://api.github.com/users/Vocal/gists{/gist_id}","starred_url":"https://api.github.com/users/Vocal/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/Vocal/subscriptions","organizations_url":"https://api.github.com/users/Vocal/orgs","repos_url":"https://api.github.com/users/Vocal/repos","events_url":"https://api.github.com/users/Vocal/events{/privacy}","received_events_url":"https://api.github.com/users/Vocal/received_events","type":"User","site_admin":false},"labels":[],"state":"closed","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":3,"created_at":"2016-10-30T12:52:02Z","updated_at":"2016-10-30T17:02:38Z","closed_at":"2016-10-30T17:02:38Z","body":"- Laravel Version: 5.3.21\r\n- PHP Version: \r\n- Database Driver & Version: \r\n\r\nHi all,\r\ni'm using Policy to authorization but it's not working on all route.\r\n\r\n## Description \r\n\r\n\r\n1.Create default controller using \r\n\r\n`php artisan make:controller PostController --resource`\r\n\r\n2.Create policy \r\n\r\n`php artisan make:policy PostPolicy --model=Post`\r\n\r\n3.In **PostPolicy** return true for each action (view, create, update, delete)\r\n\r\n`public function view(User $user, Post $post)\r\n    {\r\n        return $user->id === 1;\r\n    }`\r\n\r\n4.Register policy in the **AuthServiceProvider**\r\n\r\n`protected $policies = [\r\n        'App\\Model' => 'App\\Policies\\ModelPolicy',\r\n        Post::class => PostPolicy::class,\r\n    ];`\r\n\r\n5.In **web.php** add routes\r\n\r\n`Route::resource('post', 'PostController');`\r\n\r\n6.in PostController add **authorizeResource** method\r\n\r\n`public function __construct()\r\n    {\r\n        $this->authorizeResource(Post::class);\r\n    }`\r\n\r\n7.Access to URL from browser.\r\n \r\nMETHOD\r\n[GET]   _http://laravel.local:8000/post_ (post.index)  ==> worked\r\n[DELETE] _http://laravel.local:8000/post/1_ (post.destroy)  ==> worked\r\n[GET] _http://laravel.local:8000/post/create_ (post.create)  ==> worked\r\n[POST] _http://laravel.local:8000/post/create_ (post.store)  ==> worked\r\n[GET] _http://laravel.local:8000/1/edit_ (post.edit)  ==> Error : This action is unauthorized.\r\n[GET]   _http://laravel.local:8000/1_ (post.show) ==> Error : This action is unauthorized.\r\n\r\n8.in post_index.blade \r\n\r\n`@can('view', $post)\r\n    <a href=\"{{ route('post.show', ['post' => $post])}}\">Show</a>\r\n@endcan`\r\n\r\n`@can('update', $post)\r\n    <a href=\"{{ route('post.edit', ['post' => $post])}}\">Edit</a>\r\n@endcan`\r\n\r\nResult : **Show, Edit** link is display correct. (in view check policy is correct ??)\r\n\r\n2 routes :  **edit** and **show** is not working. "}}
{"actor":{"display_login":"Vocal"}}