Last active
October 15, 2017 16:34
-
-
Save FernandoBasso/3469ccbef72a8e2dfc8a03b6dbffa90b to your computer and use it in GitHub Desktop.
catch not catching ...
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Http\Middleware; | |
use Closure; | |
use Illuminate\Support\Facades\Auth; | |
<?php | |
class Admin | |
{ | |
/** | |
* Handle an incoming request. | |
* | |
* @param \Illuminate\Http\Request $request | |
* @param \Closure $next | |
* @return mixed | |
*/ | |
public function handle($request, Closure $next) | |
{ | |
if (Auth::check() && (Auth::user()->isEditor() || Auth::user()->isAdmin())) { | |
return $next($request); | |
} | |
return redirect('/admin'); | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Http\Controllers\Admin; | |
use Illuminate\Http\Request; | |
use App\Http\Controllers\Controller; | |
use App\PostCategory; | |
use Illuminate\Support\Facades\Auth; | |
use Illuminate\Auth\Access\AuthorizationException; | |
use Illuminate\Auth\Access\AccessDeniedHttpException; | |
class PostCategoriesController extends Controller | |
{ | |
public function __construct() | |
{ | |
// Causes exception, but catch wont catch anything and won't redirect. | |
try { | |
$this->authorizeResource(PostCategory::class); | |
} | |
//catch (AccessDeniedHttpException $err) { | |
// return redirect()->route('admin.welcome'); | |
//} | |
catch (\Exception $err) { | |
return redirect()->route('admin.welcome'); | |
} | |
} | |
/** | |
* Display a listing of the resource. | |
* | |
* @return \Illuminate\Http\Response | |
*/ | |
public function index() | |
{ | |
$post_categories = PostCategory::all(); | |
return view('admin.post-categories.index', ['post_categories' => $post_categories]); | |
} | |
/** | |
* Show the form for creating a new resource. | |
* | |
* @return \Illuminate\Http\Response | |
*/ | |
public function create() | |
{ | |
// This works... | |
try { | |
$this->authorize('create'); | |
return view('admin.post-categories.create'); | |
} catch (\Exception $err) { | |
return redirect()->route('admin.welcome'); | |
} | |
} | |
/** | |
* Store a newly created resource in storage. | |
* | |
* @param \Illuminate\Http\Request $request | |
* @return \Illuminate\Http\Response | |
*/ | |
public function store(Request $request) | |
{ | |
$inputs = $request->all(); | |
PostCategory::create($inputs); | |
return redirect()->route('post-categories.index'); | |
} | |
/** | |
* Display the specified resource. | |
* | |
* @param int $id | |
* @return \Illuminate\Http\Response | |
*/ | |
public function show($id) | |
{ | |
// | |
} | |
/** | |
* Show the form for editing the specified resource. | |
* | |
* @param int $id | |
* @return \Illuminate\Http\Response | |
*/ | |
public function edit($id) | |
{ | |
$post_category = PostCategory::find($id); | |
return view('admin.post-categories.edit', ['post_category' => $post_category]); | |
} | |
/** | |
* Update the specified resource in storage. | |
* | |
* @param \Illuminate\Http\Request $request | |
* @param int $id | |
* @return \Illuminate\Http\Response | |
*/ | |
public function update(Request $request, $id) | |
{ | |
$post_category = PostCategory::find($id); | |
$post_category->update($request->all()); | |
return redirect()->route('post-categories.index'); | |
} | |
/** | |
* Remove the specified resource from storage. | |
* | |
* @param int $id | |
* @return \Illuminate\Http\Response | |
*/ | |
public function destroy($id) | |
{ | |
// | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+--------+-----------+--------------------------------------------+-------------------------+------------------------------------------------------------------------+--------------------------------------------+ | |
| Domain | Method | URI | Name | Action | Middleware | | |
+--------+-----------+--------------------------------------------+-------------------------+------------------------------------------------------------------------+--------------------------------------------+ | |
| | GET|HEAD | / | | Closure | web | | |
| | GET|HEAD | admin | admin.welcome | Closure | web,auth,admin | | |
| | GET|HEAD | admin/post-categories | post-categories.index | App\Http\Controllers\Admin\PostCategoriesController@index | web,auth,admin | | |
| | POST | admin/post-categories | post-categories.store | App\Http\Controllers\Admin\PostCategoriesController@store | web,auth,admin,can:create,App\PostCategory | | |
| | GET|HEAD | admin/post-categories/create | post-categories.create | App\Http\Controllers\Admin\PostCategoriesController@create | web,auth,admin,can:create,App\PostCategory | | |
| | GET|HEAD | admin/post-categories/{post_category} | post-categories.show | App\Http\Controllers\Admin\PostCategoriesController@show | web,auth,admin,can:view,post_category | | |
| | PUT|PATCH | admin/post-categories/{post_category} | post-categories.update | App\Http\Controllers\Admin\PostCategoriesController@update | web,auth,admin,can:update,post_category | | |
| | DELETE | admin/post-categories/{post_category} | post-categories.destroy | App\Http\Controllers\Admin\PostCategoriesController@destroy | web,auth,admin,can:delete,post_category | | |
| | GET|HEAD | admin/post-categories/{post_category}/edit | post-categories.edit | App\Http\Controllers\Admin\PostCategoriesController@edit | web,auth,admin,can:update,post_category | | |
| | GET|HEAD | admin/posts | posts.index | App\Http\Controllers\Admin\PostsController@index | web,auth,admin | | |
| | POST | admin/posts | posts.store | App\Http\Controllers\Admin\PostsController@store | web,auth,admin | | |
| | GET|HEAD | admin/posts/create | posts.create | App\Http\Controllers\Admin\PostsController@create | web,auth,admin | | |
| | GET|HEAD | admin/posts/{post} | posts.show | App\Http\Controllers\Admin\PostsController@show | web,auth,admin | | |
| | PUT|PATCH | admin/posts/{post} | posts.update | App\Http\Controllers\Admin\PostsController@update | web,auth,admin | | |
| | DELETE | admin/posts/{post} | posts.destroy | App\Http\Controllers\Admin\PostsController@destroy | web,auth,admin | | |
| | GET|HEAD | admin/posts/{post}/edit | posts.edit | App\Http\Controllers\Admin\PostsController@edit | web,auth,admin | | |
| | GET|HEAD | api/user | | Closure | api,auth:api | | |
| | GET|HEAD | home | home | App\Http\Controllers\HomeController@index | web,auth | | |
| | GET|HEAD | login | login | App\Http\Controllers\Auth\LoginController@showLoginForm | web,guest | | |
| | POST | login | | App\Http\Controllers\Auth\LoginController@login | web,guest | | |
| | POST | logout | logout | App\Http\Controllers\Auth\LoginController@logout | web | | |
| | GET|HEAD | noticias | | App\Http\Controllers\Site\PostsController@index | web | | |
| | POST | password/email | password.email | App\Http\Controllers\Auth\ForgotPasswordController@sendResetLinkEmail | web,guest | | |
| | GET|HEAD | password/reset | password.request | App\Http\Controllers\Auth\ForgotPasswordController@showLinkRequestForm | web,guest | | |
| | POST | password/reset | | App\Http\Controllers\Auth\ResetPasswordController@reset | web,guest | | |
| | GET|HEAD | password/reset/{token} | password.reset | App\Http\Controllers\Auth\ResetPasswordController@showResetForm | web,guest | | |
| | GET|HEAD | register | register | App\Http\Controllers\Auth\RegisterController@showRegistrationForm | web,guest | | |
| | POST | register | | App\Http\Controllers\Auth\RegisterController@register | web,guest | | |
+--------+-----------+--------------------------------------------+-------------------------+------------------------------------------------------------------------+--------------------------------------------+ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException thrown with message "This action is unauthorized." | |
Stacktrace: | |
#55 Symfony\Component\HttpKernel\Exception\AccessDeniedHttpException in /home/fernando/develop/VBSMidia/1newprojs/simplecms/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php:201 | |
#54 Illuminate\Foundation\Exceptions\Handler:prepareException in /home/fernando/develop/VBSMidia/1newprojs/simplecms/vendor/laravel/framework/src/Illuminate/Foundation/Exceptions/Handler.php:175 | |
#53 Illuminate\Foundation\Exceptions\Handler:render in /home/fernando/develop/VBSMidia/1newprojs/simplecms/app/Exceptions/Handler.php:51 | |
#52 App\Exceptions\Handler:render in /home/fernando/develop/VBSMidia/1newprojs/simplecms/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:83 | |
#51 Illuminate\Routing\Pipeline:handleException in /home/fernando/develop/VBSMidia/1newprojs/simplecms/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:55 | |
#50 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /home/fernando/develop/VBSMidia/1newprojs/simplecms/app/Http/Middleware/Admin.php:20 | |
#49 App\Http\Middleware\Admin:handle in /home/fernando/develop/VBSMidia/1newprojs/simplecms/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:149 | |
#48 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in /home/fernando/develop/VBSMidia/1newprojs/simplecms/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53 | |
#47 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /home/fernando/develop/VBSMidia/1newprojs/simplecms/vendor/laravel/framework/src/Illuminate/Routing/Middleware/SubstituteBindings.php:41 | |
#46 Illuminate\Routing\Middleware\SubstituteBindings:handle in /home/fernando/develop/VBSMidia/1newprojs/simplecms/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:149 | |
#45 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in /home/fernando/develop/VBSMidia/1newprojs/simplecms/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53 | |
#44 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /home/fernando/develop/VBSMidia/1newprojs/simplecms/vendor/laravel/framework/src/Illuminate/Auth/Middleware/Authenticate.php:43 | |
#43 Illuminate\Auth\Middleware\Authenticate:handle in /home/fernando/develop/VBSMidia/1newprojs/simplecms/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:149 | |
#42 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in /home/fernando/develop/VBSMidia/1newprojs/simplecms/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53 | |
#41 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /home/fernando/develop/VBSMidia/1newprojs/simplecms/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/VerifyCsrfToken.php:67 | |
#40 Illuminate\Foundation\Http\Middleware\VerifyCsrfToken:handle in /home/fernando/develop/VBSMidia/1newprojs/simplecms/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:149 | |
#39 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in /home/fernando/develop/VBSMidia/1newprojs/simplecms/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53 | |
#38 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /home/fernando/develop/VBSMidia/1newprojs/simplecms/vendor/laravel/framework/src/Illuminate/View/Middleware/ShareErrorsFromSession.php:49 | |
#37 Illuminate\View\Middleware\ShareErrorsFromSession:handle in /home/fernando/develop/VBSMidia/1newprojs/simplecms/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:149 | |
#36 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in /home/fernando/develop/VBSMidia/1newprojs/simplecms/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53 | |
#35 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /home/fernando/develop/VBSMidia/1newprojs/simplecms/vendor/laravel/framework/src/Illuminate/Session/Middleware/StartSession.php:63 | |
#34 Illuminate\Session\Middleware\StartSession:handle in /home/fernando/develop/VBSMidia/1newprojs/simplecms/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:149 | |
#33 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in /home/fernando/develop/VBSMidia/1newprojs/simplecms/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53 | |
#32 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /home/fernando/develop/VBSMidia/1newprojs/simplecms/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/AddQueuedCookiesToResponse.php:37 | |
#31 Illuminate\Cookie\Middleware\AddQueuedCookiesToResponse:handle in /home/fernando/develop/VBSMidia/1newprojs/simplecms/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:149 | |
#30 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in /home/fernando/develop/VBSMidia/1newprojs/simplecms/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53 | |
#29 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /home/fernando/develop/VBSMidia/1newprojs/simplecms/vendor/laravel/framework/src/Illuminate/Cookie/Middleware/EncryptCookies.php:59 | |
#28 Illuminate\Cookie\Middleware\EncryptCookies:handle in /home/fernando/develop/VBSMidia/1newprojs/simplecms/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:149 | |
#27 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in /home/fernando/develop/VBSMidia/1newprojs/simplecms/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53 | |
#26 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /home/fernando/develop/VBSMidia/1newprojs/simplecms/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:102 | |
#25 Illuminate\Pipeline\Pipeline:then in /home/fernando/develop/VBSMidia/1newprojs/simplecms/vendor/laravel/framework/src/Illuminate/Routing/Router.php:647 | |
#24 Illuminate\Routing\Router:runRouteWithinStack in /home/fernando/develop/VBSMidia/1newprojs/simplecms/vendor/laravel/framework/src/Illuminate/Routing/Router.php:622 | |
#23 Illuminate\Routing\Router:runRoute in /home/fernando/develop/VBSMidia/1newprojs/simplecms/vendor/laravel/framework/src/Illuminate/Routing/Router.php:588 | |
#22 Illuminate\Routing\Router:dispatchToRoute in /home/fernando/develop/VBSMidia/1newprojs/simplecms/vendor/laravel/framework/src/Illuminate/Routing/Router.php:577 | |
#21 Illuminate\Routing\Router:dispatch in /home/fernando/develop/VBSMidia/1newprojs/simplecms/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:176 | |
#20 Illuminate\Foundation\Http\Kernel:Illuminate\Foundation\Http\{closure} in /home/fernando/develop/VBSMidia/1newprojs/simplecms/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:30 | |
#19 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /home/fernando/develop/VBSMidia/1newprojs/simplecms/vendor/fideloper/proxy/src/TrustProxies.php:56 | |
#18 Fideloper\Proxy\TrustProxies:handle in /home/fernando/develop/VBSMidia/1newprojs/simplecms/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:149 | |
#17 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in /home/fernando/develop/VBSMidia/1newprojs/simplecms/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53 | |
#16 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /home/fernando/develop/VBSMidia/1newprojs/simplecms/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php:30 | |
#15 Illuminate\Foundation\Http\Middleware\TransformsRequest:handle in /home/fernando/develop/VBSMidia/1newprojs/simplecms/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:149 | |
#14 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in /home/fernando/develop/VBSMidia/1newprojs/simplecms/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53 | |
#13 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /home/fernando/develop/VBSMidia/1newprojs/simplecms/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/TransformsRequest.php:30 | |
#12 Illuminate\Foundation\Http\Middleware\TransformsRequest:handle in /home/fernando/develop/VBSMidia/1newprojs/simplecms/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:149 | |
#11 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in /home/fernando/develop/VBSMidia/1newprojs/simplecms/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53 | |
#10 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /home/fernando/develop/VBSMidia/1newprojs/simplecms/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/ValidatePostSize.php:27 | |
#9 Illuminate\Foundation\Http\Middleware\ValidatePostSize:handle in /home/fernando/develop/VBSMidia/1newprojs/simplecms/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:149 | |
#8 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in /home/fernando/develop/VBSMidia/1newprojs/simplecms/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53 | |
#7 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /home/fernando/develop/VBSMidia/1newprojs/simplecms/vendor/laravel/framework/src/Illuminate/Foundation/Http/Middleware/CheckForMaintenanceMode.php:46 | |
#6 Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode:handle in /home/fernando/develop/VBSMidia/1newprojs/simplecms/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:149 | |
#5 Illuminate\Pipeline\Pipeline:Illuminate\Pipeline\{closure} in /home/fernando/develop/VBSMidia/1newprojs/simplecms/vendor/laravel/framework/src/Illuminate/Routing/Pipeline.php:53 | |
#4 Illuminate\Routing\Pipeline:Illuminate\Routing\{closure} in /home/fernando/develop/VBSMidia/1newprojs/simplecms/vendor/laravel/framework/src/Illuminate/Pipeline/Pipeline.php:102 | |
#3 Illuminate\Pipeline\Pipeline:then in /home/fernando/develop/VBSMidia/1newprojs/simplecms/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:151 | |
#2 Illuminate\Foundation\Http\Kernel:sendRequestThroughRouter in /home/fernando/develop/VBSMidia/1newprojs/simplecms/vendor/laravel/framework/src/Illuminate/Foundation/Http/Kernel.php:116 | |
#1 Illuminate\Foundation\Http\Kernel:handle in /home/fernando/develop/VBSMidia/1newprojs/simplecms/public/index.php:55 | |
#0 require_once in /home/fernando/develop/VBSMidia/1newprojs/simplecms/server.php:21 |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment