【发布时间】:2019-02-27 12:43:24
【问题描述】:
当我按数据库表中可用的城市名称搜索时,它会显示结果,但是当我按数据库表中不可用的未知城市搜索时,它会显示 -没有模型 [App\ 的查询结果城市]。我将代码和截图分享给你see error screenshot 实际上,如果在我的数据库表中找不到该城市,我想重定向到 401 页面
这是我的路线
Route::get('teacher-jobs-by-city/{city}','TeacherJobsController@by_location');
这是我的功能
公共函数 by_location($location_id='') {
$data= array();
$location = City::where('slug',$location_id)->where('status','1')->firstOrFail();
$items= Subject::orderBy('id','asc')->get();
$data['location']=$location;
//$subjects = [''=>'Select Subject'] + Subject::lists('subject_title','id')->toArray();
//$city = [''=>'Select City'] + City::lists('name','id')->toArray();
$active_class ='Select Subject to see job Openings';
return view('frontend.teacherjobs.by_location',compact('active_class','data','items'));
}
【问题讨论】:
标签: laravel laravel-5 laravel-5.2 laravel-5.1