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
4
votes
2 answers

How to send Authorization access_token to request header in Laravel using Middleware

I'm Bulid an API Authentication System. Everything I can check using Postman But I want to attach this mark portion (please see the image) that's means the header portion send from my controller or middleware with request header. How Can I do this…
Gabrielle-M
  • 1,037
  • 4
  • 17
  • 39
4
votes
0 answers

Can we intercept outgoing http requests from a node js app using middleware like "Intercepting outgoing servlet http requests in java"

I have several http requests in my node.js app. I want to intercept the outgoing http requests and add a token in the header without changing the code in the app by introducing the interception code as an middleware or wrapper as in java
niku
  • 51
  • 2
  • 7
4
votes
4 answers

Laravel only retrieve Model Records if they belong to authenticated user

I'm using Laravel 5.4 and have a Model called Order. To test things I've created two users and two Orders, each user having one Order. I've just seen that I'm able to retrieve the order of someone who is not my current user. I'm retrieving a list of…
xTheWolf
  • 1,756
  • 4
  • 18
  • 43
4
votes
2 answers

How handle() method of Laravel middleware is called using 'Clousre $next' in another Middleware?

Here is a handle() method from Laravel's ValidatePostSize: public function handle($request, Closure $next) { $max = $this->getPostMaxSize(); if ($max > 0 && $request->server('CONTENT_LENGTH') > $max) { throw new…
Mayank Kumar
  • 176
  • 1
  • 1
  • 14
4
votes
3 answers

Accessing Route URL Parameter in Middleware in Laravel 5.3

I am having a hard time accessing the Route URL Parameter in Middleware after updating from Laravel 5.1 to Laravel 5.3. Here is my route file: Route::group(['middleware' => ['app.access']], function() { Route::resource('apps/{apps}/houses',…
Neel
  • 9,352
  • 23
  • 87
  • 128
4
votes
4 answers

Laravel Middleware / Route Groups

I'm fairly new to Laravel, so this question may obvious to some. In the case of running checks per HTTP request, for example User Authentication. Is there a better, more efficient or simple correct way to run these checks. From my initial research…
scottevans93
  • 1,119
  • 1
  • 9
  • 25
4
votes
5 answers

How to register middlewares in OctoberCMS plugin?

Registering middlewares in Laravel is easy: simply list the middleware class in the $middleware property of your app/Http/Kernel.php class or If you would like to assign middleware to specific routes, you should first assign the middleware a…
B Faley
  • 17,120
  • 43
  • 133
  • 223
4
votes
2 answers

How to log every response in laravel 5.2 framework

I was using below code for logging each and every request and response for my API but now it's not working for Laravel 5.2. I have tried to use https://laravel.com/docs/5.2/middleware#terminable-middleware but not succeed. use Closure; use…
Jitender Thakur
  • 490
  • 5
  • 15
4
votes
1 answer

In Laravel, should I check for permission in controller if already checking on middleware?

I created a middleware that checks if the user is authorized to perform an action and added this middleware to the routes that I want to protect like this: // VerifyPermission middleware class VerifyPermission { /** * Handle an incoming…
enriqg9
  • 1,455
  • 1
  • 21
  • 40
4
votes
2 answers

Laravel 5 : multi-model middleware "Owner"

I want to create a middleware to check if the authenticated user is the owner of the item. For a single model, the code is easy and would look something like :
BassMHL
  • 8,523
  • 9
  • 50
  • 67
4
votes
1 answer

In Laravel 5 how do I implement an App::before() filter?

In Laravel 4.2 I had this before filter that set the Eloquent model and table based on the URL (admin.example.com vs example.com) Here is my filter code: App::before(function($request) { // Check if we are using the admin URL $host =…
ScottM
  • 88
  • 1
  • 10
3
votes
2 answers

Laravel 8 + Jetsream: How to Redirect to Prior Page After Login?

I have a basic web page where I want the user to be able to click the login link, go through the login, and then be returned to that page (not the home page). The page has some features that can only be seen when the user is logged in. I am having…
Daniel C
  • 607
  • 2
  • 8
  • 20
3
votes
0 answers

Auth is not working in middleware in Laravel

I have successfully loggedin my adminpanel but while I redirect to dashboard after login using middleware it's not working. login controller if (Auth::attempt(['username' => $request->email, 'password' => $request->password])) { return…
3
votes
1 answer

How to pass more than one gate in middleware? (Laravel)

I am creating a Learning Management System for my university final year project (only recently introduced to laravel). I have set up three different roles (admin, instructor and student). I have created two views which only the admin&instructor can…
Zak
  • 185
  • 2
  • 4
  • 12
3
votes
2 answers

Call to a member function setCookie() on null - Laravel 5.8

I have no idea why I keep getting this lately by just simply navigate between pages. Call to a member function setCookie() on null This is what I have in my AdminMiddleware
code-8
  • 54,650
  • 106
  • 352
  • 604