라라벨 컨트롤러 404 페이지 출력

1 개요[ | ]

라라벨 컨트롤러 404 페이지 출력
  • fruit값이 'Apple' 또는 'Banana'가 아니면 404 페이지를 출력함
  • 여기서는 간단히 404 페이지를 띄우는 방법을 설명한다.
( 유효성 검증에는 Validator를 이용하는 것이 좋다. )
( 필요에 따라 미들웨어로 작성하는 방법도 생각해보자. )
namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
class FooController extends Controller
{
	public function index() {
		$fruit = request('fruit');
		if( !in_array($fruit, ['Apple','Banana']) ) {
			abort(404);
			return;
		}
		return "Hello, $fruit!";
	}
}

2 같이 보기[ | ]

3 참고[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}