Skip to content
This repository was archived by the owner on Jun 16, 2025. It is now read-only.

Controller

CrixuAMG edited this page Mar 11, 2018 · 2 revisions

Within your controller, add the following, and replace ExampleContract with the name of your contract (for example, UserContract).

use App\Contracts\ExampleContract;

class ExampleController extends Controller
{
	private $repository;

	public function __construct(ExampleContract$repository)
	{
		$this->repository = $repository;
	}

	public function index()
	{
		// Retrieve the users
		$users = $this->repository->index(request()->input('page') ?? 1);
		// Return the resource collection
		return response()->json(['users' => $users]);
	}
}

Using the repository property within the controller now redirects your data through your defined decorators!

Clone this wiki locally