laravel-middleware

Laravel 5.2 : Web middleware is applied twice

落花浮王杯 提交于 2019-11-28 14:38:51
Here is my routes.php code Route::auth(); Route::group(['middleware' => 'web'], function () { Route::group(['namespace' => 'Admin', 'prefix' => 'admin', 'middleware' => ['auth','role:Admin']], function(){ Route::get('/home', 'HomeController@index'); Route::get('user/data', ['as' => 'admin.user.data','uses'=>'UserController@userData']); Route::resource('user', 'UserController'); Route::get('merchant/data', ['as' => 'admin.merchant.data','uses'=>'MerchantController@merchantData']); Route::resource('merchant', 'MerchantController'); Route::get('bcategory/data', ['as' => 'admin.bcategory.data',

Laravel 5.2, auth::check return true after login but false after redirect

帅比萌擦擦* 提交于 2019-11-28 10:52:18
问题 I'm trying to use the authentication system that comes built in with laravel 5.2. The login seems to be working correctly, if I replace the return statement with Auth::check(), it returns true. But when I redirect to '/', Auth::check() suddenly returns false in my Auth middleware. Sessions Create method: public function create(Request $request) { $email = $request->email; $password = $request->password; if(Auth::attempt(['email' => $email, 'password' => $password])) { return redirect()-

Laravel Middleware return variable to controller

拥有回忆 提交于 2019-11-27 17:47:46
I am carrying out a permissions check on a user to determine whether they can view a page or not. This involves passing the request through some middleware first. The problem I have is I am duplicating the same database query in the middleware and in the controller before returning the data to the view itself. Here is an example of the setup; -- routes.php Route::get('pages/{id}', [ 'as' => 'pages', 'middleware' => 'pageUser' 'uses' => 'PagesController@view' ]); -- PageUserMiddleware.php (class PageUserMiddleware) public function handle($request, Closure $next) { //get the page $pageId =

Laravel middleware with multiple roles

筅森魡賤 提交于 2019-11-27 10:24:27
问题 I've been running into some issues with Laravel's middleware. Let me tell you the basic idea of what I'm trying to accomplish: Registered users on the site will have one of four roles: Student (default): can access ' index ' and ' show ' views Approver: can access previous, plus ' overview ', ' update ' Editor: can access previous, plus ' create ', ' edit ' and ' store ' Admin: can access everything fyi: 'overview' is sort of an index view, but only for approver role and higher What would you

Undefined variable: errors in Laravel

寵の児 提交于 2019-11-27 04:09:20
When I want to register a user in my laravel project, the page always says Undefined variable: errors (View: /var/www/resources/views/auth/register.blade.php)" According to the Laravel documentation, $errors should always automatically be set: So, it is important to note that an $errors variable will always be available in all of your views on every request, allowing you to conveniently assume the $errors variable is always defined and can be safely used. I have this on on every view when I use: @if (count($errors) > 0) <div class="alert alert-danger"> <ul> @foreach ($errors->all() as $error)

Undefined variable: errors in Laravel

独自空忆成欢 提交于 2019-11-26 09:09:36
问题 When I want to register a user in my laravel project, the page always says Undefined variable: errors (View: /var/www/resources/views/auth/register.blade.php)\" According to the Laravel documentation, $errors should always automatically be set: So, it is important to note that an $errors variable will always be available in all of your views on every request, allowing you to conveniently assume the $errors variable is always defined and can be safely used. I have this on on every view when I