Use the IOC Container to automagically inject the request class into your controller and access the $_POST and $_GET input as shown below.
Also See: http://programmingarehard.com/2014/01/11/stop-using-facades.html and http://laravel.com/docs/facades#facade-class-reference
<?php
use Illuminate\Http\Request as Request;
class MyController extends BaseController
{
protected $request;
public function __construct(Request $request)
{
$this->request = $request;
}
public function index()
{
// Input::get() - Retrieves combined $_POST and $_GET
$this->request->all();
// Input::get('foo')
$this->request->get('foo');
// $_GET array
$this->request->query->all();
// $_GET['foo']
$this->request->query->get('foo');
// $_POST array
$this->request->request->all();
// $_POST['bar']
$this->request->request->get('bar');
}
}
Dixter said:
Use the IOC Container to automagically inject the request class into your controller and access the $_POST and $_GET input as shown below.
Also See: http://programmingarehard.com/2014/01/11/stop-using-facades.html and http://laravel.com/docs/facades#facade-class-reference
<?php use Illuminate\Http\Request as Request; class MyController extends BaseController { protected $request; public function __construct(Request $request) { $this->request = $request; } public function index() { // Input::get() - Retrieves combined $_POST and $_GET $this->request->all(); // Input::get('foo') $this->request->get('foo'); // $_GET array $this->request->query->all(); // $_GET['foo'] $this->request->query->get('foo'); // $_POST array $this->request->request->all(); // $_POST['bar'] $this->request->request->get('bar'); } }
High.
I see I can use it like this. But I don't see the benefit really. Can you explain please? Thanks
use Acme\Interfaces\MembersInterface as MembersInterface;
use Illuminate\Http\Request as Request;
class MembersController extends \BaseController {
protected $MembersInterface;
public function __construct(MembersInterface $MembersInterface, Request $request)
{
$this->MembersInterface = $MembersInterface;
$this->request = $request;
}
public function index()
{
return View::make('Members.MembersSearch')->with('results', array());
}
public function search()
{
$email = $this->request->get('email');
$results = $this->MembersInterface->search($email);
return View::make('Members.MembersSearch')->with('results', $results);
}
}
The benefit is, you don't have to use the Input facade. Isn't that what you were trying to accomplish?
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community