正常情况下用findOrFail,如果主键不存在会出现404页面。

Add this to your uses in your controller

use Illuminate\Database\Eloquent\ModelNotFoundException;//find or fail error exception class.

and modify you current code to 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 it will skip return view('profil..
        //and excute whatever in this section
    }
}