On my page I have two wrappers some users don't have permission to view the second wrapper so using @if($user->direct_mail == 0)
I hide the second wrapper which is great!
However when I login into the user I get Trying to get property of non-object
I think this is because the controller is still passing back the variables for the second wrapper and although its hidden it still throws an error.
Is there a way to not return the variable to the view if it's null
, or equal to 0
. My understanding was because the content was within the if statement and therefore hidden (which it is) it wouldn't throw an error as the variable isn't called on the page.
Example -
@if($user->direct_mail == 0)
<div class="wrapper">
<h2>Wrapper 1#</h2>
</div>
@endif
@if($user->website == 0)
<div class="wrapper">
<h2>Wrapper 2#</h2>
</div>
@endif
Routes
return view('home')
->with('website', $website)
->with('mailJumbo', $mailJumbo)
The variable $mailJumbo
is null as the user doesn't have the data on his user profile thats why the error exists. If the user has the correct permissions to view both wrappers the error doesn't exist.
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire