The throw_unless function throws the given exception if a given boolean expression evaluates to false:
<?php throw_unless(Auth::user()->isAdmin(), AuthorizationException::class);

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

        $component = '\Illuminate\Console\View\Components\\'.ucfirst($method);



        throw_unless(class_exists($component), new InvalidArgumentException(sprintf(

            'Console component [%s] not found.', $method

        )));



        return with(new $component($this->output))->render(...$parameters);

    }
<?php     {

        $this->expectException(LogicException::class);



        throw_unless(false, new LogicException);

    }



    public function testThrowUnlessDefaultException()
<?php     {

        $this->expectException(RuntimeException::class);



        throw_unless(false);

    }



    public function testThrowUnlessExceptionWithMessage()
<?php         $this->expectException(RuntimeException::class);

        $this->expectExceptionMessage('test');



        throw_unless(false, 'test');

    }



    public function testThrowUnlessExceptionAsStringWithMessage()
<?php         $this->expectException(LogicException::class);

        $this->expectExceptionMessage('test');



        throw_unless(false, LogicException::class, 'test');

    }



    public function testThrowReturnIfNotThrown()
<?php     public function testThrowReturnIfNotThrown()

    {

        $this->assertSame('foo', throw_unless('foo', new RuntimeException));

    }



    public function testThrowWithString()