Skip to content

Error: Method Store does not exist. When trying to store a file. Laravel 5.3 #16511

@ghost

Description

  • Laravel Version 5.3
  • PHP Version: 5.6
  • Database Driver & Version: MySql

When i try to use the store method from the documentation:
https://laravel.com/docs/5.3/filesystem#file-uploads i got error: Method store does not exist.
Also i've wached this video in laracasts, writing the exact same code: https://laracasts.com/series/whats-new-in-laravel-5-3/episodes/12 and the result is the same.
This is my code:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;
use Illuminate\Support\Facades\Storage;
use Illuminate\Support\Facades\File;
use App\Http\Requests;

class UserController extends Controller {

    protected $validationRules = [
        'avatar' => 'mimes:jpg,png,gif,jpeg'
    ];
    

    public function store(Request $request){

      $validator = Validator::make($request->all(), $this->validationRules);
      if($validator->passes()){
          $path = $request->file('avatar')->store('avatars'); // here is the problem
          dd($path);
      }else{
          dd($validator->messages());
      }
    }
Route::post('/user/store', 'UserController@store');

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions