I am trying to upload a photo with Request::file('file')->move('location/file.type');
But it doesn't seem work, it creates new folder with the name of the file. Not upload the file.
I got really confused of this because in another controller it works very well with the same code.
Here is the controller:
/*
* upload the avatar
*/
if ($request->hasFile('avatar')){
$file = $request->file('avatar');
$name = str_random(15).".{$file->getClientOriginalExtension()}";
// cek if the name already exists
while (\File::exists("images/travelagents/avatar/{$name}")){
$name = str_random(10).'.'.$file->getClientOriginalExtension();
}
$file->move("images/travelagents/avatar/{$name}");
$travelAgent->avatar = $name;
}
$travelAgent->save();
and the result was:
###when i change the code
/*
* upload the avatar
*/
if ($request->hasFile('avatar')){
$file = $request->file('avatar');
$name = "test.{$file->getClientOriginalExtension()}";
$file->move("images/travelagents/avatar/{$name}");
$travelAgent->avatar = $name;
}
$travelAgent->save();
And the result:
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community