我有以下範圍在模型建立:Laravel範圍查詢拋出異常Grammar.php
public function scopeInbox($query, $order = 'desc'){
$userId = Auth::user()->id;
return $query
->where('current_inbox','=',$userId)
->join('users', 'messages.created_by', '=', 'users.id')
->join('users as forwarder', 'messages.forwarded_by', '=', 'forwarder.id')
->select('messages.*', 'users.name', 'forwarder.name as forwarder')
->orderBy('updated_at', $order);
}
而且在它下面的關聯控制器:
public function inbox()
{
$messages = Message::inbox();
return response($messages->get());
}
而Laravel不斷拋出以下例外:
Argument 1 passed to Illuminate\Database\Grammar::columnize() must be of the type array, string given
任何想法,S/O?
'scopeInbox'? '消息:: scopeInbox'? – aldrin27
我的代碼幾乎完全按照文檔:http://laravel.com/docs/5.1/eloquent#query-scopes「範圍」不應該是必要的。 –
就查詢生成器語法而言,您的代碼是正確的。你確定錯誤是從那裏來的嗎?您沒有包含引發錯誤的文件和行。 – Bogdan