jet
73
11
Laravel

Integrity constraint violation: 1048 Column 'category_id' cannot be null (SQL: insert into `posts`

Posted 3 months ago by jet
 public function store(Request $request)
    {
        $this->validate($request, array(
                'title' => 'required|max:255',
                
        ));

        $post = new Post;

        $post->title = $request->title;
        $post->category_id = $request->category_id;
        $post->content = $request->content;
        $post->order = $request->order;
        $post->views = $request->views;
        $post->status = $request->status;
        $post->slug  = str_slug($request->title);
        $post->meta = $request->meta;
        

        $post->save();

        return redirect()->route('posts.show', $post->id);
    }

how can i fix it

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

Reply to

Use Markdown with GitHub-flavored code blocks.