I created a package in the Laravel 4 workbench and it worked like a charm on my machine. Everything loaded as expected but now on another machine I'm getting the Class not found exception.
What I have:
composer.json (root)
"autoload": {
"classmap": [
"app/commands",
"app/controllers",
"app/models",
"app/database/migrations",
"app/database/seeds",
"app/tests/TestCase.php",
"workbench"
],
"files": [
"app/helpers.php"
]
},
Please note that the workbench directory is listed.
Inside the workbench directory I have the vendor and package folders: workbench/krynble/contenter
Inside is the regular package structure but the most important is that there is another composer.json file (created when the package was generated):
"autoload": {
"classmap": [
"src/migrations"
],
"psr-0": {
"Krynble\\Contenter\\": "src/"
}
},
So inside of it I followed the steps to create the Service Provider cited in the documentation
workbench/krynble/contenter/src/Krynble/Contenter/ContenterSerivceProvider.php (also generated automaticaly) and left it as created, with only the boot method as follows:
public function boot()
{
$this->package('krynble/contenter');
}
register:
public function register()
{
//
}
provides:
public function provides()
{
return array();
}
Added this service provider to my app.php in the providers list and invoking a die() in the boot function shows it's being called.
Last, I created my utility class:
workbench/krynble/contenter/src/Krynble/Contenter/Services/Mappers/MediaMapperSerivce.php
<?
namespace Krynble\Contenter\Services\Mappers;
class MediaMapperService {
...
}
Finally, in my controller:
<?php
use Krynble\Contenter\Services\Mappers\MediaMapperService;
class MediaController extends BaseController {
private $mediaMapperService;
public function __construct(MediaMapperService $mediaMapperService)
{
$this->mediaMapperService = $mediaMapperService;
}
Nice! It worked on my machine (vagrant box with ubuntu)! But on the mac notebook it's not working (so I discarded the case-sensitive thing).
Any clues? Any way to debug? I'm going nuts, thrown die() in every point and can't seem to find the source.
Am I supposed to add something in the provides method in my service provider? If so, why did it work on my machine without adding this?
composer dump-autoload
help? – Unnawut