如何在控制器中使用count()?
如何在这里获得行数?当我使用$ count = $ frignts-> count();
我获得此错误计数数组中的所有元素或对象中的所有内容
public function index(Request $request)
{
$airline = airline::all();
$search = $request->get('search');
if($search!=""){
$flights = DB::table('flights')
->join('airlines', 'flights.AirlineId', '=', 'airlines.id')
->select('flights.*', 'airlines.name', 'airlines.country','airlines.logo')
->where(DB::raw("CONCAT(flights.id,' ',flights.flightDesignator,' ',airlines.country,' ',airlines.name,' ',flights.departureFrom,' ',flights.arriveTo,' ',flights.departureTime,' ',flights.ArrivalTime)"),'LIKE','%'.$search.'%')
->paginate(4);
$flights->appends(['search' => $search]);
$count = $flights->count();
if($count == 0)
return view('admin.flights')->with(['flights' => $flights,'airline' => $airline, 'NoFound' => 'There is no result
How do I get the number of rows here? When I use $count = $flights->count();
I get this error Count all elements in an array, or something in an object
public function index(Request $request)
{
$airline = airline::all();
$search = $request->get('search');
if($search!=""){
$flights = DB::table('flights')
->join('airlines', 'flights.AirlineId', '=', 'airlines.id')
->select('flights.*', 'airlines.name', 'airlines.country','airlines.logo')
->where(DB::raw("CONCAT(flights.id,' ',flights.flightDesignator,' ',airlines.country,' ',airlines.name,' ',flights.departureFrom,' ',flights.arriveTo,' ',flights.departureTime,' ',flights.ArrivalTime)"),'LIKE','%'.$search.'%')
->paginate(4);
$flights->appends(['search' => $search]);
$count = $flights->count();
if($count == 0)
return view('admin.flights')->with(['flights' => $flights,'airline' => $airline, 'NoFound' => 'There is no result ????']);
else
return view('admin.flights')->with(['flights' => $flights,'airline' => $airline,'found' => ' records founded']);
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
使用了分页,因此只需更改
$ count = $ fights-> count();
to$ count = $ fights-> total();
>There is pagination is used so just change
$count = $flights->count();
to$count = $flights->total();
尝试使用收集
,然后您可以使用它来计算
try to use collection
and then you can count it with