$oAgent= DB::table('agents')
->join('users', 'users.id', '=', 'agents.id_user')
->where('id_user','=', Sentry::getUser()->id)
// ->where('first_name','=', 'main')
->paginate();
$oAgent has a join on users, wouldn't it contain the user record?
Maybe something like $oAgent[0]->users->first_name
A total guess as I don't know your table structures.
Also, do you need the "->paginate();". The only reference I see is $oAgent[0]->id_agent. And the "->where('id_user','=', Sentry::getUser()->id)" hopefully should only return one record.
Hope that helps
Thanks TerrePorter but this update code And I need one query and loop to get first,last name from table users
public function getAccountList()
{
$oAgent= DB::table('agents')
->join('users', 'users.id', '=', 'agents.id_user')
->where('id_user','=', Sentry::getUser()->id)
->paginate();
$oAgents= DB::table('agents')
->join('users', 'users.id', '=', 'agents.id_user')
->where('id_parent',"=",$oAgent[0]->id_agent)
->paginate();
$oAgentArr =array( $oAgent[0]->id_agent);
$oUserArr =array(Sentry::getUser()->id);
foreach ( $oAgents as $dKey => $oAgentt) {
array_push($oAgentArr,$oAgentt->id_agent);
array_push($oUserArr,$oAgentt->id_user);
}
$oUsers = DB::table('users')
->whereIn('id',$oUserArr )
->paginate(Config::get('app.list_length'));
$oAccounts = DB::table($this->oAccountModel->getTable())
->join('mt4_users', 'login', '=', $this->oAccountModel->getTable().'.mt4_users')
->whereIn('agents_idAgent',$oAgentArr)
->paginate(Config::get('app.list_length'));
return View::make('agent.accounts.AccountsList')
->with('oAccounts', $oAccounts);
}
Maybe something like ...
...
oNames = array();
foreach ( $oAgents as $dKey => $oAgentt) {
array_push($oAgentArr,$oAgentt->id_agent);
array_push($oUserArr,$oAgentt->id_user);
// store the user's name
$oNames[ $oAgentt->id_agent ] = $oAgentt->users->first_name . ' ' $oAgentt->users->first_name;
}
...
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community