Abort if condition failed

abort_if() can be used as shorter way to check condition and throw an error page.

1$product = Product::findOrFail($id);
2if($product->user_id != auth()->user()->id){
3 abort(403);
4}

Shorter way

1/* abort_if(CONDITION, ERROR_CODE) */
2$product = Product::findOrFail($id);
3abort_if ($product->user_id != auth()->user()->id, 403)

Like our articles?

Become a Premium Member for $129/year or $29/month
What else you will get:
  • 22 courses (477 lessons, total 38 h 20 min)
  • 2 long-form tutorials (one new every week)
  • access to project repositories
  • access to private Discord