LoginSignup
21
15

More than 5 years have passed since last update.

Laravelでエラーを返す簡単な方法3つ

Posted at

方法1 abort()

*.php
Route::post('/task', function(Request $request) {
    if (!$request->user->is_admin) {
        abort(403, '権限がありません');
    }
}

方法2 abort_if()

*.php
Route::post('/task', function(Request $request) {
    abort_if(!$request->user->is_admin, 403);
}

方法3 abort_unless()

*.php
Route::post('/task', function(Request $request) {
    abort_unless($request->user->is_admin, 403);
}

Laravel のヘルパーは便利なものが多いので、開発する前に一通り読んでおいたほうがいいですよ。

(英語)
https://laravel.com/docs/5.3/helpers
(日本語)
https://readouble.com/laravel/5.3/ja/helpers.html

21
15
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
21
15