When I tried to upload the file it shows error:
Undefined variable: request
This is where I used it: UploadController:
if($request->hasFile('file')){
$file = $request ->file('file');
$fileName = $file->getClientOriginalName();
$destinationPath = config('app.fileDesinationPath').'/'.$fileName;
$uploads = Storage::put($destinationPath,file_get_contents($file->getRealPath()));
}
return redirect()->to('/upload');
What's wrong here?
Add Request $request
parameter in your function. Example:
public function yourFunction(Request $request)
{
if($request->hasFile('file')){
$file = $request ->file('file');
$fileName = $file->getClientOriginalName();
$destinationPath = config('app.fileDesinationPath').'/'.$fileName;
$uploads = Storage::put($destinationPath,file_get_contents($file->getRealPath()));
}
return redirect()->to('/upload');
}
Please read the documentation thoroughly: http://laravel.com/docs
You can also watch Laravel tutorials here: http://laracasts.com
You can also use request()
helper function as:
if(request()->hasFile('file')) {
...
}
The request function returns the current request instance.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With