lundi 23 novembre 2015

Error trying to insert data with Laravel 5.1

I'm having a had time trying to insert data using Laravel 5.1

here's my code :

$event = Event::whereId($request->input('event'))->first();

$participant = new Participant([
    'email' => $request->input('mail'),
    'lastname' => $request->input('lastname'),
    'firstname' => $request->input('firstname'),
    'phonenumber' => $request->input('phone'),
    'address' => $request->input('address'),
    'department' => $request->input('department')
]);

$gender = Gender::whereId($request->input('gender'));
$expertise = Expertise::whereId($request->input('expertise'));
$country = Country::whereId($request->input('country'));

$participant->gender()->associate($gender);
$participant->expertise()->associate($expertise);
$participant->country()->associate($country);

$event->participant()->save($participant);

her's my error :

"Object of class Illuminate\Database\Eloquent\Builder could not be converted to string"
[...]
at BelongsToMany->save(object(Participant)) in EventController.php line 122

Line 122 correspond to : "$event->participant()->save($participant);"

I don't think you need any more information but you can always ask me.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire