0

I get the following error from Laravel 4.1.

ReflectionException Class Acme\Services\TaskCreatorService does not exist.

Thanks in advance for any help.

Below is the code defining the class. It is found in app\Acme\Services.


<?php namespace Acme\Services;

use \Acme\Validators\TaskValidator;
use \Acme\Validators\ValidationException;
use \Acme\Validators\Validator;

class TaskCreatorService {

    protected $validator;

    public function __construct(TaskValidator $validator) {

        $this->validator = $validator;

    }

    public function make(array $attributes) {

        //determone whether data is valid
        if ($this->validator->isValid($attributes)) {
        Task::create([
            'title' => $attributes['title'],
            'body' => $attributes['body'],
            'user_id' => $attributes['assign']
         ]);

        return true;
        }

        throw new ValidationException('Task validation failed', $this->validator-getErrors());
        //create the new task
        //
        //if not throw exception
    }
}

I have also add this to composer.json in the autoload section.

    "psr-0": {
        "Acme": "app/"
    }
2
  • Seems like whatever code is trying to use your class isn't configured to autoload that namespace Commented Feb 28, 2014 at 3:57
  • As Antonio says below, while you don't need to do a composer dump-autoload in general when using PSR-0/4, you will need to do it the first time you edit the composer.json file to specify this, just so that Composer actually knows about this PSR rule. Is that the issue here? Commented Feb 28, 2014 at 9:38

2 Answers 2

1

For me, in my case, following did work!

composer dump-autoload

I found it with a little explanation in the following link

Hope it will be helpful!

Laravel is really harder for newbies to catch up with, specially for the people who don't know Symfony or Ruby-on-Rails techniques!

Good Luck guys!

Sign up to request clarification or add additional context in comments.

Comments

0

Having your PSR-0 namespace

"Acme": "app/"

Your class file must be:

/var/www/appdir/app/Acme/Services/TaskCreatorService.php

And you have to

composer dump-autoload

Once, when you created the PSR-0 namespace. Check the file

/var/www/appdir/vendor/composer/autoload_psr0.php

And check if your namespace is there.

1 Comment

Thank you all for the help. I was missing a freaking comma after adding a file in composer.json. Lesson learned to go over my code with a fresh mind!

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.