Support the ongoing development of Laravel.io →
posted 10 years ago
Requests

I have a users controller and i want to trigger my constructor for the dependency injection works but when i request to UsersController@index to show all paginated users the userRepository property returns null meaning the constructor did not initialized..

 protected $userRepository;

    /**
     * @param UserRepository $userRepository
     */
    function _construct(UserRepository $userRepository)
    {
        dd('e');
        $this->userRepository = $userRepository;
    }

	/**
	 * Display a list of registered users.
	 *
	 * @return Response
	 */

	public function index()
	{
           dd($this->userRepository);
           $users = $this->userRepository->getPaginated();
           return View::make('users.index')->withUsers($users);
        }
Last updated 3 years ago.
0

The magic constructor method has a double underscore __construct()

Last updated 3 years ago.
0

WTF!! i didn't see that... thanks man..

Last updated 3 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.

© 2025 Laravel.io - All rights reserved.