mardi 29 octobre 2019

Laravel 5.4 pushing new object to array

I am trying to push an object to a user model.

The user model, has the below parameter:

User.posts.

Where posts is an array.

First I tried the below:

$user->posts()->save($Post);

This didn't add the new Post object to the user.posts (but it didn't return an error).

I also tried $user->posts()->push($Post);

and $user->posts = array_add($Post)...but this is requiring three parameters.

Sorry, I am new to laravel...How to push an object instance to the array (posts) of the user model?

Thanks,



from Newest questions tagged laravel-5 - Stack Overflow https://ift.tt/2WlWO4s
via IFTTT

Aucun commentaire:

Enregistrer un commentaire