javascript - Uncaught (in promise) TypeError: Cannot read property 'uid' of undefined ← (JavaScript)

Solution:

I can see you are using route model binding.

Route::put('/videos/{video}','VideoController@update');

Route model binding works out of the box with ID field. If you use a different key, you need to tell your model to use that key for route model binding.

In Video model add

public function getRouteKeyName() {
    return 'uid';
}

Update

In providers/RouteServiceProvider, add this inside boot()

Route::bind('video', function ($value) {
    return App\Models\Video::where('uid', $value)->first();
});

If it still does not work, simply get the video and update it, the good old way

public function update(VideoUpdateRequest $request, $uid)
{
    $video = Video::where('uid', $uid)->first();
    $video->title = $request->title;
    $video->description = $request->description;
    ...
    $video->update();

    if ($request->ajax()) {
        return response()->json(null, 200);
    }

    return redirect()->back();
}

Answer



Solution:

Replace this this.uid = response.json().data.uid; by this.uid = response.body.data.uid;

it must work,if not let me hear

Read Docs for more

Source