findorFail method in Laravel

2024-04-18 20:28:01 Sunil Laravel

How to use findOrFail() method?

Sometimes you may wish to throw an exception if a specific record is not found. To do this, you may use the findOrFail method in Laravel findOrFail method and generates and exception if specific record is not found.

$model = User::findOrFail(1);

This post is submitted by one of our members. You may submit a new post here.

Related Tricks