Laravelde şöyle bir durum yaşıyorum. Trait;
trait UploadController
{
public function uploadImage(UploadedFile $file, string $type)
{
if ($file->isValid()) {
$baseName = '/assets/';
$relativePath = $baseName . $type . '/' . date('Y') . '/' . date('m');
$upload = Storage::put("$relativePath", $file);
$path = Storage::url($upload);
return $path;
}
return null;
}
}
Controller:
if ($request->filled('avatar') && $request->hasFile('avatar')) {
$file = $request->file('avatar');
$userDetailData['avatar'] = $this->uploadImage($file, 'avatar');
}
dd($this->uploadImage($request->file('avatar'), 'avatar'));
dd() içerisine baktığımda bana dönen sonuç:
"/storage/assets/avatar/2023/11/Sk5Sw24SoznSkG1O4cXXeenk5pK2Qhi1lqi9zzl8.jpg" // app/Http/Controllers/Admin/User/UserController.php:66
Tam istediğim gibi fakat ddyi kaldırıp böyle yaptığımda;
if ($request->filled('avatar') && $request->hasFile('avatar')) {
$file = $request->file('avatar');
$userDetailData['avatar'] = $this->uploadImage($request->file('avatar'), 'avatar');
}
Bana böye bir sonuç dönüyor, hata nerede anlamadım:
Illuminate\Http\UploadedFile {#1466 ▼ // app/Http/Controllers/Admin/User/UserController.php:66
-test: false
-originalName: "16.jpeg"
-mimeType: "image/jpeg"
-error: 0
#hashName: null
path: "/private/var/tmp"
filename: "php59SI3R"
basename: "php59SI3R"
pathname: "/private/var/tmp/php59SI3R"
extension: ""
realPath: "/private/var/tmp/php59SI3R"
aTime: 2023-11-08 13:59:47
mTime: 2023-11-08 13:59:47
cTime: 2023-11-08 13:59:47
inode: 98475870
size: 73131
perms: 0100600
owner: 501
group: 0
type: "file"
writable: true
readable: true
executable: false
file: true
dir: false
link: false
}