<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0"><channel><title><![CDATA[Laravel Multiple Authentication using guards, not working!]]></title><description><![CDATA[<p dir="auto">laravel framework එක හොඳට දන්න කෙනෙක් උදව් කරන්න. customers ලටයි Admin users ලටයි වෙන වෙනම guards දෙකක් හඳල තියෙන්නෙ. ඒත් attempt method එකෙන් හරියට login එක වෙලා redirect වෙන්නෙ නැ.</p>
<p dir="auto">මේ Logincontroller එක<br />
dd($status) එකෙනුත් false රිටන් වෙන්නෙ.</p>
<pre><code>&lt;?php

namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use Illuminate\Foundation\Auth\AuthenticatesUsers;
use Illuminate\Http\Request;
use Auth;

class LoginController extends Controller
{
    /*
    |--------------------------------------------------------------------------
    | Login Controller
    |--------------------------------------------------------------------------
    |
    | This controller handles authenticating users for the application and
    | redirecting them to your home screen. The controller uses a trait
    | to conveniently provide its functionality to your applications.
    |
    */

    use AuthenticatesUsers;

    /**
     * Where to redirect users after login.
     *
     * @var string
     */
    protected $redirectTo = '/home';

    /**
     * Create a new controller instance.
     *
     * @return void
     */
    public function __construct()
    {
        $this-&gt;middleware('guest')-&gt;except('logout');
        $this-&gt;middleware('guest:adminuser')-&gt;except('logout');
        $this-&gt;middleware('guest:customer')-&gt;except('logout');
    }
    
    /*public function showUserLoginForm() //show backend login form for admin users
    {
        return view('auth.login', ['url' =&gt; 'admin']); //edit this line to set path for adminLTE login form
    }*/

    public function adminLogin()
    {
        return view('admin.adminLogin');
    }

    public function adminHome()
    {
        return view('admin.home');
    }

    //login for the Admin user
    public function userLogin(Request $request)
    {
        $this-&gt;validate($request, [
            'username'   =&gt; 'required|min:3',
            'password' =&gt; 'required|min:6|max:6'
        ]);

        $status = Auth::guard('adminuser')-&gt;attempt(['email' =&gt; $request-&gt;username, 'password' =&gt; $request-&gt;password]);
        dd($status);
        if ($status == true) {
            return redirect()-&gt;intended('/adminhome');
            //$request-&gt;session()-&gt;flash('success', 'Login Successfully!');
           // return redirect('/adminhome'); // redirect to admin dashboard
        }
        else{
            $request-&gt;session()-&gt;flash('error', 'Sorry,Login Unuccessfull!');
            return redirect()-&gt;back();
        }
        //return back()-&gt;withInput($request-&gt;only('email', 'remember'));
    }


    //login for the customer
    public function customerLogin(Request $request)
    {
        $this-&gt;validate($request, [
            'username' =&gt; 'required|min:3',
            'password' =&gt; 'required|min:6|max:6'
        ]);
        
        $status = Auth::guard('customer')-&gt;attempt(['email' =&gt; $request-&gt;username, 'password' =&gt; $request-&gt;password], $request-&gt;get('remember'));
        if ($status == true) {
            $request-&gt;session()-&gt;flash('success', 'Login Successfully!');
            return redirect('/index');
        }
        else{
            $request-&gt;session()-&gt;flash('error', 'Sorry,Login Unuccessfull!');
            return redirect()-&gt;back();
        }
        //return back()-&gt;withInput($request-&gt;only('email', 'remember'));
    }
}

</code></pre>
<p dir="auto">AdminUser.php Model එක</p>
<pre><code>&lt;?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;

class AdminUser extends Authenticatable
{
    protected $table = 'adminusers';

    use Notifiable;

    protected $guard = 'adminuser';

    protected $fillable = [
        'username', 'password',
    ];

    protected $hidden = [
        'password', 'remember_token',
    ];
}

</code></pre>
<p dir="auto">auth.php මේකෙ තමා customer , adminuser කියන guards දෙක හදල තියෙන්නෙ</p>
<pre><code>&lt;?php

