laravel-authorization

auth() method null on Exceptions

江枫思渺然 提交于 2019-12-13 16:05:23
问题 I was playing around with Laravel 5.4.23 and i came across this scenario when i hit a 404 page the auth() , auth()->check() , auth()->user() , and those are not initialized thus returning null in views, or anywhere near that. i even went to AppServiceProvider.php class to do some tests, dd(auth()->check()); returns Null in the boot method, even if i'm logged in, which makes 0 sense to me. that means, whenever a users hits a 404 page, navbars and so on will not render the user data like for

How to Use Auth() Register During Login Session in Laravel 5.7

让人想犯罪 __ 提交于 2019-12-13 06:35:43
问题 I have changed the register page of Laravel 5.7 Auth() to the studentRegister page to register a new student, but it is inaccessible when I'm logged in through another user. The route didn't work while I'm in the session. However, it works perfectly after logging out from one session. Please suggest how I can register a new student while I'm logged in. studentRegister.blade.php I have removed {{csrf}} as well. @extends('layouts.app') @section('content') <div class="container"> <div class="row

How to define a policy method with no argument in Laravel 5.2?

时光总嘲笑我的痴心妄想 提交于 2019-12-11 01:57:41
问题 It's sometimes necessary to check user authorization for an action with no argument like create/store method: class PostPolicy { use HandlesAuthorization; /** * Determine if the user can create a new post. * * @param \App\User $user * @return bool */ public function create(User $user) { if($user->is_admin) { return true; } return false; } } and use the authorize method in PostController: class PostController extends Controller { /** * Show the form for creating a new post. * * @return

How to return custom 403 exception when using Laravel 5.1 authorize method

假装没事ソ 提交于 2019-12-11 01:18:47
问题 In laravel 5.1 you can return a custom response when you check abilities if you use the following method: if (Gate::denies('update', $post)) { return response()->view('errors.403'); } Is there any way to return a similar custom error when using the authorize method: $this->authorize('update', $post); The above simply throws a http exception with status code 403. 回答1: I can do it in following way: In App\Http\Controllers\Controller add the following method: protected function

How to define or pass auth guard for broadcast authentication routes instead of default auth guard?

北战南征 提交于 2019-12-10 19:26:15
问题 I am very new to realtime event broadcasting, I have simple laravel-echo-server setup and working with everything. I am unable to set/define authentication against other auth guard it is always checking with user/default guard defined in auth.php I have setup the authentication routes for each guards private channels in routes/channel.php as below per documentation. For auth guard user private channels Broadcast::channel('users.{id}', function ($user, $id) { Log::info(class_basename($user));

Laravel 5.3 Password Broker Customization

元气小坏坏 提交于 2019-11-30 12:12:26
问题 Does anyone know how to override the functions used within laravel's password broker? I know the docs: https://laravel.com/docs/5.3/passwords#resetting-views Give information on what to do for things like views and a few surface level things but it's not clear at all really or maybe I'm not reading it enough times. I already know how to override the ResetsPasswords.php Trait but overriding the functionality of the Password::broker() is for the next layer in. If there is more information

Laravel 5.2: Auth::logout() is not working

血红的双手。 提交于 2019-11-29 01:36:21
I'm building a very simple app in Laravel 5.2, but when using AuthController 's action to log out, it just simply doesn't work. I have a nav bar which checks for Auth::check() and it doesn't change after calling the log out action. I have this route inside the routes.php file: Route::get('users/logout', 'Auth\AuthController@getLogout'); and it's outside the Route::group(['middleware' => ['web']], function () statement. I did also try to add the follow action at the end of the AuthController.php file. public function getLogout() { $this->auth->logout(); Session::flush(); return redirect('/'); }

Laravel 5.2: Auth::logout() is not working

纵饮孤独 提交于 2019-11-27 16:05:38
问题 I'm building a very simple app in Laravel 5.2, but when using AuthController 's action to log out, it just simply doesn't work. I have a nav bar which checks for Auth::check() and it doesn't change after calling the log out action. I have this route inside the routes.php file: Route::get('users/logout', 'Auth\AuthController@getLogout'); and it's outside the Route::group(['middleware' => ['web']], function () statement. I did also try to add the follow action at the end of the AuthController

Can Anyone Explain Laravel 5.2 Multi Auth with Example

随声附和 提交于 2019-11-26 00:29:51
问题 I am trying to authenticate users and admin form user table and admin table respectively. I am using the User model as provided by laravel out of the box and created the same for Admin. I have added a guard key and provider key into auth.php. Guards \'guards\' => [ \'user\' =>[ \'driver\' => \'session\', \'provider\' => \'user\', ], \'admin\' => [ \'driver\' => \'session\', \'provider\' => \'admin\', ], ], Providers \'providers\' => [ \'user\' => [ \'driver\' => \'eloquent\', \'model\' => App