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

As far as I know you only have to say that a user has an account level and not both! It's all in the documentation

Last updated 2 years ago.

Thanks blackbirddev, that's the documentation I've been using to port my SQL statements over.

I can see how I can find 1 relational record by using a foreign key but not how to call a record and it's associated relational data.

the doc shows me how to pull a record from 'phone' that is related to a 'user'

my need:
I need to pull a 'user' record and also the associated 'accountlevel' record related from the user record

This is where I'm getting a logic disconnect with Eloquent. It looks like I've structured my models correctly but when I try to add


it generates a Laravel error instead of returning the user record + associated data from accountlevel as designed.

I built this in Laravel's Query Builder as a work around.

public function showUser($id) {  
  $user = DB::table('users')  
    ->leftJoin('accountlevel', 'users.accountlevel', '=', '')  
    ->select(' as user_id', 'users.emailaddress as emailaddress', 'users.nickname as nickname', 'users.password as password', ' as accountlevel_id', ' as accountlevel_name')  
    ->where('', '=', $id)  
return View::make('profile')->with('user', $user);  


@section('title', ucfirst($user->nickname))  
  <p><strong>users</strong><br />  
    id: <span>{{ $user->user_id }}</span><br />  
    emailaddress: <span>{{ $user->emailaddress }}</span><br />  
    nickname: <span>{{ ucfirst($user->nickname) }}</span><br />  
    password: <span>{{ $user->password }}</span><br />  
    accountlevel: <span>{{ ucfirst($user->accountlevel_name) }} ({{ $user->accountlevel_id }})</span>  

Which works but still doesn't use Eloquent.

Last updated 2 years ago.

Sign in to participate in this thread!


Your banner here too?

DrFark drfark Joined 25 Aug 2014


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

Your logo here?

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

© 2024 - All rights reserved.