I am using "jgrossi/corcel": "3.0.0", Laravel 6.16.0 and PHP 7.4.1
I would like to add an existing category Product to my new post in wordpress. However, I am not sure how to do this.
I can create a wordpress post the following way:
$post = new Post();
$post->post_title = $title;
$post->post_content = $msg;
$post->save();
Any suggestions how to use corcel to add an existing category to the post?
Appreciate your replies!
The Post model has a belongsToMany relationship to the taxonomies model, as you can see here...
Therefore you should be able to link the post to a category using the category id like so...
You can find more about these types of relationships here https://laravel.com/docs/8.x/eloquent-relationships#updating-belongs-to-relationships