본문 바로가기

개발/Laravel

Laravel 6 Auth Login

기존 DB Table 을 활용하여 로그인 기능 구현

 

1. login 오버라이드

public function login(Request $request) 
    {
        $id = $request->id;
        $pwd = md5($request->pwd); // 기존 데이터 md5

		// Laravel Auth attempt 
        if(Auth::attempt(['id' => $id, 'pwd' => $pwd])) {
            // add login passed process
            return "로그인 성공";
        } else {
            // add login failed process
            return "로그인 실패";
        }

    }

2. Eloquent Model 구현

<?php

namespace App\Models;
use Illuminate\Database\Eloquent\Model;

class Member extends Model {
	// 테이블 명 지정
	protected $table = 'Member';
    // 기본키 지정
  	protected $primaryKey = 'Seqno';
    // 기본키가 auto increment 가 아닐 경우 false 
  	public $incrementing = false;
    // 기본키가 정수가 아닐 경우 false
    protected $keyType = 'string';
  	// created_at 컬럼 설정
  	const CREATED_AT = 'creation_date';
  	// updated_at 컬럼 설정
  	const UPDATED_AT = 'last_update';
  	// create_at, updated_at 을 사용하지 않을 경우 false
  	public $timestamps = false;
    // 타임 스탬프 포맷 변경
    protected $dateFormat = 'U';
    // 커넥션 변경
    protected $connection = 'connection-name';
    // 기본값 정의
    protected $attributes = [
    	'delayed' => false,
    ]

    // The attributes that aren't mass assignable.
    protected $guarded = [
      'idx'
    ];

    // The attributes that are mass assignable.
    //protected $fillable = [
    //  'title', 'content'
    //];

    // The attributes that should be hidden for arrays.
    protected $hidden = [
      'password'
    ];
}
반응형

'개발 > Laravel' 카테고리의 다른 글

Laravel Singleton 구현  (0) 2020.06.24
Laravel Dependency Injection Container - 1  (0) 2020.06.23
Laravel 6 Custom Exception  (0) 2020.06.10
Laravel 6 Gmail 연결 및 메일 전송 설정  (2) 2020.06.09
서비스 컨테이너  (0) 2020.06.08