Doesn't that code always end up returning the profile for the user with the id of 1? An example more in tune with Laravel would be like this I think:
class ProfileController extends BaseController {
/**
* @param $username
*
* @return \Illuminate\View\View
*/
public function show($username)
{
//get user from db, if no result throw not found (404)
$user = User::whereUsername($username)->with('profile')->first();
if ($user->active)
{
// return the active user view
return View::make('profile.user', compact('user'));
} else
{
// return the inactive view
return View::make('profile.inactive', compact('user'));
}
}
}
Yes, it does - I'm trying to make it dynamic, but keep getting errors.
Thanks for your help. However, I'm getting an error:
ErrorException (E_UNKNOWN) Undefined variable: profile
That's weird. It should work as long as you have a model named Profile and a relationship setup within the User model. Check out the eager loading part of the laravel docs:
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community