简体   繁体   中英

Upload file Laravel 5 registration

I am trying to use the built in registration of Laravel 5 to upload a photo for each user.

I have made the changes that i needed in:

  • views/auth/register.blade.php
  • app/User.php
  • app/services/Registrar.php

And registration works fine.

But when I try to add the file upload logic, my problem is in Registrar.php.

I have added:

use Illuminate\Http\Request;

but in the create method using:

Request::hasFile()

returns an error of can't use as static.

use dependancy injection.

use Illuminate\Http\Request;

class FooController extends Controller {

    public function __construct(Request $request)
    {
        $this->request = $request;
    }

    public function bar()
    {
        dd($this->request->hasFile('key'));
    }

}

With laravel 5.* please comment the first line and use the second line.

line 1 : //use Illuminate\\Http\\Request;

line 2 : use Request;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM