[Vuejs]-Foreign key on post request Laravel & Vue

0👍

First of all:

$engagement = Engagement::create([
            'return_type' => $request->return_type,
            'year' => $request->year,
            'assigned_to' => $request->assigned_to,
            'status' => $request->status,
            'done' => $request->done,
            + [
                'client_id' => $client_id
            ]
        ]);

why is there this +[...] array thing? Doesn’t really makes sense to me…

But the 500 Server Error most probably results from your false request (which most of 500’s do).

If this is your Route definition:

Route::post('/engagements', 'EngagementsController@store');

This is the method head:

public function store($client_id, Request $request)

And your Post request is the following:

axios.post(('/engagements'), {
        return_type: engagement.return_type,
        year: engagement.year,
        assigned_to: engagement.assigned_to,
        status: engagement.status,
        done: false
      })

You will notice, that the function definition differs from your Route. In the function you expect a parameter ‘client_id’ which isn’t known by the route. So to resolve this issue, put your client_id into the Post request body (underneath your done: false for example) and remove the parameter from the function definition.

Leave a comment