Hi there i'm storing data in my db tables through forms inside a view. The view is about products which contain a brand and a model. Im storing in the products table the brand id and the model id, but what i want to show in my view is the brand name and not the id, and the same for the model.
@foreach($file as $key => $product)
<tr>
<td style="display: none">{{ $key+1 }}</td>
<td>{{ $product['ptype']['productType']}}</td>
<td>{{ $product->brand_id}}</td>
<td>{{ $product->model_id}}</td>
When i show the productType it works fine but if i do:
<td>{{ $product['brand']['brandName']}}</td>
i get the error:
Trying to access array offset on value of type null
ProductController:
public function add(){
$product['ptypes'] = Ptype::all();
$product['brands'] = Brand::all();
$product['models'] = ModelP::all();
return view('backend.product.add-product', $product);
}
public function store(Request $request){
$product = new Product();
if($request->file('file')){
$file = $request->file('file');
$filename = time().'.'.$file->getClientOriginalName();
$request->file->move('storage/', $filename);
$product->file = $filename;
}
$product->ptype_id = $request->ptype_id;
$product->brand_id = $request->brand_id;
$product->model_id = $request->model_id;
$product->description = $request->description;
$product->fob = $request->fob;
$product->sale_price = $request->sale_price;
$product->buy_coin = $request->buy_coin;
$product->sale_coin = $request->sale_coin;
$product->quantity = '0';
$product->created_by = Auth::user()->id;
$product->save();
Session::flash('success');
return redirect()->route('products.view');
}
I've never seen a view error like this, and i dont have a clue how to fix it. I've look for similar questions in other forums but i still can't solve it.