Support the ongoing development of Laravel.io →
posted 10 years ago
Database
Last updated 2 years ago.
0

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.

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

ezebra ezebra Joined 15 Aug 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.