2016-08-31 13:14 阅读 40

无法使用Form Facade在Laravel 5.2中上传图像

I have been struggling to upload an image using a simple form. Every time I upload the file, it says there is no file, as per the functionality I've set up in the controller. Here is the code so far:

The blade form:

 <div class="text-align-center">
    {{Form::open(['url' => 'profile', 'files' => true]) }}
    {{Form::submit('Update',['class' => 'pull-left btn btn-sm btn-primary']) }}
    {{Form::close() }}

The routes file:

Route::get('profile', 'UserController@profile');
Route::post('profile', 'UserController@avatar');

The UserController:

public function profile(){

            return view('profile', array('user' => Auth::user()));

    public function avatar(Request $request){

                die('there is no file here!');

The User model:

protected $fillable = [
        'username', 'email', 'avatar'

My php.ini has maximum file size limits of 8M, the file I'm trying to upload is only a few KB.

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 复制链接分享

1条回答 默认 最新

  • 已采纳
    dongxiao9583 dongxiao9583 2016-09-01 09:17

    I had not cleared the views cache in a long while. This goes to show that the cache could impede new forms from being added. It was still loading the view with two forms, one of which I had already deleted. Once I cleared the view cache with view:clear, and then made a new view with the same code and file name, it was all working then.

    点赞 评论 复制链接分享