how can we call controller method from console kernel.php in laravel. I am going to schedule one cron to so in schedule method I have write some code and going to call controller method.
When I am going to call it and run the command sudo php artisan schedule:run It gives me error like
[ReflectionException] Class
App\Http\Controllers\Auth\ReservationController does not exist
Check your namespace. It should be App\Http\Controllers\ReservationController.
Related
In my laravel app, I want to schedule some tasks using the scheduler. In order not to duplicate code, I want to re-use functionality already in some of my Modules. I specifically made one CronModule, that uses some of the other modules for it's job.
In my app/Console/Kernel.php I have this for the schedule function:
protected function schedule(Schedule $schedule)
{
$cronmodule = $this->app->make('App\Dashboard\Modules\CronModule');
$schedule->call(function () {
echo "======yes";
})->everyMinute();
}
The problem that I run into, is that some of my other modules make use of the Illuminate\Support\Facades\Auth Facade, which is aliased in config\app.php to "Auth". I don't actually need the Auth facade to work for any of the functions called by my CronModule. Of course that wouldn't make sense in the scope of CronJobs. But I think the modules for some reason can't find that Facade already when importing it, and so running php artisan schedule:run errors out with
[ErrorException]
Use of undefined constant Auth - assumed 'Auth' (this will throw an Error in a future version of PHP)
I try to make a controller with PHP artisan but when I run command php artisan make:controller TasksController I confront with following error:
In RouteAction.php line 84:
Invalid route action: [App\Http\Controllers\TaskController].
why this error to be occur?
Thanks in Advance.
The error occurs because you're trying to execute TaskController without action. You need to add action to the controller:
Route::get('task', 'TaskController#someAction');
If you don't have a similar route, it means routes are cached with some wrong route. Since Artisan commands do not work, clear this cache manually by deleting this file:
bootstrap/cache/routes.php
I'm using Laravel 5.1.*. Installed defender and created my role 'admin'...But when will using the middleware 'needsRole' (in routes.php) or 'Defender::hasRole('admin')' (in controller) not working.
Message error
BadMethodCallException in Builder.php line 2093:
Call to undefined method Illuminate\Database\Query\Builder::hasRole()
make sure of two things use the trait in your model Artesaos\Defender\Traits\HasDefender and register the service provider then do a composer dump-autoload
When I run php artisan route:list command then i am getting this error
The reason you're getting the error is this piece of code:
Auth::user()->name;
in your CategoryController's constructor.
When you run php artisan route:list, Laravel instantiates all controllers to check, if they declare a middleware - it's usually done in constructor by a call to middleware() method. At this point, there is no user session, therefore Auth::user() won't return anything, that's why you're getting an error trying to access name property on non-object.
You shouldn't access user object in the constructor, do that in action methods.
In Laravel 5, I just ran php artisan make:command doMagicStuff to create a generic command with a die() statement in the handler. Whenever I try to `$this->dispatch(new DoMagicStuff()), however, I get:
[Symfony\Component\Debug\Exception\FatalErrorException]
Class 'App\Commands\Command' not found
If I remove extends Command it works, though obviously not correctly.
Is there some reason it can't find App\Commands\Command ? (Note: In ./app/Commands, there is no Command.php, so that is a hint, though it might live under the vendor directory. I did a grep for "class Command", but no luck.
Did you clone the repo from github? The repository there has a Command.php with nothing in it, just empty abstract. My projects also have it, so... weird.
Here: https://github.com/laravel/laravel/tree/5.0/app/Commands
Whenever you create a command, it is namespaced as namespace App\Commands; and you extends Command, so it will look in the App\Commands dir for a Command class, since it exists in the repo, it should exist in your copy too.