I am just starting to learn Laravel and started with the basics on Laracast. In this episode 13 it shows howto inject the User
model into the UserController
with the use of the constructor.
But when I try to inject the View
and Input
model using the same technique I run into some errors like:
Symfony \ Component \ Debug \ Exception \ FatalErrorException (E_ERROR)
Call to undefined method Illuminate\Support\Facades\View::make()
Symfony \ Component \ Debug \ Exception \ FatalErrorException (E_ERROR)
Call to undefined method Illuminate\Support\Facades\Input::all()
When I inject the Redirect
model it just works like the User
model. Could somebody explain to me why View
and Input
don't work? And howto fix this?
UserController:
NOTE: I commented the lines out that didn't work and threw the errors, the lines like $this->view->make();
class UserController extends \BaseController {
protected $user, $redirect, $view, $input;
public function __construct(User $user, Redirect $redirect, View $view, Input $input)
{
$this->user = $user;
$this->redirect = $redirect;
$this->view = $view;
$this->input = $input;
}
/**
* Display a listing of the resource.
*
* @return Response
*/
public function index()
{
$users = $this->user->all();
return View::make('users.index', ['users' => $users]);
// TODO: Why does below not work?
// return $this->view->make('users.index', ['users' => $users]);
}
/**
* Show the form for creating a net
* @return Response
*/
public function create()
{
return View::make('users.create');
// TODO: Why does below not work?
// return $this->view->make('users.create');
}
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function store()
{
$input = Input::all();
// TODO: Why does below not work?
// $input = $this->input->all();
if ( ! $this->user->fill($input)->isValid() )
{
return $this->redirect->back()->withInput()->withErrors($this->user->errors);
}
$this->user->save();
return $this->redirect->route('users.index');
}
/**
* Display the specified resource.
*
* @param int $id
* @return Response
*/
public function show($id)
{
$user = $this->user->find($id);
return View::make('users.show', ['user' => $user]);
// TODO: Why does below not work?
// return $this->view->make('users.show', ['user' => $user]);
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
* @return Response
*/
public function edit($id)
{
//
}
/**
* Update the specified resource in storage.
*
* @param int $id
* @return Response
*/
public function update($id)
{
//
}
/**
* Remove the specified resource from storage.
*
* @param int $id
* @return Response
*/
public function destroy($id)
{
//
}
}