BackEND/Laravel

로그인 구현

smartlittlepuppy 2020. 11. 22. 21:39
반응형

1. php artisan make:auth 명령어를 실행한다.

2. views>auth, layouts>app.blade.php, web.php안에 Auth::routes() 자동으로 생성된다. 

3. http://127.0.0.1:8000/login 페이지가 자동으로 생성되어있다.

4. http://127.0.0.1:8000/register 페이지가 자동으로 생성되어있다. 

5. 로그인이 필요한 페이지에 로그인구현 기능 넣기.

Middleware groups may be assigned to routes and controller actions using the same syntax as individual middleware. Again, middleware groups make it more convenient to assign many middleware to a route at once.laravel.com/docs/5.8/middleware#middleware-groups

Route::get('/', function () {
    //
})->middleware('web');

Route::group(['middleware' => ['web']], function () {
    //
});
//폼을 불러온다. 
Route::get('/create', 'WeavingController@create')->middleware('auth');

6. 5번 보다 더 편리하게 하기위해서,

web.php에서 그룹화, 특정페이지는 로그인한 사용자만 허용, prefix를 이용해서 구현

The prefix method may be used to prefix each route in the group with a given URI. For example, you may want to prefix all route URIs within the group with admin:

Route::prefix('/')->middleware('auth')->group(function(){

    //전체리스트 불러오기
    Route::get('index', 'WeavingController@index');

    //폼을 불러온다. 
    Route::get('create', 'WeavingController@create');

    //폼에서 넘어온값을 받아서 테이블에 넣는다. 
    Route::post('store', 'WeavingController@store');

    //글 보기. 테이블에 저장된 하나의 레코를 불러온다. weavingID를 show함수에. 
    Route::get('view/{weavingID}', 'WeavingController@show');

    //글 수정폼 받아서 테이블에 넣는다. 
    Route::get('{weavingID}/edit', 'WeavingController@edit');

    //글 수정폼 받아서 테이블에 넣는다. 
    Route::put('{weavingID}', 'WeavingController@update');
    Route::get('/home', 'HomeController@index')->name('home');

});

Auth::routes();

 

반응형

'BackEND > Laravel' 카테고리의 다른 글

CRUD 라라벨에서 글수정1  (0) 2020.11.03
CRUD 라라벨에서 글보기  (0) 2020.11.03
CRUD 라라벨에서 글 저장하기 2  (0) 2020.11.02
CRUD 라라벨에서 글 저장하기 1  (0) 2020.11.02
CRUD 라라벨에서 글 읽어오기.  (0) 2020.11.01