I am trying to make collection in laravel and trying to print it in view but this is showing me error
Trying to get property of non-object
anyone tell me where I am wrong.
$seo = Collection::make([
"meta_title" => "Eco Elegant - Frp Dustbins & Planters Manufacturers in India",
"meta_desc" => "Eco Elegant is the leading manufacturer and designers of stainless steel/ (Fiber Reinforced Plastic) FRP planters and dustbins for places with diverse usage needs.",
"meta_keyword" => "Eco Elegant, Frp Dustbins, Frp Planters, Stainless Steel Dustbins, Stainless Steel Planter, Dustbins and Planter Suppliers, Exporters in India"
]);
@if($seo->count() > 0)
@foreach($seo as $seo1)
<title>{{ $seo1->meta_title }}</title>
<meta name="description" content="{{ $seo1->meta_desc }}">
<meta name="keywords" content="{{ $seo1->meta_keyword }}">
@endforeach
@else
<title>Eco Elegant</title>
<meta name="description" content="">
<meta name="keywords" content="">
@endif
3
Answers
You need to access the array index like
Instead of
Since you have a single array in the collection and not a collection of arrays or objects, you don’t need to iterate over it.
So, remove the
foreach()
part and use:Instead of:
It seems only one item in you collection as per your question So remove the foreach and try once