阅读(2062) (7)

Laravel 8 throw_unless() {#collection-method}

2021-07-05 10:24:22 更新

在给定的布尔表达式结果为 false 时,throw_unless 函数抛出给定的异常:

throw_unless(Auth::user()->isAdmin(), AuthorizationException::class);

throw_unless(
    Auth::user()->isAdmin(),
    AuthorizationException::class,
    'You are not allowed to access this page'
);