jet
12
11
Laravel

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

Posted 1 month 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.

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

Channels

Reply to

Use Markdown with GitHub-flavored code blocks.