laravel-middleware

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

ぃ、小莉子 提交于 2021-01-27 04:57:12
问题 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 web.php Route::get('/end', [EndPageController::class, 'index']) ->name('survey.end') ->middleware('App\Http\Middleware\LegacyEndCheck'); Middleware LegacyEndCheck.php handle function public function handle($request, Closure $next) { $sjid = $request->input('sjid',

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

非 Y 不嫁゛ 提交于 2021-01-27 04:56:44
问题 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 web.php Route::get('/end', [EndPageController::class, 'index']) ->name('survey.end') ->middleware('App\Http\Middleware\LegacyEndCheck'); Middleware LegacyEndCheck.php handle function public function handle($request, Closure $next) { $sjid = $request->input('sjid',

How to enable both api and web guard in laravel

你。 提交于 2021-01-27 04:27:31
问题 Laravel 5.7 PHP 7.2.10 Currently I am able to use any one of web and api guards, is there any way to allow both, so that both web app and api will work together. Something like return [ /* |-------------------------------------------------------------------------- | Authentication Defaults |-------------------------------------------------------------------------- | | This option controls the default authentication "guard" and password | reset options for your application. You may change

How does Laravel know whether a middleware should be run after the request handled?

半腔热情 提交于 2021-01-05 08:13:25
问题 I read the source code, and there is only a pipeline which reads all middlewares as an array. These middlewares should be run before the request dispatchToRouter. return (new Pipeline($this->app)) ->send($request) ->through($this->app->shouldSkipMiddleware() ? [] : $this->middleware) ->then($this->dispatchToRouter()); However, if I created an after-middleware, the after-middleware should be run after the request handled. here and when the after-middleware being execute in the laravel source

Laravel: Encode JSON responses in UTF-8

最后都变了- 提交于 2020-05-27 05:15:32
问题 I want to encode the JSON responses of my API to UTF-8, but every time I make a response I don't want to do this: return response()->json($res,200,['Content-type'=>'application/json;charset=utf-8'],JSON_UNESCAPED_UNICODE); So I thought about making a middleware for all API routes which handle(...) function would be this: public function handle($request, Closure $next) { $response = $next($request); $response->header('Content-type','application/json; charset=utf-8'); return $next($request); }

Temporarily disable / bypass Middleware

北慕城南 提交于 2020-01-02 03:47:09
问题 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 the request must provide an authorization header or the application quits with an OAuthException. Now I want to unittest my controllers. So I have to seed my database with a OAuth session and access token for every test. Then overwrite the call()

Laravel Middleware return variable to controller

浪子不回头ぞ 提交于 2019-12-28 04:50:06
问题 I am carrying out a permissions check on a user to determine whether they can view a page or not. This involves passing the request through some middleware first. The problem I have is I am duplicating the same database query in the middleware and in the controller before returning the data to the view itself. Here is an example of the setup; -- routes.php Route::get('pages/{id}', [ 'as' => 'pages', 'middleware' => 'pageUser' 'uses' => 'PagesController@view' ]); -- PageUserMiddleware.php

Laravel use resource controller method $id parameter as middleware parameter

泪湿孤枕 提交于 2019-12-25 04:20:01
问题 I am trying to make a middleware to check if the user has the permissions required to view certain pages. Below the code that I currently use to call the middleware. I now pass the name of the role the user needs to have but I also want to pass through the required id that is used when the store method is called. Is there a way to do this or should I make either a seperate function in this controller or move the route checking middleware to the routes.php? I prefer not to move it because this