반응형
Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | 2 | 3 | 4 | 5 | 6 | 7 |
8 | 9 | 10 | 11 | 12 | 13 | 14 |
15 | 16 | 17 | 18 | 19 | 20 | 21 |
22 | 23 | 24 | 25 | 26 | 27 | 28 |
29 | 30 | 31 |
Tags
- blockchain
- Laravel
- win32
- elasticSearch
- Python
- javascript
- 이더리움
- php
- 인민공원
- 당사자표시정정신청서
- vue
- as후기
- Sentinel
- 전자소송
- Blade
- auth
- 체당금
- cartalyst
- 홈택스
- 코로나
- 보정명령
- Eclipse
- Bootstrap
- 코로나19
- Tutorial
- 소액임금체불
- reactnative
- 개인사업자
- 사업자계좌
- Java
Archives
- Today
- Total
그냥 사는 이야기
Laravel 5.3 Sentinel - Visitors & Manager 본문
반응형
Visitor 권한
우선 VisitorMiddleware를 만든다.
php artisan make:middleware VisitorsMiddleware
routes/web.php
Route::group(['middleware' => 'visitors'], function() {
Route::get('/register', 'RegistrationController@register');
Route::post('/register', 'RegistrationController@postRegister');
Route::get('/login', 'LoginController@login');
Route::post('/login', 'LoginController@postLogin');
});
visitor가 접근 할 수 있는 register, login 경로는 visitor middleware group로 묶는다.
App/Http/Kernel.php
...
'visitors' => \App\Http\Middleware\VisitorsMiddleware::class,
App/Http/Middleware/VisitorsMiddleware
use Sentinel;
...
public function handle($request, Closure $next)
{
if(!Sentinel::check())
return $next($request);
return redirect('/');
}
earnings view
resources/views/admins/earnings.blade.php
Total earnings 9999
<form action="/logout" method="POST" id="logout-form">
{{ csrf_field() }}
<a href="#" onclick="document.getElementById('logout-form').submit()">Logout</a>
</form>
App/Http/Controllers/AdminController
public function earnings()
{
return view('admins.earnings');
}
Manager 권한
php artisan make:middleware ManagerMiddleware
App/Http/Kernel.php
...
'manager' => \App\Http\Middleware\ManagerMiddleware::class,
App/Http/Middleware/ManagerMiddleware
use Sentinel;
...
public function handle($request, Closure $next)
{
if (Sentinel::check() && Sentinel::getUser()->roles()->first()->slug == 'manager') {
// \Log::info('role', ['role' => Sentinel::getUser()->roles()->first()]);
return $next($request);
}
else
return redirect('/');
}
routes/web.php
...
Route::get('tasks', 'ManagerController@tasks')->middleware('manager');
App/Http/Controllers/ManagerController
public function earnings()
{
return view('managers.tasks');
}
로그인 시 권한에 맞는 페이지 redirect
LoginController
public function postLogin(Request $request)
{
Sentinel::authenticate($request->all());
$slug = Sentinel::getUser()->roles()->first()->slug;
if ($slug =='admin')
return redirect('/earnings');
elseif ($slug =='manager')
return redirect('/tasks');
return Sentinel::check();
}
'Development > Web' 카테고리의 다른 글
Laravel 5.3 Blog System - Post And Comments (2) | 2020.01.22 |
---|---|
Laravel 5.3 Blog System - Setup Database (0) | 2020.01.22 |
Laravel 5.3 Sentinel - Restricting Access According to Roles (0) | 2020.01.21 |
Laravel 5.3 Sentinel - Roles (0) | 2020.01.21 |
Laravel 5.3 Sentinel - Logout & show content to logged users only (0) | 2020.01.21 |
Comments