我嘗試使用diff-Function使用數據透視表來獲取與多個關係中某個項目無關的所有項目。
這就是我想出了: 我想使用diff($collection)
功能,但我總是得到以下錯誤:
Argument 1 passed to Illuminate\Support\Collection::__construct() must be of the type array, object given, called in */vendor/laravel/framework/src/Illuminate/Foundation/ProviderRepository.php on line 157 and defined
見的功能在這裏一個例子:我加入了http://www.neontsunami.com/post/new-collection-methods-in-laravel-4-1
以下兩行提供給我的供應商陣列中的app.php
'Illuminate\Support\Collection',
'Illuminate\Database\Eloquent\Collection',
這是我的代碼User.php
:
public function scopeNotProject($query, $project_id)
{ $all_users = Users::all();
$participants = Project::find($project_id)->users;
$nonparticipants = $all_users->diff($participants);
return $nonparticipants;
}
和我的觀點:(?)
@foreach(User::notProject($project_id)->get() as $nonparticipant)
<option value="{{ $nonparticipant->id }}">{{ $nonparticipant->firstname . " " . $nonparticipant->lastname }}</option>
@endforeach
據我所看到的,通過項目應該是一個集合,而不是一個數組。我是laravel的新手,所以任何幫助表示讚賞!謝謝。