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

Laravel Call to a member function setCookie() on null - when returning controller action from middleware

Hello Good Developers, This is Not a Direct Duplicate of: Call to a member function setCookie() on null As I am calling a Controller action from Middleware and then in the controller action I am returning View, Here's My Route from…
Pankaj Jha
  • 886
  • 15
  • 37
6
votes
3 answers

Apply Auth Middleware to All Laravel Routes

What is the correct way to authenticate all routes except login and register when I apply auth middleware in all controllers? Is there a way to apply auth middleware in one place and exclude login, register routes?
user3351236
  • 2,488
  • 10
  • 29
  • 52
6
votes
7 answers

Laravel 419 Error - VerifyCsrfToken issue

I have multiple Laravel sites hosted on the same server. With the latest site I've created, the contact form refuses to submit without throwing a 419 error. I have set up the routing in my web.php file just like the other websites, which have live,…
Chad
  • 1,531
  • 3
  • 20
  • 46
6
votes
2 answers

laravel VerifyCsrfToken excepts url with wildcard?

I try to build my own API. I begin so my only model for the moment will be a "User". Here is how I would like to call my API : HTTP/POST http://example.com/api/user/ # get all the users HTTP/POST http://example.com/api/user/1 # get…
Anwar
  • 4,162
  • 4
  • 41
  • 62
6
votes
1 answer

Laravel blade template specific code

Currently we are using the Laravel framework on several projects, but one issue we keep running into which i don't like is the following issue: Lets say you have a Homepage and a Content page HomepageController has all Homepage specific php code…
RemcoDN
  • 143
  • 10
6
votes
3 answers

Temporarily disable / bypass Middleware

In my Application I implemented a OAuth2-Server (oauth2-server-laravel) in combination with a custom Authentication Package (Sentinel by Cartalyst). In my routes.php: Route::group(['before' => 'oauth'], function() { // ... some routes here } So…
rookian
  • 1,045
  • 14
  • 38
5
votes
4 answers

Laravel Rate Limiter Limits Access Wrongly After Only One Attempt

I'm working with Laravel 5.8 and I wanted to set up a Rate Limiter that limits accessing to route by per minute and also IP address. So I added this to RouteServiceProvider.php: protected function configureRateLimiting() { …
Pouya
  • 114
  • 1
  • 8
  • 36
5
votes
3 answers

Laravel test for URL param in middleware BEFORE group Middleware

I am using a middleware to check for the existence of a login token from another site. If the login token is present and the user is not already logged in, I would like to use the token to log the user in and send them to their intended page. If…
Lance
  • 3,193
  • 2
  • 32
  • 49
5
votes
0 answers

Laravel locale middleware not working for all routes & locale session destroys after logout

I am working Multi-language website. I have created a middleware for locale. Locale is working fine with Home, Login & Registration views. But, it is not working with auth/passwords/reset.blade.php and auth/passwords/email.blade.php. When I press…
G Naga Subrahmanyam
  • 308
  • 1
  • 5
  • 19
5
votes
2 answers

Laravel Middleware Auth for API

I am currently developing and application that has an API which I want to be accessible through middleware that will check if the user is authenticated using either Laravel's default Auth middleware and Tymone's JWT.Auth token based middleware so…
rosscooper
  • 1,976
  • 3
  • 16
  • 29
5
votes
1 answer

How to understand Laravel framework completely?

I have gone through Laravel beginners tutorial, and now I can understand every topics listed in those tutorials and have created my own project, but as I saw in those, the tutors were able to understand what each file was meant for and had the…
rranj
  • 288
  • 1
  • 5
  • 16
5
votes
4 answers

Laravel 5 - how to use basic auth with username in place of email?

Hello guys ! So in Laravel 4 we could do Route::filter('auth.basic', function() { return Auth::basic('username'); }); But now it's not possible, and the doc doesn't give a clue about how to. So can anyone help ? Thanks !
5
votes
1 answer

Laravel 5 localization: exclude /public/ directory

I am trying to implement localization in my Laravel 5 project and I'm running into an issue. The middleware that I put in to catch the language is as follows:
watzon
  • 2,401
  • 2
  • 33
  • 65
5
votes
1 answer

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

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

Class App\Http\Middleware\Authenticate:api does not exist on Broadcasting

I am having an issue with the auth:api guard working with broadcasting. I get the error Class App\Http\Middleware\Authenticate:api does not exist if I call php artisan route:list. BroadcastServiceProvider.php:
1 2
3
37 38