uploaded file path is not working
Hi , i have this line of code in my controller
asset(Storage::putFile('public', $request->file('file')));
the returned path result is 404 .. also i have done
php artinsan storage:link
any solutions ?
Why is it wrapped in asset? That makes little sense
@Sinnbeck to generate a full path to that image
@Sinnbeck
controller :
public function store(StoreContactRequest $request)
{
$file = Storage::putFile('public', $request->file('file'));
return "<img src='$file'>";
}
StoreContactRequest :
public function rules()
{
return [
'fullname' => ['required'],
'email',
'phone_number',
'home_number',
'file' =>['file','mimetypes:image/jpg,image/png,image/jpeg'],
];
}
@faraz73 Why are you returning a img tag from your store method? Is this used for ajax?
Start by using dd() to see what is stored
$file = Storage::putFile('public', $request->file('file'));
dd($file);
@Sinnbeck to see the file path works or not .. the upload has done successfully .. but i don't know how to get correct path to load image in view ...
@faraz73 Normally you would save the path to a model in the database, so you can get it back later on.
@Sinnbeck well ... I should make sure inserted data is correct .. this line
Storage::putFile('public', $request->file('file'));
returns path ... but not works X(
@faraz73 To test it
- Upload image and get the path using dd() as explained
- Add the path to the url and hit enter
@faraz73 "not working" isnt very informative. What happens? It says the file does not exist?
- What is the exact url you are trying with?
- What is the path?
- Can you see the file in /public/storage
@Sinnbeck yes .. to get currect path .. i should use :
$file = $request->file('file')->store('public');
$path = Storage::path($file);
this one works ...
what path does it generate and where is the file stored?
based on this "not working" - you don't want to put in the effort then neither do I. It's obviously not that important.
Please or to participate in this conversation.