我如何把我的Blog_id放在这个包中

时间:2016-07-06 00:10:45

标签: laravel tags laravel-5.2

我正在使用此套餐

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');
}

1 个答案:

答案 0 :(得分:0)

您必须将int main(){ for(int n: {0, 1, 2, 3, 4, 5}) // the initializer may be a braced-init-list std::cout << n << ' '; return 0; } 分配给博客对象,例如

taggable_id

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