Laravel 不依赖于物品的 Nova 动作

Laravel Nova action that doesn't depend on items

我有一个来自 IoT 设备的 table,所以我有很多数据。

我想创建一个操作来检查数据是否一致,并且我没有丢失数据,具体取决于 3 个参数。

我的问题是,只有当我 select 至少从资源列表中选择一项时,该操作才会显示。

有没有一种方法无需 select 列表中的项目即可触发操作?

您可以使用 cron 作业来实现此目的。您可以创建一个 Artisan 命令来检查遗漏的项目并将其添加到服务器上的 cron 条目。 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.
    }

之后将此 Artisan 命令添加到计划 App\Console\Command\Kernel.php

$schedule->command('check_missed_items:fire')->daily();

最后将 php artisan schedule:run 添加到服务器上的 cron 条目。

> crontab -e

添加此命令

   * * * * * cd /path-to-your-project && php artisan schedule:run >> /dev/null 2>&1

通过这样做,您的 artisan 命令每天都会在后台运行。

听起来你想要一个 Laravel Nova 独立动作。

查看 https://github.com/gobrightspot/nova-detached-actions