我尝试了一切由于某种原因我一直得到这个错误甚至我选择那个一个id的东西,当我在控制器上它得到它正确但在视图中给出错误继承人
$affilliate = Affiliate::find($id);
if (App::getLocale() == 'ar') {
$affilliate->TitleEn = $affilliate->TitleAr;
$affilliate->DescriptionEn = $affilliate->DescriptionAr;
$affilliate->ContentEn = $affilliate->ContentAr;
}
if (App::getLocale() == 'ur') {
$affilliate->TitleEn = $affilliate->TitleUr;
$affilliate->DescriptionEn = $affilliate->DescriptionUr;
$affilliate->ContentEn = $affilliate->ContentUr;
}
if (App::getLocale() == 'ch') {
$affilliate->TitleEn = $affilliate->TitleCh;
$affilliate->DescriptionEn = $affilliate->DescriptionCh;
$affilliate->ContentEn = $affilliate->ContentCh;
}
return view('affilliates.affilliate-details')
->with('Affiliates', $affilliate);
并且继承了我的观点
<div class="row">
<div class="col-xs-12">
<h3 class="orange-heading">{{$Affiliates->TitleEn}}</h3>
<hr class="orange-hr pull-left">
</div>
<div class="col-xs-12 lead">
<p>{!! $Affiliates->ContentEn !!} </p>
</div>
</div>
答案 0 :(得分:2)
这样的事情对你有用吗?映射集合以确保我们始终拥有TitleEn
,DescriptionEn
和ContentEn
获取App::getLocale()
并将第一个字母设置为大写(稍微干一点)
$affilliate = Affiliate::where($id);
$affiliateMapped = $affiliate->map(function($affiliate) {
$locale = ucfirst(App::getLocale());
$affiliate['TitleEn'] = $affiliate["Title{$locale}"];
$affiliate['DescriptionEn'] = $affiliate["Description{$locale}"];
$affiliate['ContentEn'] = $affiliate["Content{$locale}"];
return $affiliate;
});
return view('affilliates.affilliate-details')
->with('Affiliates', $affiliateMapped);
如果您提供dd()
$affiliate
以及确认错误是来自视图还是控制器(特别是哪条线路),我可以更新我的答案。
更新:编写with('Affiliates', $affilliate)
时出现拼写错误,应该是一个l
字符而不是两个字符,因此将其更改为with('Affiliates', $affiliate)
。如果我是你,我会考虑重构,所以我会保留原来的答案。