Randy_Johnson
2 months ago
170
1
General

Uploading an image in Laravel

Posted 2 months ago by Randy_Johnson
  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 sign in or create an account to participate in this conversation.