laravel-middleware

Laravel Middleware Auth for API

99封情书 提交于 2019-12-22 12:17:16
问题 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 requests can be authenticated either of the ways. I can work out how to have one or the other but not both, how could I do this? I'm thinking I need to create a custom middleware that uses these existing middlewares? I am using Laravel 5.1 Thanks 回答1

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

痴心易碎 提交于 2019-12-21 17:33:13
问题 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 = $request->getHost(); $parts = explode('.', $host); if ($parts[0] == 'admin') { // Set the config for user info (not sponsor) Config::set('auth.model', 'Admin'); Config::set('auth.table', 'admins'); } }); I tried creating middleware for this in laravel 5 and have

Laravel - Passing variables from Middleware to controller/route

余生颓废 提交于 2019-12-21 07:27:19
问题 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

Laravel 419 Error - VerifyCsrfToken issue

◇◆丶佛笑我妖孽 提交于 2019-12-19 10:08:59
问题 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, working contact forms, and I'm generating and sending the token exactly the same way - with {{ csrf_field() }} . I found an answer to a similar question stating that you can disable Csrf checking by adding entries to the $except array in app/Http

How to set the Laravel middleware order of execution?

∥☆過路亽.° 提交于 2019-12-18 11:46:25
问题 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

Laravel 5.2 : Web middleware is applied twice

感情迁移 提交于 2019-12-17 21:23:15
问题 Here is my routes.php code Route::auth(); Route::group(['middleware' => 'web'], function () { Route::group(['namespace' => 'Admin', 'prefix' => 'admin', 'middleware' => ['auth','role:Admin']], function(){ Route::get('/home', 'HomeController@index'); Route::get('user/data', ['as' => 'admin.user.data','uses'=>'UserController@userData']); Route::resource('user', 'UserController'); Route::get('merchant/data', ['as' => 'admin.merchant.data','uses'=>'MerchantController@merchantData']); Route:

Class 'App\Http\Middleware\DB' not found when using Middleware in Laravel 5

我是研究僧i 提交于 2019-12-13 02:13:56
问题 So I want to check whether the database is connected in laravel 5.I used Middlewares for this. Middleware code Middleware.php namespace App\Http\Middleware; use Closure; class MyMiddleware { /** * Handle an incoming request. * * @param \Illuminate\Http\Request $request * @param \Closure $next * @return mixed */ public function handle($request, Closure $next) { if(DB::connection()->getDatabaseName()) { echo "conncted sucessfully to database ".DB::connection()->getDatabaseName(); }else{ die(

How to retrieve a url parameter from request in Laravel 5?

核能气质少年 提交于 2019-12-12 11:13:05
问题 I want to perform certain operations with a model in a middleware. Here is an example of what I want to achieve: public function handle($request, Closure $next) { $itemId = $request->param('item'); // <-- invalid code, serves for illustration purposes only $item = Item::find($itemId); if($item->isBad()) return redirect(route('dont_worry')); return $next($request); } My question is, how can I retrieve the desired parameter from the $request ? 回答1: public function handle(Request $request,

Laravel 5.2 Does not show errors in register

最后都变了- 提交于 2019-12-12 03:09:15
问题 I add my routes in web middleware . When I post null value in register, it does not show me validation errors. But when I remove web middleware from my route it works correctly. Route::group(['middleware' => ['web']], function () { Route::auth(); } it does not work, but Route::auth(); works correctly Kernel.php protected $middleware = [ \Illuminate\Foundation\Http\Middleware\CheckForMaintenanceMode::class, \Illuminate\Session\Middleware\StartSession::class, \Illuminate\View\Middleware

Laravel two diffrent middleware authentication from auth middleware only

℡╲_俬逩灬. 提交于 2019-12-11 18:34:21
问题 I have two seprate table for authentication. Following middleware pointing to different table: $this->middleware('auth:admin'); // - admins $this->middleware('auth'); // - user The solution i need : I want authentication must be done with two diffrent table through only " $this->middleware('auth') " middleware Through middleware " $this->middleware('auth') " I want to login both admin and user. Currently admin and user login from diffrent middleware I have shown above. For this, in which file