vendredi 17 mai 2019

PHP - Call to a member function store() on null

I tried to upload an image through Laravel rest API but got this error message

Call to a member function store() on null

My code

public function upload(Request $request){

        $patient = DB::table('patients') 
            ->select('patients.id','patients.user_id')
            ->where('patients.user_id',Auth::user()->id)
            ->first();

        $patient = Patient::find($patient->id);
        $patient->image = $request->image->hashName();
        $patient->save();

        $path = $request->file('image')->store('avatar','public');

        if($patient->save()){
            return response()->json(['success' => Auth::user()->id], $this-> successStatus); 
        }
        else{
            return response()->json(['failed' => $user], $this-> successStatus); 
        }
    }

Please advice. Thank you.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire