Reputation: 19695
I have a table that comes from IoT device, so I have a lot of data.
I want to create an action to check that data is consistent and that I have no missing data depending on 3 params.
My problem is the action is only showing when I select at least 1 item from resource list.
Is there a way to trigger an action without having to select items from the list ?
Upvotes: 0
Views: 1557
Reputation: 26
Sounds like you want a Laravel Nova Detached Action.
Check out https://github.com/gobrightspot/nova-detached-actions
Upvotes: 1
Reputation: 1188
You can use cron job to accomplish this purpose. You can create an Artisan command to check missed items and add it to cron entry on the server. Please check this documentation.
<?php
namespace App\Console\Commands\CheckMissedItems;
use Illuminate\Console\Command;
use \DB;
class CheckMissedItems extends Command
{
/**
* The name and signature of the console command.
*
* @var string
*/
protected $signature = 'check_missed_items:fire';
/**
* The console command description.
*
* @var string
*/
protected $description = 'Command description';
/**
* Create a new command instance.
*
* @return void
*/
public function __construct()
{
parent::__construct();
}
/**
* Execute the console command.
*
* @return mixed
*/
public function handle()
{
$missingItems = DB::table("test")->where("status", false)->count();
if($missingItems) {
// TODO what you need.
}
// TODO what you need.
}
After that add this Artisan command to schedule App\Console\Command\Kernel.php
$schedule->command('check_missed_items:fire')->daily();
Finally add php artisan schedule:run
to cron entry on the server.
> crontab -e
Add this command
* * * * * cd /path-to-your-project && php artisan schedule:run >> /dev/null 2>&1
By doing this, your artisan command runs daily in background.
Upvotes: 1