jeudi 10 septembre 2020

How to send files in array Request method in laravel

This looks simple and kind of stuck here.

I have array like below, which has some fields and one file for each array.

{
  "networks": [
    {
      "username": "silverman-p",
      "slug": "youtube",
      "status": false,
      "avatar":"image/file",
      "name":"my website"
    },
    {
      "username": "silverman-p",
      "slug": "pinterest",
      "status": false,
      "avatar":"image/file",
      "name":"my website"
    } 
  ]
}

Here Im trying in postman able to send data all as text, But when i try to send image and recieve in backend i get errors.

Call to a member function hasFile() on array

here in the code in controller,

public function userlinks(Request $request){
  $me = Auth::user();

  
  foreach ($request->networks as $key => $value) {
  // print_r($value) ;exit;
    $network = Network::where('slug', $value['slug'])->first();
    $network_id = $network->id; 

    if($value->hasFile('avatar')) {
      $file = $value->file('avatar');
      $rand = str_random(56);

    }  

}

Can someone help me..



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire