laravel - Exception if object doesn't exists -


in application id route/url. should in controller if there no object id?

my favorite solution throw 404. idea? there helpers common problem?

// url /groups/1  public function group($group_id) {     if (! group::find($group_id)) {         app::abort(404);     }  } 

in django there short cut function problem. https://docs.djangoproject.com/en/1.6/topics/http/shortcuts/#get-object-or-404

eloquent::findorfail($pk) looking for. throw modelnotfoundexception. here's how set up:

controller

public function group($group_id) {     // throw app::error() when $group_id doesn't exist     $group = group::findorfail($group_id); } 

routes (or similar)

app::error(function(illuminate\database\eloquent\modelnotfoundexception $e) {     // ran when ::findorfail() doesn't find object     app::abort(404); }); 

Comments

Popular posts from this blog

c++ - OpenCV Error: Assertion failed <scn == 3 ::scn == 4> in unknown function, -

php - render data via PDO::FETCH_FUNC vs loop -

The canvas has been tainted by cross-origin data in chrome only -