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
-1
votes
1 answer

Lavavel Middleware does not exist

I have recently moved to Laravel from the normal php and I have managed to finish a project in my localhost, everything works fine at least to my expectation but when I moved my files to the server, I am experincing a middleware issue. Now I have a…
-1
votes
1 answer

My authorize function is always failing in laravel-5.8?

I created one policy inside create function i am checking weather this user can able to create records and i am registering the Model and policy in the AthServiceProvider.php after that i am checking inside the controller by using…
-1
votes
1 answer

"Call to a member function send() on strin" error appear when my middleware run on laravel

I want to make a middleware to redirect all my requests to 'dashboard' route if my database is empty, but this error appears on page. public function handle(Request $request, Closure $next) { $wallets = Wallet::get()->count(); echo…
-1
votes
1 answer

web guard allows login but admin guard does not allow login

I define a new guard "Admin" to have a multi Auth System User and admin in my project . web guard allows login.But admin guard does not allow login when I try to login into Admin ,it gives SQLSTATE[42S22]: Column not found: 1054 Unknown column…
-1
votes
1 answer

Laravel check middleware for AJAX request

Thank you in advance I have one middleware that is used to check the user is logged in or not. it is working absolutely fine for synchronous request, For example, the user is logged out, after that they made one ajax request at that time middleware…
Ronak Solanki
  • 341
  • 2
  • 5
  • 14
-1
votes
3 answers

Add middleware to controller in __construct in Laravel

I am trying to assign a middleware in __construct of a controller based on Laravel docs but it throws the follwing error: BadMethodCallException Method App\Http\Controllers\MyController::middlware does not exist. that is my controller…
Sam
  • 1,424
  • 13
  • 28
-1
votes
2 answers

check the status is active or not in middleware

I have a table called agents and I want to check in middleware when the agent is trying to log in, the agent is active or not public function handle($request, Closure $next) { $user = $this->auth->user(); …
itxrahulsingh
  • 53
  • 1
  • 11
-1
votes
1 answer

Laravel cannot pass multiple middleware

recently i created two middlewares which is one for user called device, and one other for super user which is high level of admin. This is my middleware Role Device Middleware
Abdan Syakuro
  • 1,034
  • 2
  • 12
  • 26
-1
votes
1 answer

laravel 5.1 middleware class not exist

I have implemented my own middleware on local machine. It is working fine on local machine. But, when I uploaded the files on server, then it gives the error like middleware class not exist. Same error given when I created the custom helper.
-1
votes
1 answer

Performance issues in eloquent queries during middleware

I have a case where the exact same eloquent builder query is being run twice. This is on purpose to try and figure this out. Basically when the query executes inside of the route middleware it takes over 5000ms to complete. However in the controller…
-1
votes
1 answer

Route Action Method in Laravel 5.4

I am trying to do a before-action check on a route. Therefore I set up a middleware as follows:
Josh
  • 1,660
  • 5
  • 33
  • 55
-2
votes
3 answers

middleware doesn't able to get the route parameter in Laravel

this is my code: the route: Route::get('lang/change', [LangController::class, 'change'])->name('changeLang'); nav.blade.php
Select Language:
Osama Mohammed
  • 2,433
  • 13
  • 29
  • 61
-2
votes
2 answers

How to listen to GET param in laravel middleware

I'm trying to listen to simple get param (test param) in laravel middleware. here is my code Route::middleware('api')->get('/betshistory', function (Request $request) { return $request->user(); }); here is my…
sortof
  • 530
  • 1
  • 8
  • 18
-2
votes
1 answer

What is the difference from the auth, web and guard middleware in Laravel 5.8

I'm a newbie in Laravel. Can someone explain what is the difference from web, auth, and guest middleware in Laravel 5.8?
-2
votes
3 answers

Explain how to use Session In The Constructor Laravel 5.3

according to laravel docs https://laravel.com/docs/5.3/upgrade#5.3-session-in-constructors i can no longer access the session in the construct because the middleware isnt loaded yet , they provided an example that i couldnt understand public…
1 2 3
37
38