mfadel's avatar

Error when uploading a file Call to undefined method Illuminate\Support\Facades\Request::file()

Hello everybody,

I am trying to upload a file using $request->file('image') I have posted the code of the function and uses below, when I execute http://localhost:8000/mobile/create and then add my data and submit it goes to http://localhost:8000/mobile and I get this error FatalErrorException in MobileController.php line 48: Call to undefined method Illuminate\Support\Facades\Request::file()

How can I make the upload file functionality??? Any help?

use App\Http\Requests;

use App\Http\Controllers\Controller;

use Illuminate\Support\Facades\Request;

use App\Mobile;

//use Request;

class MobileController extends Controller {

public function store(Request $request)

{

    $mobile = Request::all();

    $Mob = Mobile::create($mobile);

    $imageName = $Mob->id.'.'.$request->file('image')->getClientOriginalExtension();

    $request->file('image')->move(base_path().'/public/images/devices/',$imageName);

    return redirect('mobile');
}

}

0 likes
4 replies
d3xt3r's avatar

Import proper class.

//use Illuminate\Support\Facades\Request; // is not what  you require instead use
use Illuminate\Http\Request;
1 like
mfadel's avatar

thanks d3xt3r,

now I have a problem I can't use $mobile = Request::all(); in this line it will show this message,

Non-static method Illuminate\Http\Request::all() should not be called statically, assuming $this from incompatible context

d3xt3r's avatar
d3xt3r
Best Answer
Level 29
public function store(Request $request)

{

    $mobile = $request->all();

    $Mob = Mobile::create($mobile);

    $imageName = $Mob->id.'.'.$request->file('image')->getClientOriginalExtension();

    $request->file('image')->move(base_path().'/public/images/devices/',$imageName);

    return redirect('mobile');
}
mfadel's avatar

thanks very much it is solved now

Please or to participate in this conversation.