PHPFixing
  • Privacy Policy
  • TOS
  • Ask Question
  • Contact Us
  • Home
  • PHP
  • Programming
  • SQL Injection
  • Web3.0

Thursday, January 13, 2022

[FIXED] How to customize an auth of multi auth in Laravel?

 January 13, 2022     laravel     No comments   

Issue

I found the way to add an admin guard.

But there are no documentation to customize the following functionality:

Auth::guard('admin')->attempt()
Auth::guard('admin')->user()
Auth::guard('admin')->check()
middleware('auth:admin')

I need to check an additional field of admin table to check if the admin can be logged in.

In Auth::guard('admin')->attempt(), I want to use SQL like this:

Admin::where('login_id', $request->input('login_id'))
    ->where('password', md5($request->input('password')))
    ->where('additional_field', [additional condition]);
    

By Auth::guard('admin')->user(), I want to get the result of SQL like this:

Admin::where('id', Auth::guard('admin')->id())
    ->where('additional_field', [additional condition]);

And both Auth::guard('admin')->check() and middleware('auth:admin') also should consider the additional condition in the code above.

Is there a way to customize them?

And, are there any other functionalities of Laravel's auth which I have to customize to satisfy the requirement of the additional condition above?

I'm using Laravel 8.


Solution

IF your additional stuff are some input like login_id and password maybe this should work.

$cradentials= $request->only('email','password','additional stuff');
if( Auth::guard('admin')->attempt($cradentials) ){

       //stuff here
     }


Answered By - MUHAMMAD MESUM
  • Share This:  
  •  Facebook
  •  Twitter
  •  Stumble
  •  Digg
Newer Post Older Post Home

0 Comments:

Post a Comment

Note: Only a member of this blog may post a comment.

Total Pageviews

Featured Post

Why Learn PHP Programming

Why Learn PHP Programming A widely-used open source scripting language PHP is one of the most popular programming languages in the world. It...

Subscribe To

Posts
Atom
Posts
Comments
Atom
Comments

Copyright © PHPFixing