Support the ongoing development of Laravel.io →
Requests Views Architecture
Last updated 2 years ago.
0

If I'm not mistaken, it would be something like:

@if ( Auth::user()->username == "YourUsername" )
Last updated 2 years ago.
0

You need to create a column in your article table with the owner id.

While looping through your articles you can do a check like this:

@if(Auth::user()->id == $article->user_id) 

Would give you a more complete example, but I'm on the train typing on my phone.

Last updated 2 years ago.
0

Hey mengidd,

I tried your example, but it returns an:

Trying to get property of non-object

So I guess that is what you meant by a more complete example :p?

Last updated 2 years ago.
0

Hey StyleOnPc,

I tried your example without luck, it returns the same error as above. I ofc replaced with my username, seems like i am missing something?

Last updated 2 years ago.
0

Use roles.

@if ( Auth::user()->role == "admin" || $post->created_by == Auth::user()->user_id ) 
Last updated 2 years ago.
0

Hey extjac, Im trying to implement Zizaco's entrust package, for doing what you suggest. It seems that if I use:

@if (! Entrust::hasRole('Admin') )

I dont get any error messages, however, my challenge now is that i'm not sure where to declare my users roles, so that they can be passed to my views?

Last updated 2 years ago.
0

I am not familiar with the Zizaco's entrust package. My guess is that you might have a USERS table and a USERS_ROLES table where you create the relationship. User_id =1, role ='admin'.

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Reached reached Joined 27 Feb 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.