laravel-authorization

How to use One Laravel Controller with Multiple Guard instead of Duplicating the Controller

六月ゝ 毕业季﹏ 提交于 2021-02-11 15:42:16
问题 I have two Guards Admin User Also i have created controllers where user can manage his own data and admin can also manage user data. So i created two Controllers Controllers Admin EducatonBackgroundController User EducationBackgroundController In User/EducationBackgroundController i have this function which fetch education background of a current logged user and display on the user view public function index(Education $education) { try { $educations = $education->where('user_id',$this-

laravel nova hide edit button on index page

橙三吉。 提交于 2021-01-05 09:57:12
问题 How to disable edit/delete button on nova index page and still allow in detail page, if I will create a policy, that will disable the operation everywhere, I want to allow edit and delete in detail page, but just want to remove those button from index, is doing something like public function update(User $user, Customer $customer) { if ( request()->route()->getName('route-name') ) { return false; } } is correct way or there is any better way? 回答1: I had a resource of Leads and I needed to hide

Laravel: Using multiple columns for authentication

和自甴很熟 提交于 2020-08-26 10:36:15
问题 I have a Laravel 6 application. In a typical application, the user would just specify their email , where the email is unique. However, in my application, I have 2 columns in the User model that is used to authenticate users. app_id email unique(app_id, email) So in order to login, we need to pass both an app_id and an email , along with the password . The same email could be used across different app_id s. How would I achieve this? 回答1: The default login actions provided by Auth::routes()

Laravel: Using multiple columns for authentication

孤者浪人 提交于 2020-08-26 10:35:28
问题 I have a Laravel 6 application. In a typical application, the user would just specify their email , where the email is unique. However, in my application, I have 2 columns in the User model that is used to authenticate users. app_id email unique(app_id, email) So in order to login, we need to pass both an app_id and an email , along with the password . The same email could be used across different app_id s. How would I achieve this? 回答1: The default login actions provided by Auth::routes()

Authorizing Resource Controllers in Laravel Post does not work?

随声附和 提交于 2020-08-20 03:11:11
问题 I have created a ProductPolicy where I have: <?php namespace App\Policies; use App\Models\Product; use App\Models\Vendor; use App\User; use Illuminate\Auth\Access\HandlesAuthorization; class ProductPolicy { use HandlesAuthorization; public function before($user, $ability){ if($user->roles == 'admin' || $user->roles == 'editor'){ return true; } } public function viewAny(User $user) { return true; } public function view(User $user, Product $product) { $vendor_id = Vendor::where('user_id', $user

Authorizing Resource Controllers in Laravel Post does not work?

女生的网名这么多〃 提交于 2020-08-20 03:10:16
问题 I have created a ProductPolicy where I have: <?php namespace App\Policies; use App\Models\Product; use App\Models\Vendor; use App\User; use Illuminate\Auth\Access\HandlesAuthorization; class ProductPolicy { use HandlesAuthorization; public function before($user, $ability){ if($user->roles == 'admin' || $user->roles == 'editor'){ return true; } } public function viewAny(User $user) { return true; } public function view(User $user, Product $product) { $vendor_id = Vendor::where('user_id', $user

Laravel blade @can policy - string

こ雲淡風輕ζ 提交于 2020-07-16 06:10:12
问题 I am using Laravel 5.2. So I'm learning about how to deal with roles and permissions Authorization. Everything runs fine. I even made my own policy PostPolicy. And now to the problem. I load the $post data into the view in the PostsController which then loads in blade. PostsController : public function show($id) { $post = Post::find($id); return view('posts.show', compact('post')); } posts/show.blade.php : @section('content') <!-- begin --> @can('hasRole', Auth::user()) <h1>Displaying Admin

Laravel passport refresh token

三世轮回 提交于 2020-01-01 12:20:08
问题 I am using a Laravel version 5.5 using Passport for authentication. I have successfully create the token and can access it using the auth:api middleware. But whenever user login into system it create new token for that user. I just want to refresh user last token and send it back instead of creating a new token. I have used the following code to generate auth token $token = $user->createToken('string-'.$user->id)->accessToken; It generate the token with 1075 characters but when i checked in

How to check if user's status is active in laravel 5.x?

走远了吗. 提交于 2019-12-14 02:35:44
问题 I have set a bit different login logic in AuthController provided by laravel 5.2. The code is protected function authenticated(Request $request) { $email = $request->input('email'); $password = $request->input('password'); if (Auth::attempt(['email' => $email, 'password' => $password, 'is_active' => 1])) { return redirect()->intended('admin/dashboard'); } return $this->sendFailedLoginResponse($request); } The code works fine. But the problem when user is not active, it still get logged in as