  | 
              
	              
	                
  
    
	 
        Laravel 5.5 ต้องการปรับแต่งระบบ Auth ที่มีมาให้ใช้กับตารางผู้ใช้งานที่มีอยู่ครับ     | 
   
  
    |   | 
   
 
 
 
              
  
          
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 แก้ไขในนี้ดูครับ 
app/config/auth.php                        
               
               | 
             
            
              
			                              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2018-04-17 08:56:20 | 
                        By :
                            mongkon.k | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                   ตอบความคิดเห็นที่ : 1 เขียนโดย : mongkon.k เมื่อวันที่ 2018-04-17 08:56:20 
รายละเอียดของการตอบ ::
  ส่วนนี้ผมแก้ไขแล้วครับ จะให้ดูตามด้านล่างนะครับ
  
 
เพ่ิม Model  Student.php 
Code (PHP) 
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Foundation\Auth\User as Authenticatable;
class Student extends Authenticatable
{   
    protected $table = 'Student';
    //protected $primaryKey = 'ID';
    //protected $fillable = ['ID', 'ID_No'];
    public function getAuthPassword()
    {
        return $this->ID_No;
    }
}
 
 
แก้ไขไฟล์ auth.php 
Code (PHP) 
<?php
return [
    /*
    |--------------------------------------------------------------------------
    | Authentication Defaults
    |--------------------------------------------------------------------------
    */
    'defaults' => [
        'guard' => 'web',
        'passwords' => 'users',
    ],
    /*
    |--------------------------------------------------------------------------
    | Authentication Guards
    |--------------------------------------------------------------------------
    */
    'guards' => [
        'Student' => [
            'driver' => 'session',
            'provider' => 'Student',
        ],
        'web' => [
            'driver' => 'session',
            'provider' => 'users',
        ],
        'api' => [
            'driver' => 'token',
            'provider' => 'users',
        ],
    ],
    /*
    |--------------------------------------------------------------------------
    | User Providers
    |--------------------------------------------------------------------------
    */
    'providers' => [
        'Student' => [
            'driver' => 'eloquent',
            'model' => App\Student::class,
            'table' => 'Student',
        ],
        'users' => [
            'driver' => 'eloquent',
            'model' => App\User::class,
        ],
        // 'users' => [
        //     'driver' => 'database',
        //     'table' => 'users',
        // ],
    ],
    /*
    |--------------------------------------------------------------------------
    | Resetting Passwords
    |--------------------------------------------------------------------------
    */
    'passwords' => [
        'users' => [
            'provider' => 'users',
            'table' => 'password_resets',
            'expire' => 60,
        ],
    ],
];
 
 
เพิ่มในส่วนของ StudentLoginController 
Code (PHP) 
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use App\Student;
class StudentLoginController extends Controller
{
    public function index()
    {
        return view('student.login');
    }
    public function authentication(Request $request)
    {
        /* ผมคิดว่าต้องการใช้ login วิธีนี้  เพราะก่อนจะได้วิธีนี้จะใช้ login ผ่าน ldap เอาครับ แต่ไม่ได้ครับ */
        $student = Student::find($request->studentId);
        if(Auth::guard('Student')->login($student)){
            return redirect()->intended('home');
        }else{
            return 'log in failed!';
        }
        /*$credentials = [
            'ID' => $request->studentId, 
            'password' => $request->citizenId,
        ];*/
        /* ตรงนี้ลองแล้วไม่ได้ครับ มันไม่ยอมเอา password ไปคิวรี่ด้วยเลยไม่ผ่าน */
        /*if(Auth::guard('Student')->attempt($credentials))
        {
            //dd($request);
            //return redirect()->intended('home');
            return 'logged in successfully.';
        }else{
            //dd($request);
            return 'log in failed!';
        }*/
    }
    public function logout(){
        Auth::guard('Student')->logout();
        return back();
    }
}
 
 
หลักๆ ก็มี 3 ไฟล์นี้ครับ ที่แก้ ไม่รู้ว่าต้องแก้อะไรอีกหรือเปล่าครับ                        
               
               | 
             
            
              
			                              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2018-04-17 09:43:22 | 
                        By :
                            angelkiller9 | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 เท่าที่ดูน่าจะใช้ได้แล้วน่ะ เปลี่ยน auth จาก table users ไปใช้ student                        
               
               | 
             
            
              
			                              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2018-04-17 10:15:25 | 
                        By :
                            mongkon.k | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	     
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 แสดงว่า format ของ user profile session น่าจะยังไม่ตรงกับของ laravel                        
               
               | 
             
            
              
			                
  ประวัติการแก้ไข 2018-04-17 10:36:09              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2018-04-17 10:35:36 | 
                        By :
                            mongkon.k | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
               
		
     
		
	     
	    
     
               
		
     
		
	  
        
             | 
            | 
            | 
             | 
         
        
             | 
                       | 
          
            
               
                 Code (PHP) 
    'guards' => [
        'students' => [ // object แนะนำตัวแรกให้เป็นตัวเล็ก เติม s ด้วยกับเพราะ rows มากกว่า 1
            'driver' => 'session',
            'provider' => 'Student',
        ],
        'web' => [
            'driver' => 'session',
            'provider' => 'students', // อ้างอิงจาก object guards ให้ทำการเพิ่ม session
        ],
 
จริงๆแล้ว คุณสามารถเช็คค่าโดยการ return จาก model มาแสดงก่อนได้เพื่อ return ค่าปัจจุบันมาทำการตรวจสอบก่อนได้                        
               
               | 
             
            
              
			                
  ประวัติการแก้ไข 2018-04-17 16:54:38              
                              
              
                
                     | 
                     | 
                     | 
                 
                
                     | 
                  
                      
                        | Date :
                            2018-04-17 16:45:17 | 
                        By :
                            dudesaranyu | 
                         
                    | 
                     | 
                 
                
                     | 
                     | 
                     | 
                 
                | 
             
           
			         | 
             | 
         
        
             | 
            | 
             | 
             | 
         
          
	    
     
      		  
	
     | 
   
 
                 |