Level 75
Jan 19, 2020
1
Level 8
Uploading an image in Laravel
public function store(Request $request)
{
if(DB::table($this->table)->insert(
[
'name' => $request->input('name'),
'description' => $request->input('description'),
'price' => $request->input('price'),
'kg' => $request->input('kilogram'),
'type' => $request->input('type'),
'img' => $request->input('image'),
'created_at' => Carbon::now(),
'updated_at' => Carbon::now()
]
))
{
$path = Storage::putFile('public/img/product', $request->file('image'));
return redirect()->route($this->table);
}
else
{
return abort(404);
}
}
/**
* Store the uploaded file on the disk.
*
* @param string $path
* @param \Illuminate\Http\File|\Illuminate\Http\UploadedFile $file
* @param array $options
* @return string|false
*/
public function putFile($path, $file, $options = [])
{
return $this->putFileAs($path, $file, $file->hashName(), $options);
}
/**
* Store the uploaded file on the disk with a given name.
*
* @param string $path
* @param \Illuminate\Http\File|\Illuminate\Http\UploadedFile $file
* @param string $name
* @param array $options
* @return string|false
*/
public function putFileAs($path, $file, $name, $options = [])
{
$stream = fopen($file->getRealPath(), 'r');
Call to a member function hashName() on null
Please or to participate in this conversation.