In laravel5 i got following message(error)
No query results for model [App\\Products].
I have a table \"products
\" which has a
**You should change form **
$category_id = Products::findOrFail($id);
$records=\DB::table('products')->Where('category_id','$category_id')->get();
change to this
$records = Products::where('category_id', $id)->get();
`$categroy_id `
**is get object form your products table instance of **$category_id
to $category_id->id
Check your API routes. Make sure nothing is competing with that endpoint that would cause a 404 error on the request for /products
. This happens to me often.
Try adding this member to your Product model class;
protected $table = 'products';
I know it's too late, but for the help for you(May be) and other people:
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);
}
If $id equals category id, do only $records = Products::where('category_id', $id)->get();
in searchCategoryByTag.