This might work for you:
<?php
public function getIndex($profile_uname)
{
if(Sentry::getUser()->username === $profile_uname) {
// This is your profile
return View::make('user.profile.index');
} else {
// This isn't your profile but you may see it!
return View::make('user.profile.index')->with('user', Sentry::findUserByLogin($profile_uname));
}
}
If username is not your login column, then you can do it in two steps:
$userId = \Cartalyst\Sentry\Users\Eloquent\User::where('username', $profile_uname)->first()->id;
return View::make('user.profile.index')->with('user', Sentry::findUserById($userId));
If you have a User model tied to your users table, you can just do:
$userId = User::where('username', $profile_uname)->first()->id;
return View::make('user.profile.index')->with('user', Sentry::findUserById($userId));
And in this last case you probably will be able to use that same model, since they would be the same in Sentry and pure Eloquent:
$user = User::where('username', $profile_uname)->first();
return View::make('user.profile.index')->with('user', $user);
Also, to avoid a conflict between your views related to the current logged user, you should rename the $user
variable you are instantiating via View::share()
or View::composer()
from $user
to $loggedUser
or something like that.