Problem: class PostRepostioryInterface not found for line 4 in PostController.php or as for namespace, I even got the class Application \ Models \ Interfaces \ PostRepositoryInterface not found
Questions: How to register namespace in laravel 4? What do I need to do for L4 to recognize classes / interfaces in this namespace?
Larave 3 had a static namespaces object in ClassLoader where you could add namespaces
Autoloader::namespaces(array( 'App\Models\Interfaces' => path('app').'models/interfaces', ));
I'm not sure I have this right for laravel 3, but in any case, AutoLoader does not exist in Laravel 4 and ClassLoader does exist, but the method namespace does not exist in ClassLoader in Laravel 4.
I looked at this, but it does not work without registering the namespace. Using namespaces in Laravel 4
Structure example:
app/models/interfaces PostRepostitoryInterface.php app/models/repositories EloquentPostRepository.php namespaces: App\Models\Repositories; App\Models\Interfaces;
files:
PostRepositoryInterface.php
<?php namespace App\Models\Interfaces; interface PostRepositoryInterface { public function all(); public function find($id); public function store($data); }
EloquentPostRepository.php
<?php namespace App\Models\Repositories; use App\Models\Interfaces\PostRepositoryInterface; class EloquentPostRepository implements PostRepositoryInterface { public function all() { return Post::all(); } public function find($id) { return Post::find($id); } public function store($data) { return Post::save($data); } }
PostController.php
<?php use App\Models\Interfaces\PostRepositoryInterface; class PostsController extends BaseController { public function __construct( PostRepositoryInterface $posts ) { $this->posts = $posts; }
thanks
source share