Laravel 5 "Class does not exist" when using scheduler

I am trying to use the scheduler for the first time to call a method:

protected function schedule(Schedule $schedule)
    {   
        $schedule->call('MyClassName@myMethodName')
            ->everyMinute();
    }

      

The class I'm calling is defined App/Http/Controller

like this:

namespace App\Http\Controllers;

use App\Http\Requests;
use App\Models\Reaction;
use View;
use Request;

class MyClassNameController extends Controller {

      

But every time the scheduler starts, it gets:

  [ReflectionException]
  Class MyClassName does not exist

      

How can I fix this?

+2


source to share


1 answer


You shouldn't call controller methods this way. Controller methods are designed to handle HTTP requests.

The content myMethodName

should be output to the command. You can learn about creating teams here .

As an aside, the reason you are getting ReflectionException

is because the exception is specified: is MyClassName

not a valid class.

$schedule->call('App\Http\Controllers\MyClassNameController@myMethodName')

      



The description above indicates the fully qualified name of the class you are trying to access. You can also import this class at the top of the file and usejoin

use App\Http\Controllers\MyClassNameController;

// ...

$schedule->call(join('@', [ MyClassNameController::class, 'myMethodName ]))

      

But again , you shouldn't call controller methods this way .

+8


source







All Articles