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

I keep getting this error: "Call to a member function create() on null" in my controller. My $this->forum is null when i diedump it, and i have no idea why or how to fix it. I followed multiple tutorials on repository patterns, but keep ending up the same.

This is my directory structure: app/lib/Repositories/Forum/

My Controller:

<?php

use Repositories\Forum\ForumInterface;

class ForumController extends \BaseController {
    protected $forum;

    public function __constructor(ForumInterface $forum)
    {
        $this->forum = $forum;
    }

    ........

	public function store()
	{
        $input = Input::except('_token');

        $this->forum->create($input);

        return Redirect::route('dashboard');
	}

    .....

}

My Interface:

<?php namespace Repositories\Forum;

interface ForumInterface {

   ....

    public function create($input);

   ....

}

My repository:

<?php namespace Repositories\Forum;

use Forum;

class ForumRepository implements ForumInterface {

     .......

    public function create($input)
    {
        return Forum::create($input);
    }

    ......

}

ServiceProvider:

<?php namespace Repositories\Forum;

use Illuminate\Support\ServiceProvider;

class ForumServiceProvider extends ServiceProvider {

    public function register()
    {
        $this->app->bind(
            'Repositories\Forum\ForumInterface',
            'Repositories\Forum\ForumRepository'
        );
    }

}

What am i missing or doing wrong? Can anyone lead me in the right direction? Would really be appreciated, thank you!

Last updated 3 years ago.
0
Solution

It's __construct not __constructor :)

Last updated 3 years ago.
0

Wauw.. like seriously wauw.. Thank you! I would have overlooked that for days!

Last updated 3 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

lorienhd lorienhd Joined 20 Mar 2014

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.