Support the ongoing development of Laravel.io →
Database Eloquent
Last updated 2 years ago.
0

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'));

    }

  }

}
Last updated 2 years ago.
0

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

Last updated 2 years ago.
0

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:

http://laravel.com/docs/eloquent#eager-loading

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

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.