Support the ongoing development of Laravel.io →
Architecture
Last updated 2 years ago.
0

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');
	}
	
}
Last updated 2 years ago.
0

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);
	}
}


Last updated 2 years ago.
0

The benefit is, you don't have to use the Input facade. Isn't that what you were trying to accomplish?

Last updated 2 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.