If I'm not mistaken, it would be something like:
@if ( Auth::user()->username == "YourUsername" )
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.
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?
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?
Use roles.
@if ( Auth::user()->role == "admin" || $post->created_by == Auth::user()->user_id )
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?
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'.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community