使用带有参数Css的where条件在laravel中不起作用后

问题描述 投票:0回答:1

[我试图在调用此函数CSS后使用带参数的条件条件列出数据库详细信息,但CSS无法正常工作,但所有数据均已正确列出,并且没有参数,CSS正常工作。

web.php

Route::get('/viwelist/{id}','Front\SISProfileController@check');

控制器

class SISProfileController extends Controller
 {

 public function check($district){

    $list = SISAccount::all()->where('District', '==', $district);

    //dd($list->all());


    return view('Front.listSIS', compact('list'));

}

 }

link

 <a href="{{ URL('/viwelist/'.'districtname')}}">click</a>

This is the viwe

php html css laravel web-deployment
1个回答
0
投票

您正在做的是从数据库中获取所有元素,并通过Collection::where方法检查条件,如果数据库中有很多数据,这将引起很多问题。相反,您应该直接在数据库上使用where方法,而不是只获取那些记录,因此您应该执行以下操作:

$list = SISAccount::where('District', '=', $district)->get(); //to get back a Collection with all the records

$list = SISAccount::where('District', '=', $district)->first(); //to get only the first record, like if District is your primary key

还请记住,在这种情况下(以及在Collection where方法中,运算符为=,而不是==

© www.soinside.com 2019 - 2024. All rights reserved.