findOrFail laravel

Posted by pavan - 1 year ago

Example findOrFail Method

If you will use findOrFail() then you don't require to check object null or not like find() method. it will automatic check and then run following thesource code:

/**
 * Show the application dashboard.
 *
 * @return \Illuminate\Contracts\Support\Renderable
 */
public function index(){

  $productId = 9898;

  $product  = Product::findOrFail($productId);

  dd($product);
}

Also You can More Full Example