laravel-middleware

Laravel - Passing variables from Middleware to controller/route

左心房为你撑大大i 提交于 2019-12-04 01:05:42
How can I pass variables from a middleware to a controller or a route that executes such middleware? I saw some post about appending it to the request like this: $request->attributes->add(['key' => $value); also others sugested using flash: Session::flash('key', $value); but I am not sure if that is best practice, or if there is a better way to do this? Here is my Middleware and route: namespace App\Http\Middleware; use Closure; class TwilioWorkspaceCapability { /** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public

Restrict route access to non-admin users

纵然是瞬间 提交于 2019-12-03 07:48:25
问题 Goal I'm trying to create Admin route restriction for my log-in users. I've tried a check to see if my user is log-in , and also if the user type is Admin , and if they are, I want to allow them access to the admin route, otherwise, respond a 404. routes.php <!-- Route group --> $router->group(['middleware' => 'auth'], function() { <!-- No Restriction --> Route::get('dashboard','WelcomeController@index'); <!-- Admin Only --> if(Auth::check()){ if ( Auth::user()->type == "Admin" ){ //Report

Restrict route access to non-admin users

不羁的心 提交于 2019-12-02 21:13:40
Goal I'm trying to create Admin route restriction for my log-in users. I've tried a check to see if my user is log-in , and also if the user type is Admin , and if they are, I want to allow them access to the admin route, otherwise, respond a 404. routes.php <!-- Route group --> $router->group(['middleware' => 'auth'], function() { <!-- No Restriction --> Route::get('dashboard','WelcomeController@index'); <!-- Admin Only --> if(Auth::check()){ if ( Auth::user()->type == "Admin" ){ //Report Route::get('report','ReportController@index'); Route::get('report/create', array('as'=>'report.create',

Can I use Laravel 5 Middleware to allow packages to override app routes?

跟風遠走 提交于 2019-12-01 19:56:44
问题 I would like to be able to override the routes defined in app/Http/routes.php with a route in a package. For example, in app/Http/routes.php I might have this: Route::get('/search/{type?}',['as' => 'search','uses' => 'SearchController@search']); I want to be able to define this in /vendor/author/package/src/Http/routes.php: Route::get('/search/properties', ['as' => 'properties','uses' => 'PropertyController@search']); The app/Http/routes.php file is loaded first so the route in their is used,

Can I use Laravel 5 Middleware to allow packages to override app routes?

二次信任 提交于 2019-12-01 18:01:40
I would like to be able to override the routes defined in app/Http/routes.php with a route in a package. For example, in app/Http/routes.php I might have this: Route::get('/search/{type?}',['as' => 'search','uses' => 'SearchController@search']); I want to be able to define this in /vendor/author/package/src/Http/routes.php: Route::get('/search/properties', ['as' => 'properties','uses' => 'PropertyController@search']); The app/Http/routes.php file is loaded first so the route in their is used, not the package. In Laravel 4 I would do this using App::before or App::after, giving them a priority.

Laravel 5 Resourceful Routes Plus Middleware

强颜欢笑 提交于 2019-11-30 10:37:59
问题 Is it possible to add middleware to all or some items of a resourceful route? For example... <?php Route::resource('quotes', 'QuotesController'); Furthermore, if possible, I wanted to make all routes aside from index and show use the auth middleware. Or would this be something that needs to be done within the controller? 回答1: In QuotesController constructor you can then use: $this->middleware('auth', ['except' => ['index','show']]); Reference: Controller middleware in Laravel 5 回答2: You could

How to set the Laravel middleware order of execution?

瘦欲@ 提交于 2019-11-30 04:49:09
The Laravel 5 documentation describes two ways of assigning Middleware : Assign middleware to the controller's route. Specify middleware within your controller's constructor. However, I realised that any code written in the controllers __construct() function will run before the Middleware , even if the Middleware is declared on the first line of the controller's __construct function. I found a bug report for a similar issue in the Laravel github repository. However a collaborator closed the issue stating "This is the expected behaviour.". I am thinking that middleware should be "layers"

Laravel 5 Resourceful Routes Plus Middleware

笑着哭i 提交于 2019-11-29 21:14:22
Is it possible to add middleware to all or some items of a resourceful route? For example... <?php Route::resource('quotes', 'QuotesController'); Furthermore, if possible, I wanted to make all routes aside from index and show use the auth middleware. Or would this be something that needs to be done within the controller? In QuotesController constructor you can then use: $this->middleware('auth', ['except' => ['index','show']]); Reference: Controller middleware in Laravel 5 You could use Route Group coupled with Middleware concept: http://laravel.com/docs/master/routing Route::group([

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

不想你离开。 提交于 2019-11-29 17:21:10
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()->intended('/'); // returns true when replaced with Auth::check(); } return redirect("login"); } Auth

Laravel middleware with multiple roles

百般思念 提交于 2019-11-28 18:28:25
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 guys suggest is the best way to go about doing this? This is what I've done so far, but it doesn't