没有有关模型[App \ Products] Laravel的查询结果 [英] No query results for model [App\Products] Laravel
本文介绍了没有有关模型[App \ Products] Laravel的查询结果的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在laravel5中,我收到以下消息(错误)
In laravel5 i got following message(error)
No query results for model [App\Products].
我有一个表"products
",其中有一个列"category_id
",每个类别项目的category Id
.我想根据category Id
I have a table "products
" which has a column "category_id
" that a category Id
of each category items. I want to show the items according to category Id
我的控制器就是这样
public function category()
{
$recordsByCategories=\DB::table('products')
->select('categories','category_id', \DB::raw('count(*) as totalProducts'))
->groupBy('categories')
->get();
return view('dashboard.show',compact('recordsByCategories'));
}
**//I have received error in below function**
public function searchCategoryByTag($id)
{
$category_id = Products::findOrFail($id);
$records=\DB::table('products')->Where('category_id','$category_id');
dd($records);
}
我的路线是这样的
Route::get('categorys/{id}' ,array(
'as'=>'category',
'uses'=>'GoodsController@searchCategoryByTag'));
我的看法是这样的
@foreach($recordsByCategories as $recordsByCategory)
<a href="{{URL::route('category',$recordsByCategory->category_id)}}
" id="search">{{$recordsByCategory->categories}}</a>:{{$recordsByCategory->totalProducts}}
@endforeach
推荐答案
我知道为时已晚,但是对于您(可能是)和其他人的帮助:
I know it's too late, but for the help for you(May be) and other people:
在这里您误认为了'$category_id'
,请删除该单引号.
Here you mistaken the '$category_id'
, remove that single quotes.
public function searchCategoryByTag($id)
{
$category_id = Products::findOrFail($id);
$records=\DB::table('products')->Where('category_id', $category_id);
}
这篇关于没有有关模型[App \ Products] Laravel的查询结果的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文