Questions tagged [laravel-middleware]

HTTPl Middleware is a mechanism for filtering HTTP requests that are passing through your application. Middleware allows you to add additional layers around your business logic.

Laravel includes a middleware that verifies the user of your application is authenticated. If the user is not authenticated, the middleware will redirect the user to the login screen. However, if the user is authenticated, the middleware will allow the request to proceed further into the application.

Of course, middleware can be written to perform a variety of tasks besides authentication. A CORS middleware might be responsible for adding the proper headers to all responses leaving your application. A logging middleware might log all incoming requests to your application.

There are several middleware included in the Laravel framework, including middleware for maintenance, authentication, CSRF protection, and more. All of these middleware are located in the app/Http/Middleware directory.

Reference

558 questions
0
votes
1 answer

Laravel Middleware not working on some resource route

I am following a tutorial for making a access level restriction: https://gist.github.com/amochohan/8cb599ee5dc0af5f4246 I was able to make it work somehow but there's something I need to get working which is not in the tutorial. Provided I have…
jackhammer013
  • 2,295
  • 11
  • 45
  • 95
0
votes
1 answer

Laravel 5.2 custom Middleware Levels on RESTful controllers

So from not using any framework at all, I finally forced myself to use LARAVEL 5.2 because i got tired of re-writing my own "framework" over and over again. Anyway! I think I'm pretty familiar with the Laravel framework and its dependencies now. But…
0
votes
1 answer

Laravel 5.2- Restrict user acess

I'm working on a Laravel 5.2 project and I have users ,flags and countrys. What im trying to achieve is that each user can click on the Flag menu, and it should present a list of flags for the country the user is in. so User has country_id Flags…
marybane
  • 75
  • 1
  • 1
  • 7
0
votes
1 answer

Laravel and Sentinel: mix roles middleware for authorization

I'm a Laravel newbie (VERY newbie) using Cartalyst Sentinel on Laravel 5.2 to leverage roles authorizations. On the admin section I have three (or more) roles, i.e. "admin", "agent" and "writer". I also have some sections that should have mixed…
Ivan
  • 2,463
  • 6
  • 39
  • 51
0
votes
2 answers

Laravel 5.2 How to change redirects of RedirectIfAuthenticated depending on Controller?

I'm wondering if it is possible to make the authentication redirect differently for each of my controllers? Currently, everything redirects to /home. This is intended for my HomeController. But for ClientController, I want it to redirect to /client…
0
votes
2 answers

In Laravel, Middleware is ignored in ajax request?

This is the method in controller. It is requested by x-editable ajax. /** * Update base info such as status. * * @param Request $request * @return mixed */ public function postUpdateInfo(Request $request) { $this->middleware('recruit'); …
Germey
  • 640
  • 6
  • 12
0
votes
2 answers

Laravel 5 global middleware not working

I have a route group in my routes.php file with the middleware specified like so: Route::group(['prefix' => 'api', 'middleware' => 'api'], function() { Route::post('oauth/access_token', function() { return…
Anindit Karmakar
  • 825
  • 1
  • 8
  • 26
0
votes
1 answer

Models, Resource Controllers and Middleware in Laravel 5.1

I have several resources in Laravel 5.1 that are represented by models. The models all have account_id and user_id. There is a pivot table of user_account that represents the relationship between accounts and users. I have my routes in routes.php…
Joshua Ziering
  • 145
  • 2
  • 8
0
votes
2 answers

Registering Laravel middleware

Just starting to get into laravel and running into major issues migrating my vanilla php to use it. I created a middleware
moh_abk
  • 2,064
  • 7
  • 36
  • 65
0
votes
2 answers

redirect loop with middleware in laravel 5

//Route. Route::get('user/program', ['as' => 'chose.program', function(){ dd('brake'); }]); Middleware code: public function handle($request, Closure $next) { if(Auth::check()){ $v = Opt::user_get('goal_chosen'); …
0
votes
2 answers

Checking admin roles in laravel 5.1

I'm doing my project using Laravel framework. Everything seems to be perfect. However, in my login part, I want to do something like when a user login into the system, it will check the "is_admin" column. If the "is_admin" column is equal to 1, it…
Huy Le
  • 339
  • 1
  • 2
  • 11
0
votes
1 answer

Using middleware for table manipulation laravel 5.1

Currently I am developing a small to middle level application in laravel I came across middleware in laravel, My question is Can i use middleware for making changes in my table for eg, In my application(Canteen Management System), When user orders…
0
votes
3 answers

Laravel use route parameter in middleware

Couldn't find anything that specifically matches my situation. I have a route group defined as: Route::group(['prefix' => 'api/v1/{access_token}'], function(){ ... } The above group has several resource routes inside. I am trying to create a…
Vince
  • 3,207
  • 1
  • 17
  • 28
0
votes
1 answer

Why is codeception running middleware on routes in Laravel which should not be run?

So I am a codeception newbie and I am trying to figure out how to test my web service using the same. I have written my first simple test for the authenticate route just to make sure that the application is spitting out the JWT token like it should.…
Rohan
  • 13,308
  • 21
  • 81
  • 154
0
votes
2 answers

Laravel: Custom Middleware is applying on each route

I created a middleware as: use Closure; use Gate; class ACLMiddleware { /** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public…
Volatil3
  • 14,253
  • 38
  • 134
  • 263