我正在尝试在 Laravel 中创建集合并尝试在 View 中打印它,但这显示错误
Trying to get property of non-object
谁能告诉我我哪里错了。
$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
最佳答案
您需要像这样访问数组索引
$seo1['meta_title']
而不是
$seo1->meta_title
关于laravel - 尝试打印集合 laravel 时尝试获取非对象的属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48340281/