最重要的是,搜索从一个城市到另一个城市的门票,还会获取有关公交车品牌的信息。
在我的控制器中,我正在执行以下操作:
public function search() {
// Sets the parameters from the get request to the variables.
$from_city = Request::get('from');
$to_city = Request::get('to');
//Finds the city ID
$from_id = DB::table('city')->where('name', $from_city)->pluck('id');
$to_id = DB::table('city')->where('name', $to_city)->pluck('id');
$date = Request::get('date');
//Find a tickets using Query Builder
$result = DB::table('tickets')
->select(DB::raw("*"))
->where('from_city_id', '=', $from_id)
->where('to_city_id', '=', $to_id)
->where('date', '=', $date)
->get();
return view('index.search', ['tickets' => $result]);
}
另外,我的观点如下:
@foreach ($tickets as $ticket)
From city id: {{ $ticket->from_city_id }}
To city id: {{ $ticket->to_city_id }}
Date: {{ $ticket->date }}
Bus number:
From city name
To city name:
@endforeach
我需要显示来自标识符的city_name,bus_number数据,它们是在一个单独的数据库表中,我该怎么做才能在视图中显示?
总线表
城市表
门票表