php - Laravel findorfail() redirect -


i have following code :

    public function showtestprofile($id){         $auth = auth::user();         $tests = app\test::findorfail($id);         return view('profile',compact('auth','tests','members'));     } 

if have id in db table come findorfail(),

but if add not existing id url :

http://newpro.dev/user-profile/24645645456

then no query found larvel page comes up.

how can redirect route if have no id.

add uses in controller

use illuminate\database\eloquent\modelnotfoundexception;//find or fail error exception class. 

and modify current code this

 public function showtestprofile($id){     try{         $auth = auth::user();         $tests = app\test::findorfail($id);         return view('profile',compact('auth','tests','members'));     }     catch(modelnotfoundexception $err){         //if id doesnt exist skip return view('profil..         //and excute whatever in section     } } 

Comments

  1. @admin

    Our doctors or dentists are to facilitate their advance techniques and educational experience, which provide patients with the best alternatives for oral health. Our team and dentists maintain to prepare themselves to provide maximum satisfaction for patients.
    Regards,
    Dentist In New Britain, CT

    ReplyDelete
  2. @admin

    We provide all the requirements around the patients to give friendly involvement with divine and relaxed circumstances. Book an appointment and visit our clinic for our effective doctor’s experiences

    Regards,
    Dentist In Dracut, MA

    ReplyDelete
  3. @admin

    Our team takes care about dental care with excellent equipment and material in your comfortable atmosphere. Your comfort is our priority, which suits your smile as per your requirement.

    Regards,
    Dentist In Lynn MA

    ReplyDelete
  4. @admin

    Our team takes care about dental care with excellent equipment and material in your comfortable atmosphere. Your comfort is our priority, which suits your smile as per your requirement.

    Regards,
    Dentist In Lynn MA

    ReplyDelete

Post a Comment

Popular posts from this blog

java - Suppress Jboss version details from HTTP error response -

gridview - Yii2 DataPorivider $totalSum for a column -

Sass watch command compiles .scss files before full sftp upload -