return [

    /*
    |--------------------------------------------------------------------------
    | Authentication Defaults
    |--------------------------------------------------------------------------
    |
    | This option controls the default authentication "guard" and password
    | reset options for your application. You may change these defaults
    | as required, but they're a perfect start for most applications.
    |
    */

    'defaults' =&gt; [
        'guard' =&gt; 'web',
        'passwords' =&gt; 'users',
    ],

    /*
    |--------------------------------------------------------------------------
    | Authentication Guards
    |--------------------------------------------------------------------------
    |
    | Next, you may define every authentication guard for your application.
    | Of course, a great default configuration has been defined for you
    | here which uses session storage and the Eloquent user provider.
    |
    | All authentication drivers have a user provider. This defines how the
    | users are actually retrieved out of your database or other storage
    | mechanisms used by this application to persist your user's data.
    |
    | Supported: "session", "token"
    |
    */

    'guards' =&gt; [
        'web' =&gt; [
            'driver' =&gt; 'session',
            'provider' =&gt; 'users',
        ],

        'api' =&gt; [
            'driver' =&gt; 'token',
            'provider' =&gt; 'users',
            'hash' =&gt; false,
        ],
        'customer' =&gt; [
            'driver' =&gt; 'session',
            'provider' =&gt; 'customers',
        ],
        'adminuser' =&gt; [
            'driver' =&gt; 'session',
            'provider' =&gt; 'adminusers',
        ],
    ],

    /*
    |--------------------------------------------------------------------------
    | User Providers
    |--------------------------------------------------------------------------
    |
    | All authentication drivers have a user provider. This defines how the
    | users are actually retrieved out of your database or other storage
    | mechanisms used by this application to persist your user's data.
    |
    | If you have multiple user tables or models you may configure multiple
    | sources which represent each model / table. These sources may then
    | be assigned to any extra authentication guards you have defined.
    |
    | Supported: "database", "eloquent"
    |
    */

    'providers' =&gt; [
        'users' =&gt; [
            'driver' =&gt; 'eloquent',
            'model' =&gt; App\Models\User::class,
        ],
        'customers' =&gt; [
            'driver' =&gt; 'eloquent',
            'model' =&gt; App\Models\Customer::class,
        ],
        'adminusers' =&gt; [
            'driver' =&gt; 'eloquent',
            'model' =&gt; App\Models\AdminUser::class, 
        ],

        // 'users' =&gt; [
        //     'driver' =&gt; 'database',
        //     'table' =&gt; 'users',
        // ],
    ],

    /*
    |--------------------------------------------------------------------------
    | Resetting Passwords
    |--------------------------------------------------------------------------
    |
    | You may specify multiple password reset configurations if you have more
    | than one user table or model in the application and you want to have
    | separate password reset settings based on the specific user types.
    |
    | The expire time is the number of minutes that the reset token should be
    | considered valid. This security feature keeps tokens short-lived so
    | they have less time to be guessed. You may change this as needed.
    |
    */

    'passwords' =&gt; [
        'users' =&gt; [
            'provider' =&gt; 'users',
            'table' =&gt; 'password_resets',
            'expire' =&gt; 60,
        ],
    ],

];

</code></pre>
<p dir="auto">Adminuser login form එක</p>
<pre><code> &lt;form action="/adminUserLogin" method="POST"&gt;
        @csrf
        &lt;div class="input-group mb-3"&gt;
          &lt;input type="text" class="form-control" placeholder="Username" name="username" id="username"&gt;
          &lt;div class="input-group-append"&gt;
              &lt;span class="fa fa-user input-group-text"&gt;&lt;/span&gt;
          &lt;/div&gt;
        &lt;/div&gt;
        &lt;div class="input-group mb-3"&gt;
          &lt;input type="password" class="form-control" placeholder="Password" name="password" id="password"&gt;
          &lt;div class="input-group-append"&gt;
              &lt;span class="fa fa-lock input-group-text"&gt;&lt;/span&gt;
          &lt;/div&gt;
        &lt;/div&gt;
        &lt;div class="row"&gt;
          &lt;div class="col-8"&gt;
            &lt;div class="checkbox icheck"&gt;
              &lt;label&gt;
                &lt;input type="checkbox"&gt; Remember Me
              &lt;/label&gt;
            &lt;/div&gt;
          &lt;/div&gt;
          &lt;!-- /.col --&gt;
          &lt;div class="col-4"&gt;
            &lt;button type="submit" class="btn btn-primary btn-block"&gt;Sign In&lt;/button&gt;
          &lt;/div&gt;
          &lt;!-- /.col --&gt;
        &lt;/div&gt;
      &lt;/form&gt;
