Laravel Classroom image

CiliSp
 
To post your Question Join Classroom
 
Lesson Topics's No:-  First|1 | 2 | 3 | 4 | 5|
Lessons:-Authentication

14.5 Customisation
I know what you’re thinking. What if I don’t want to use Eloquent or Fluent, this seems very
limited!
Please, this is Laravel. You should have learned this by now! Laravel allows you to create
custom classes known as ‘Auth Drivers’ so that you can modify parameters or hook into
any authentication system you like. Simply create a new class. I like to put mine in
application/libraries so that they are auto-loaded for me!
1 <?php
2
3 // application/libraries/myauth.php
4 class Myauth extends Laravel\Auth\Drivers\Driver {
5
6 public function attempt($arguments = array())
7 {
8
9 }
10
11 public function retrieve($id)
12 {
13
14 }
15
16 }Your authentication driver must extend Laravel\Auth\Drivers\Driver and contain the two
methods listed above. The first method accepts the array of username and password and is
used to authenticate using your own method. On a successful authentication you should make
a call to the login() method of the parent to inform Laravel that the authentication worked, for
example..
1 <?php
2
3 public function attempt($arguments = array())
4 {
5 $username = $arguments['username'];
6 $password = $arguments['password'];
7
8 $result = my_login_method($username, $password);
9
10 if($result)
11 {
12 return $this->login($result->id, array_get($arguments, 'remember'));
13 }
14
15 return false;
16 }
The login method accepts an identifier (that can be used later to retrieve the user) and the value
of the ‘remember’ key from our arguments array. On authentication failure the method should
always return false.
The retrieve() method is handed the identifier that you previously passed to the login()
method, you can use this to return an object that represents the current user. For example..
1 <?php
2
3 public function retrieve($id)
4 {
5 return get_my_user_object($id);
6 }
Great! Now we have a working authentication driver. Before we can use it we will need to
register it with the Auth class. Add the following code to your application/start.php.
1 <?php
2
3 Auth::extend('myauth', function() {
4 return new Myauth();
5 });Pass an identifier for your authentication driver as the first parameter to Auth::extend(), the
second parameter is a Closure that is used to return a new instance of the class.
All that is left to do is update your application/config/auth.php file to point to this new
authentication driver..
1 <?php
2
3 'driver' => 'myauth',
and now enjoy using your authentication system in the usual way!

 

 

 

 
 
 

CiliSp

Skills    Laravel

Qualifications :-
Location :-,,,
Description:-
Explore
 

  Students (0)