lundi 27 août 2018

Laravel 5.6 - Cannot change the uploaded file name in $request

I created a form with file and uploads the file and stores the data in the database very well. The problem is, I need to store the modified file name in the database but the Laravel stores the temporary name. This is the code

public function store(Request $request)
{
    $image = $request->file('file');
    $imageName = time().rand(1,100).$image->getClientOriginalName();
    $image->move(public_path('uploads'),$imageName);
    $request['file'] = $imageName;
    //$request->file = $imageName;
    $im = new Image($request->all());
    $this->user->images()->save($im);
}

I tried to modify the file manually but it didn't work. This the dd of $request

enter image description here

But still the temporary file name is inserted in to database.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire