我想知道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()会出错吗?或者,我只是在思考它?