</code></pre>
<p dir="auto">කොහොමද මේක හදාගන්නෙ. plz help!</p>
]]></description><link>https://lankadevelopers.lk/topic/353/laravel-multiple-authentication-using-guards-not-working</link><generator>RSS for Node</generator><lastBuildDate>Wed, 22 Jul 2026 20:44:57 GMT</lastBuildDate><atom:link href="https://lankadevelopers.lk/topic/353.rss" rel="self" type="application/rss+xml"/><pubDate>Tue, 27 Aug 2019 12:59:19 GMT</pubDate><ttl>60</ttl><item><title><![CDATA[Reply to Laravel Multiple Authentication using guards, not working! on Mon, 16 Sep 2019 05:15:16 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://lankadevelopers.lk/uid/125">@Anjana_Gihan</a> thanks bro i did not use laravel gurd</p>
]]></description><link>https://lankadevelopers.lk/post/2190</link><guid isPermaLink="true">https://lankadevelopers.lk/post/2190</guid><dc:creator><![CDATA[Nubelle]]></dc:creator><pubDate>Mon, 16 Sep 2019 05:15:16 GMT</pubDate></item><item><title><![CDATA[Reply to Laravel Multiple Authentication using guards, not working! on Sun, 15 Sep 2019 12:21:54 GMT]]></title><description><![CDATA[<p dir="auto">For your reference @cody</p>
]]></description><link>https://lankadevelopers.lk/post/2189</link><guid isPermaLink="true">https://lankadevelopers.lk/post/2189</guid><dc:creator><![CDATA[Anjana_Gihan]]></dc:creator><pubDate>Sun, 15 Sep 2019 12:21:54 GMT</pubDate></item><item><title><![CDATA[Reply to Laravel Multiple Authentication using guards, not working! on Fri, 06 Sep 2019 16:42:44 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://lankadevelopers.lk/uid/297">@hashan</a></p>
<p dir="auto"><a href="https://codeburst.io/learn-how-to-redirect-authenticated-users-to-corresponding-path-in-laravel-dd613e2f9e3" target="_blank" rel="noopener noreferrer nofollow ugc">https://codeburst.io/learn-how-to-redirect-authenticated-users-to-corresponding-path-in-laravel-dd613e2f9e3</a></p>
]]></description><link>https://lankadevelopers.lk/post/2152</link><guid isPermaLink="true">https://lankadevelopers.lk/post/2152</guid><dc:creator><![CDATA[root]]></dc:creator><pubDate>Fri, 06 Sep 2019 16:42:44 GMT</pubDate></item><item><title><![CDATA[Reply to Laravel Multiple Authentication using guards, not working! on Thu, 05 Sep 2019 13:49:23 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://lankadevelopers.lk/uid/27">@root</a>  <a class="plugin-mentions-user plugin-mentions-a" href="https://lankadevelopers.lk/uid/2">@dev_lak</a>  ara laravel experts</p>
]]></description><link>https://lankadevelopers.lk/post/2150</link><guid isPermaLink="true">https://lankadevelopers.lk/post/2150</guid><dc:creator><![CDATA[Nubelle]]></dc:creator><pubDate>Thu, 05 Sep 2019 13:49:23 GMT</pubDate></item><item><title><![CDATA[Reply to Laravel Multiple Authentication using guards, not working! on Wed, 04 Sep 2019 12:28:50 GMT]]></title><description><![CDATA[<p dir="auto"><a class="plugin-mentions-user plugin-mentions-a" href="https://lankadevelopers.lk/uid/27">@root</a> any answer?</p>
]]></description><link>https://lankadevelopers.lk/post/2149</link><guid isPermaLink="true">https://lankadevelopers.lk/post/2149</guid><dc:creator><![CDATA[hashan]]></dc:creator><pubDate>Wed, 04 Sep 2019 12:28:50 GMT</pubDate></item><item><title><![CDATA[Reply to Laravel Multiple Authentication using guards, not working! on Wed, 28 Aug 2019 21:36:34 GMT]]></title><description><![CDATA[<p dir="auto">Ok. balamu</p>
]]></description><link>https://lankadevelopers.lk/post/2119</link><guid isPermaLink="true">https://lankadevelopers.lk/post/2119</guid><dc:creator><![CDATA[root]]></dc:creator><pubDate>Wed, 28 Aug 2019 21:36:34 GMT</pubDate></item></channel></rss>