Php 数据库中的laravel空集合
我不知道为什么我这里的藏品是空的。在过去,这对我来说很有用,但为什么我现在得到这个呢?我哪里做错了Php 数据库中的laravel空集合,php,laravel,Php,Laravel,我不知道为什么我这里的藏品是空的。在过去,这对我来说很有用,但为什么我现在得到这个呢?我哪里做错了 public function test($id){ //dd($id); $test = DB::table('images')->select('name')->where('user_id', $id)->get(); dd($test); } 它还给我这个: Collection {#402 ▼ #items: [] } 我已经定义了我的路
public function test($id){
//dd($id);
$test = DB::table('images')->select('name')->where('user_id', $id)->get();
dd($test);
}
它还给我这个:
Collection {#402 ▼
#items: []
}
我已经定义了我的路线:
Route::get('/test/{id}', ['as'=>'create', 'uses'=>'testController@test']);
我做了一个dd($id)
,它返回了我想要的id,因此该部分是正确的,当我做DB::table('images')0>选择('name')->get()代码>它返回我的数据,因此它已被传递,但一旦我尝试添加id,它就不起作用
我甚至尝试过这样做,但都不起作用:
$test = DB::table('images')->join('user1s', 'user1s.id', '=', 'images.user_id')->select('images.name')->where('images.user_id', 'user1s.id')->get();
关系:
user1s有一个映像
我假设$id
与数据库中的用户id
不匹配,您的查询没有问题,因此您没有得到结果
尝试使用数据库中可用的user\u id
,例如:
public function test($id){
$test = DB::table('images')->select('name')->where('user_id', $id)->get(); //take $id which is user_id available in your DB
dd($test);
}
希望这能帮助你,理解你 我假设$id
与数据库中的用户id
不匹配,您的查询没有问题,因此您没有得到结果
尝试使用数据库中可用的user\u id
,例如:
public function test($id){
$test = DB::table('images')->select('name')->where('user_id', $id)->get(); //take $id which is user_id available in your DB
dd($test);
}
希望这能帮助你,理解你 我认为$id
与用户id
不匹配,这就是你没有得到结果的原因!哦,天哪,你说得对,我忘了检查用户id,我已经太关注$id了。非常感谢@HirenGohelI,我认为$id
与用户id
不匹配,这就是你没有得到结果的原因!哦,天哪,你说得对,我忘了检查用户id,我已经太关注$id了。非常感谢@HirenGohel