| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253 |
- <?php
- namespace App\Http\Middleware\Board;
- use Closure;
- use Illuminate\Http\Request;
- use Illuminate\Support\Facades\Gate;
- use App\Services\BoardService;
- use Exception;
- class PostUploader
- {
- public function handle(Request $request, Closure $next)
- {
- try{
- $code = $request->route('code');
- // 게시판 코드 확인
- if (!$code) {
- throw new Exception('잘못된 접근입니다.', 404);
- }
- $boardService = new BoardService();
- // 게시판 정보 조회
- $board = $boardService->find($code);
- // 게시판 존재 유무
- if (!$board->exists) {
- throw new Exception('존재하지 않는 게시판입니다.');
- }
- // 게시판 사용 여부
- if ($board->is_display == 0) {
- throw new Exception('더 이상 사용하지 않는 게시판입니다.');
- }
- $boardMeta = $boardService->meta($board->id);
- // 이미지 첨부 권한 확인
- $response = Gate::inspect('uploader', ['App\Model\Post', $boardMeta]);
- if($response->denied()) {
- throw new Exception($response->message());
- }
- }catch(Exception $e) {
- return alert($e->getMessage(), null, false);
- }
- return $next($request);
- }
- }
|