Can't run created command on Laravel Scheduler locally - laravel

I'm trying to run created command locally, but when hitting php artisan schedule:work it shows no sceduled commands are ready to run. What's wrong?
My Kernel:
protected $commands = [
'App\Console\Commands\AddEntry',
];
protected function schedule(Schedule $schedule)
{
$schedule->command('add:entry')->everyMinute();
}
I also edited AppServiceProvider
public function boot()
{
//
Schema::defaultStringLength(191);
}
Command itself is working and it's visible on php artisan list

Related

How to run task scheduler locally on Laravel 7?

I want to learn how to use task scheduler in Laravel 7
According to the documentation, I created a task that should send out a test message to the mail on Mondays at 16:00. Judging by the documentation for local development, there is no need to add a cron entry. I just run the command php artisan schedule:work get this error Command "schedule:work" is not defined. Where am I making a mistake?
protected function schedule(Schedule $schedule)
{
$schedule->call(function () {
$test = 'test';
$email = Emails::where('id', 1)->first();
Mail::to($email)->send(new TestMail($test));
})->mondays()->at('16:00');
}
After I tried to add the line * * * * * cd /public_html/my_project && php artisan schedule:run >> /dev/null 2>&1 but got the following message bash: README_CI.md: command not found
you can try this
protected function schedule(Schedule $schedule)
{
$schedule->command('demo:cron')
->everyMinute();
}
you have cd /your/path. better do php /public_html/my_project/artisan schedule:run as cd'ing in cronjob does not work unless you have a bash script instead of inline.
as for schedule:work, that commmand should exist, does artisan (without arguments produce a list of options including schedule:work?

Error trying to execute a customized command for running migrations

I am trying to create a command to perform all the migrations I have at once but in a way that assigns each of them to a different batch.
As a first attempt, the command I have created contains:
class CreateDBStructure extends Command {
protected $signature = 'database:create';
...
public function handle(){
$this->call('migrate', [
'--path' => 'database/migrations/2021_01_01_create_roles_table.php',
'name' => 'CreateRolesTable'
]);
}
}
In kernel:
protected $commands = [
'App\Console\Commands\CreateDBStructure',
];
And the migration class name:
class CreateRolesTable extends Migration {
...
}
I am getting the following error:
php artisan database:create
The "name" argument does not exist.
I don't quite understand why I'm getting this error. Please, could you help me?
php artisan cache:clear, composer dump-autoload and other similar commands didn't work.
Thank you very much in advance.

How can I run scheduler every one minute in Laravel without setting cron job?

I want to run the scheduler in every minute on the server without setting the cron job with ssh .Please let me know Is there any way to do this ?
Thanks
Assumption: you have set cron job to your project directory
Create a command using
php artisan make:command CommandName
add your logic under handle function
public function handle()
{
//add your logic here
}
register your command under Kernel.php under $commands array
protected $commands = [
Commands\Test::class,
];
schedule command under
protected function schedule(Schedule $schedule)
{
$schedule->command('command:name')->everyMinute();
}

Laravel Testing - How to run command with RefreshDatabase with seed

in Laravel I need to run MY CUSTOM COMMAND after refreshdatabase and db:seed
new database
migration
seed
MY COMMAND
this test finish successfully when i run all these steps manually
I write this test code.
class ExampleTest extends TestCase
{
use RefreshDatabase;
public function testDbSeed()
{
Artisan::call('db:seed');
$resultAsText = Artisan::output();
$this->assertTrue(true);
}
all tables deleted and then run all my migrations successfully.
My question is How to run my CUSTOM command after seed?
php artisan permission:sync
public function testPermissionSync()
{
Artisan::call('permission:sync');
$resultAsText = Artisan::output();
$this->assertTrue(true);
}
after this command we can open main page in ourlocalsite.local/
/**
* A basic test example.
*
* #return void
*/
public function testBasicTest()
{
$response = $this->get('/');
$response->assertStatus(200);
}
but this test not passed and assert error is 403
(when i do these steps manually this command run)
you can use setUp() method that triggered before any test begins.
but don not forget to call the parent setup
public function setUp(): void
{
parent::setUp();
Artisan::call('db:seed');
}
there is also tearDown() function that triggered after test ended

Laravel 5.5 Package Commands Won't Register

I have a package for Laravel 5.5 and in the CommandsServiceProvider boot() method, I have:
if($this->app->runningInConsole()){
$this->commands([
MyCommandClass:class,
]);
}
Then, my MyCommandClass looks like:
<?php
namespace Testing\Commands;
use Illuminate\Console\Command;
class MyCommandClass extends Command
{
protected $signature = "execute:test";
protected $description = "Description of the command";
public function __construct()
{
parent::__construct();
}
public function handle()
{
$this->info('Command Executed');
}
}
The issue is that Artisan does not list the command when I run php artisan and when I try to run the command with php artisan execute:test it tells me the command is not defined.
What am I missing here? I followed the documentation for registering package commands in Laravel 5.5
It would appear that the Auto discovery only works when pulling a package from a Git Repo via Composer. When developing a package, the composer files within the package do not seem to auto load.

Resources