dimanche 10 juin 2018

Call to a member function store() on null in Laravel 5.5 using postman

I'm testing file upload with Postman but I always get this error. I've already tried adding and removing from the headers in the Postman request the field "multipart/form-data" with no result.

Postman screenshot

My code:

public function update(Request $request, $id) {
    $validator = Validator::make($request->all(), [
        'name' => 'string|max:255',
        'second_name' => 'string|max:255',
        'description' => 'string|max:255',
        'gender' =>  'string|max:255',
        'admin' =>  'boolean',
        'birthday'  => 'string|max:255',
        'email' => 'string|email|max:255|unique:users',
        'password' => 'min:6|required_with:password_confirmation|same:password_confirmation',
        'file' => 'file',
    ]);

    if ($validator->fails()) {
        return response()->json(['error' => $validator->errors()], 401);
    }

    $user = User::find($id);
    $user->name = $request->input('name');
    $user->second_name = $request->input('second_name');
    $user->description = $request->input('description');
    $user->gender = $request->input('gender');
    $user->admin = $request->input('admin');
    $user->birthday = $request->input('birthday');
    $user->email = $request->input('email');
    $user->imageUrl = $request->file('file')->store('images');

    if($user->save()) {
        return new $user;
    }
}



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire