artisticre
6 months ago

Insert ID in different Table

Posted 6 months ago by artisticre

I am trying to have the user_id inserted in my post table when the post is created but it isn't working. What can I do?

public function store(Request $request)
    {
        // validate the data

          $this->validate($request, array(
            'title' => 'required|max:255',
            'body' => 'required'
          ));
        //store in the database
            $post = new Post;
            $post->user_id = Auth::user()->id;
            $post->title = $request->title;
            $post->body = Purifier::clean($request->body);
            $post->user_id = $request->user_id;



            $post->save();

            Session::flash('success', 'Your Prayer Request Has Been Submitted');
        //redirect to another page

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

    }

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