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!
It's __construct not __constructor :)
Wauw.. like seriously wauw.. Thank you! I would have overlooked that for days!
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community