小编use*_*288的帖子

在什么情况下,laravel的雄辩集合save()会出错?

我想知道elqouent save()可能抛出的错误或异常.在laravel中,我在保存或更新模型时一直这样做.

    // create or update some data

    if($model->save()){
        // continue
        return true;
    }

    throw new Exception('Model could not be saved');
Run Code Online (Sandbox Code Playgroud)

我不喜欢save()if语句来检查是否保存了模型.如果它抛出一个异常然后,我很想把它包装成try..catch块,就像,

    try{    
        // create or update some data
        $model->save()
        // continue
        return true;
    catch(SomeException $e){
        throw new Exception('Model could not be saved');
    }
Run Code Online (Sandbox Code Playgroud)

那么,laravel的雄辩收藏save()会出错吗?或者,我只是在思考它?

php laravel

6
推荐指数
1
解决办法
3477
查看次数

标签 统计

laravel ×1

php ×1