2013-05-09 1 views
2

У меня есть это в моей модели контакта:Как назначить имена столбцов в постраничную Laravel() Метод

public static function contacts($perPage = 10) 
{ 
    $order_type = '.desc'; 
    $order = Session::get('contact.order', 'first_name' . $order_type); // Set the default order to created_at DESC 
    $order = explode('.', $order); 

    $columns = array(
     'contacts.id as id', 
     'contacts.first_name as first_name', 
     'contacts.last_name as last_name', 
     'contacts.telephone_number as telephone_number', 
     'contacts.email as email', 
     'accounts.company_name as account', 
     'users.first_name as am_first_name', 
     'users.last_name as am_last_name' 
    ); 

    $contacts = DB::table('contacts') 
     ->leftJoin('accounts', 'account_id', '=', 'accounts.id') 
     ->leftJoin('account_managers', 'accounts.account_manager_id', '=', 'account_managers.id') 
     ->leftJoin('users', 'user_id', '=', 'users.id') 
     ->orderBy($order[0], $order[1]) 
     ->paginate($perPage, $columns); 

    return $contacts; 
} 

Это не назначая мой «как» заявление по столбцам, я хочу, это означает, что я получаю «Имя столбца first_name неоднозначно.

Вы не можете сделать это с помощью метода Paginate?

Приветствия

ответ

9

Вы должны использовать select($columns) ...

$contacts = DB::table('contacts') 
    ->select($columns) 
    // other bits 
    ->paginate($perPage); 

Как упоминалось в Specifying A Select Clause

 Смежные вопросы

  • Нет связанных вопросов^_^