First Laravel project. I have a DBController what selects a row from the database after the url (for example the URL is /product/123 then it search for the product which barcode is 123). And I want to make a table about the productdetails on the next page.
Controller:
class ProductDetailsController extends Controller
{
public function product($id){
$product = DB::select('select * FROM inventory WHERE barcode = ?', [$id]);;
return view('productdetails',['product'=>$product]);
}
}
print_r($product) output:
Array ( [0] => stdClass Object ( [ID] => 1 [barcode] => 01233 [brand] => Ismeretlen [supplier] => 1 [type] => Építésianyag [name] => Homok [img] => homok.jpg [wholeprice] => 3000 [price] => 5500 [VAT] => 3 [whereis] => U [whereis2] => 1 [count] => 8 [dimension] => m3 [threshold] => 1 [lastsell] => [lastbuy] => [lastchange] => 2017-02-23 20:56:46 [register] => ) )
If I try I got:
ErrorException in 20d205ed160f36c734b8252e44ac81bfa0977988.php line 6: Trying to get property of non-object (View: /var/www/html/project/laravel/leltar/resources/views/productdetails.blade.php)
And if I try I got:
ErrorException in 20d205ed160f36c734b8252e44ac81bfa0977988.php line 6: Undefined index: brand (View: /var/www/html/project/laravel/leltar/resources/views/productdetails.blade.php)
What's going wrong?
I learn Laravel from this PDF
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire