I have a tag and post models.
App\Tag
public function posts()
{
return $this->belongsToMany('App\Post','post_tag','post_id');
}
App\Post
public function tags()
{
return $this->belongsToMany('App\Tag','post_tag','tag_id')->withTimestamps();
}
I want to add tag when add post.
PostController@store
public function store(Request $request)
{
\Auth::user()->posts()->save(new Post($request->all()));
return \Redirect::route('posts.index');
}
How do I use this save method in my store function?
App\User::find(1)->roles()->save($role, ['expires' => $expires]);
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire