Laravel 5 “Class does not exist” when using the scheduler

前端 未结 1 1978

I\'m trying to use the scheduler for the first time to call a method:

protected function schedule(Schedule $schedule)
    {   
        $schedule->call(\'M         


        
相关标签:
1条回答
  • 2021-01-14 21:24

    You should not call controller methods this way. Controller methods are meant for handling HTTP requests.

    The content of myMethodName should be pulled out into a command. You can learn about creating commands here.

    That aside, the reason you're getting the ReflectionException is because of the exact reason the exception states: MyClassName is not a valid class.

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

    The above specifies the Fully Qualified Name of the class you are trying to refer to. You could alternatively import that class at the top of your file and use a join

    use App\Http\Controllers\MyClassNameController;
    
    // ...
    
    $schedule->call(join('@', [ MyClassNameController::class, 'myMethodName ]))
    

    But again, you should not be calling controller methods this way.

    0 讨论(0)
提交回复
热议问题