Post tags sync with additional data like slug.

Posted 11 months ago by nanadjei2

Am building a blog post with tags. On the tags table the tags are posting correctly but its additional slug are not posting.

This is the controller

                'staff_id'  => Auth::user()->id,
                'meta_descripition' => $request->meta_descripition,
                'title' => $request->title,
                'content' => $request->content,
                'image' => $imageFileName,
                $date = str_replace('.', '-', $request->input('published_at')),
                'published_at' => Carbon::parse($date)->format('Y-m-d'),
                'slug' => str_replace(' ', '-', strtolower($request->slug))

$data =  ['slug' => $request->slug];

   $post->tags()->sync($request->post_category_tags, $data);

This is my CmsPost model

  public function tags() {
             return $this->belongsToMany('App\CmsPostCategoryTag', 'cms_post_category_tags', 
               'cms_post_id', 'cms_post_category_id');

Please sign in or create an account to participate in this conversation.

Laracasts Mascot

Hi, Have We Met Yet?

Did you know that, in addition to the forum, Laracasts includes well over 1000 lessons on modern web development? All for the price of one lunch out per month.

Sign Me Up


Reply to

Use Markdown with GitHub-flavored code blocks.