1

This is the controller code:

 $player1QID = time().'.'.$request->player1_Id->extension(); 
    $images1= $request->player1_Id->move(public_path('images'), $player1QID);
   
    $player2QID = time().'.'.$request->player2_Id->extension();  
     
    $images2= $request->player2_Id->move(public_path('images'), $player2QID);

///this is adding to database:

       $registeredusers = Registrations::create([
        'tournament_id' => $request->input('tournament_id'),
         'player1_name' => $request->input('player1_name'),
         'player1_email' => $request->input('player1_email'),
         'player1_Id' => $player1QID,
         'player1_gender' => $request->player1_gender,
         'player1_phone' => $request->input('player1_phone'),
         'player2_name' => $request->input('player2_name'),
          'player2_email' => $request->input('player2_email'),
          'player2_Id' => $player2QID,
         'player2_gender' => $request->player2_gender,
         'player2_phone' => $request->input('player2_phone'),
          'category' => $request->category,
          'status' => $request->input('status'),
        
       
        
    ]);

This is in view blade:

Upload image1 Upload image2

Really appreciate if someone can help

1 Answer 1

1

you should first look at your inspection in Chrome, Firefox or whatever you are using, and check what your request contains, I mean if you are sending the images in separate names like: ... player1_Id: player2_Id: ... i think, of course is sending like that because you are receiving it on your controller. Then try save it with datetime at end of name like:

public function obtainImage(Request $request){

$image1=request('player1_Id');

$this->manageImage($image1);

$image2=request('player2_Id');

$this->manageImage($image2);
}

public function manageImage($image){ $fileImageNameExtencion=$image->getClientOriginalName();

  $fileName=pathInfo($fileImageNameExtencion, PATHINFO_FILENAME);

  $fileExtencion=$image->getClientOriginalExtension();

  $newFileName=$fileName."_".time().".".$fileExtencion;

  $saveAs=$image->storeAs('public/images',$newFileName);
  return $newFileName;

}

where $ newFileName is what you need to save to your database

otherwise you can do a dd ($ player1QID. '-'. $ player2QID) before saving to database and comparing names

Sign up to request clarification or add additional context in comments.

3 Comments

i tried doing this:dd ($ player1QID. '-'. $ player2QID) ,,but I got same name for both images...specifically second image name
i checked by dd()..after adding your function its getting different image names for database storage..but files are not saved in images folder
Thank you Mr.Subhashis Pandey....I solved the issue of not saving by adding this code:$request->player1_Id->move(public_path('images'), $QID1); $request->player2_Id->move(public_path('images'), $QID2);

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.