Home > Back-end >  why i can't update table using laravel and api rest and postman?
why i can't update table using laravel and api rest and postman?

Time:09-04

I have a cvs table, which contains image, I want to update this image, use laravel and api rest and postman, but it doesn't work. when I do dd($request->all()); it returns empty array, even I upload my image in postman, my cvs table contains just an image field.

ImageController.php

 public function update(Request $request, $id)
        {
            $cv = Cv::where('id',$id)->first();
            if($request->hasFile('image'))
           {
            $image = date('His').$request->file('image')->getClientOriginalName();
            $path = "public\\annonces\\".$jdate->format('F').$jdate->year;
            $pathh = "annonces\\".$jdate->format('F').$jdate->year."\\".$image;
            $move = $request->file('image')->storeAs($path,$image);
            $cv->image= $pathh;
            }
    
            $cv->save();
            return $cv;
        }

App\Cv.php

class Cv extends Model
{
    protected $guarded = []; 
}

routes/api.php

Route::resource('cvs','CvsController');

CodePudding user response:

I guess that's because You check an input with name photo but upload input name image

CodePudding user response:

You are probably using a PUT or PATCH request right? In that case, in order to Laravel be aware of request content, you need to use a POST request and add '_method': 'PATCH' in your payload from your client side. Not sure how postman handles it, but you should use formData or multipart/form-data for uploading files.

  • Related