Hmm, doesn't seem to work this way. I end up with duplicate entries. I had another idea using the diff($collection) function but I always get the following error:
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
See an example here: http://www.neontsunami.com/post/new-collection-methods-in-laravel-4-1
I added the following two lines to my providers array in app.php
'Illuminate\Support\Collection',
'Illuminate\Database\Eloquent\Collection',
This is my code in 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;
}
and my View:
@foreach(User::notProject($project_id)->get() as $nonparticipant)
<option value="{{ $nonparticipant->id }}">{{ $nonparticipant->firstname . " " . $nonparticipant->lastname }}</option>
@endforeach
As far as I can see, the passed item should be a COllection and not an array(?). I'm new to laravel so ANY help is appreciated! Thank you.
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community