I am struggling to set up a working name space in Laravel 4, I've read some guides on here and in the code bright book. But I still can't seem to figure it out. My app is set up as follows:
app/controllers/itemController app/services/itemValidator
in my composer json file (which I dump-autoload evertime it gets changed) I have:
"autoload": {
"classmap": [
<usual data...>
"app/repositories",
"app/services",
],
"psr-0": {
"Services": "app/services/"
}
my items controller is set up as:
<?php
use Services\ItemValidator;
class ItemsController extends BaseController {
public function store()
{
$validator = new ItemValidator;
.....etc.....
and my ItemsValidator class is set up as:
<?php namespace Services;
class ItemValidator extends BaseValidator
{
....code....
Which gives me the following error when it gets to the $validator = new ItemValidator
line:
Class 'Services\ItemValidator' not found
Just to clarify: according to comments, what works in this case is a composer.json formatted this way:
"autoload": {
"classmap": [
<usual data...>
"app/repositories",
"app/services", <---- this is the only entry needed to autoload your services
],
Then you should execute
composer dump-autoload
And check if your class appeared in the file
vendor/composer/autoload_namespaces.php
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With