0

Well I have this problem... I have created a new place record, and then I check that it exists.

enter image description here

So far so good, but now when I want to link it to some restaurant, it returns 422 Error.

enter image description here

I was looking for some answer, but I don't understand what I did wrong.

This is my code:

    public function store(Request $request){

    $this->authorize('create', Feeding::class);

    $request->validate([
        'date' => 'required|date|max:255',
        'food' => 'required|string|max:255',
        'observation' => 'required|string',
        'quantityLunchs' =>'required|integer',
        'user_id' => 'required|exists:users,id',
        'artist_id' => 'required|exists:artists,id',
        'place_id' => 'required|exists:places,id',

    ], self::$messages);

    $feeding = Feeding::create($request ->all());
    return response() -> json($feeding, 201); //success
}

The headers I use in postman:

Authorizaton: Bearer token

Accept: application/json

Any solutions? Tank you

juliomalves
  • 42,130
  • 20
  • 150
  • 146

1 Answers1

0

Ok, I solved.

I had to replace here:

enter image description here

Becouse I want to link with feeding_places, no with places Fiuuu!

  • Do not use images as they can go down and then the question makes no sense as you can't see the data because it was in an image... Copy paste the code... – matiaslauriti Jul 12 '21 at 02:49