我如何将我的 Blog_id 放入此包中

问题描述 投票:0回答:1

我正在使用这个套餐

https://github.com/rtconner/laravel-tagging

但我不明白如何将 blog_id 放入此包中,我收到此错误

SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'taggable_id' cannot be null (SQL: insert into `tagging_tagged` (`tag_name`, `tag_slug`, `taggable_type`, `taggable_id`) values (Gardening, gardening, App\blog, ))

这是我的控制器

public function blogstore(Request $request){


     $this->validate($request, [
        'title' => 'required|max:255|unique:blogs',
        'summary' => 'required',
        'description' => 'required',
        'image' => 'image',
        'agree' =>  'required',
    ]);

    $blog = new blog;
    $blog->title = $request->title;
    $blog->summary = $request->summary;
    $blog->content = $request->description;
    $blog->user_id = Auth::user()->id;
    $blog->slug = EasySlug::generateSlug($blog->title, $separator = '-');
    $blog->tag('Gardening');  //this is working tag name
    $blog->tag(1);      //trying to add blog_id
    if($request->hasFile('image')) {
        $file = Input::file('image');
        //getting timestamp
        $timestamp = str_replace([' ', ':'], '-', Carbon::now()->toDateTimeString());

        $name = $timestamp. '-' .$file->getClientOriginalName();

        $blog->image = $name;

        $file->move(public_path().'/../public_html/img/blog/', $name);

        $thumb = Image::make(public_path().'/../public_html/img/blog/' . $name)->resize(1366,786)->save(public_path().'/../public_html/img/blog/thumb/' . $name, 90);
    }

    $blog->save();
    return redirect()->route('admin.blog.index')->with('status', 'Blog Posted Successfully');
}
php laravel laravel-5 tags
1个回答
0
投票

您必须将

taggable_id
分配给博客对象,如

$blog->taggable_id='SOME_VALUE';

否则taggable_id将为空,或者您可以在数据库中设置taggable_idas自动增量。

© www.soinside.com 2019 - 2024. All rights reserved.