1

i tried everything for some reason i keep getting this error even tho im selecting that one thing with that one id and when i dd it on the controller it gets it right but in the view its giving the error heres

     $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);

and heres my view

<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>
Mohammad hayajneh
  • 623
  • 2
  • 11
  • 32

1 Answers1

2

Will something like this work for you? Mapping the collection to ensure we always have a TitleEn, DescriptionEn and ContentEn by getting App::getLocale() and setting the first letter to uppercase (A little more DRY)

$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);

I could update my answer if you provide a dd() of $affiliate as well as confirming if the error comes from the view or the controller (which line in particular).

Update: You have a spelling mistake when you write with('Affiliates', $affilliate) it should be one l character not two so change it to with('Affiliates', $affiliate). I'd consider refactoring if I were you so I will keep my original answer there.

HelloSpeakman
  • 810
  • 9
  • 22