Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/276.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php laravel 5.4自定义命令不工作_Php_Cron_Laravel 5.4_Add Custom Command - Fatal编程技术网

Php laravel 5.4自定义命令不工作

Php laravel 5.4自定义命令不工作,php,cron,laravel-5.4,add-custom-command,Php,Cron,Laravel 5.4,Add Custom Command,这是我第一次在拉威尔工作。我正在开发一个自定义命令,它将读取文件并在数据库中插入行。我有错误。以下是我的代码,如有任何帮助,将不胜感激 命令文件。 namespace App\Console\Commands; use Illuminate\Console\Command; use Illuminate\Database\Eloquent\Model; use App\Ship; //use DB; class shipdata extends Command { protecte

这是我第一次在拉威尔工作。我正在开发一个自定义命令,它将读取文件并在数据库中插入行。我有错误。以下是我的代码,如有任何帮助,将不胜感激

命令文件。
namespace App\Console\Commands;

use Illuminate\Console\Command;
use Illuminate\Database\Eloquent\Model;

use App\Ship;
//use DB;

class shipdata extends Command
{
    protected $signature = 'ship:start';

    protected $description = 'This Command will Read file and Extract data from it and will store data in database';

    public function __construct()
    {
        parent::__construct();

    }

    public function handle()
    {
//            $this->line('Query Working');
        ShipNow::ShipNow();
    }
}
模型文件

    public function ShipNow()
    {

            $dir = "d:/xampp/htdocs/lara12/IN/";
            $failed_dir = "d:/xampp/htdocs/lara12/FAILED/";
            $processed_dir = "d:/xampp/htdocs/lara12/PROCESSED/";
            $files = array();

            // Get all files which need to process
                foreach (glob($dir."*.SHIP") as $file) {
                $files[] = $file;
                }

            // If .SHIP files available in the folder then start processing
        if(count($files) > 0)
        {

            // Start processing file
            foreach($files as $file)
            {
                $row = 1;
                $file_name = $file;

                // Get file name without extension
                $withoutExt = preg_replace('/\\.[^.\\s]{3,4}$/', '', $file_name);

                // Generate new filename with extension PROC
                $rename_filename = $withoutExt.".PROC";

                // Rename filename
                $file_proc = rename($file_name, $rename_filename);

                // File processing
                $error = 0;
                if (($handle = fopen($rename_filename, "r")) !== FALSE) {
                    while (($data = fgetcsv($handle, 1000, "|")) !== FALSE) {

                        $num = count($data);
                        // For header table insert
                        if($row==1)
                        {
                            $myparams['warehouse'] = $data[0];
                            $myparams['SHIPMENT_ID'] = $data[1];
                            $myparams['COMPANY'] = $data[2];
                            $myparams['CARRIER'] = $data[3];
                            $myparams['CARRIER_SERVICE'] = $data[4];
                            $myparams['CUSTOMER'] = $data[5];
                            $myparams['CUSTOMER_NAME'] = $data[6];
                            $myparams['SHIP_TO_NAME'] = $data[7];
                            $myparams['SHIP_TO_ADDRESS1'] = $data[8];
                            $myparams['SHIP_TO_ADDRESS2'] = $data[9];
                            $myparams['SHIP_TO_ADDRESS3'] = $data[10];
                            $myparams['SHIP_TO_CITY'] = $data[11];
                            $myparams['SHIP_TO_COUNTRY'] = $data[12];
                            $myparams['SHIP_TO_POSTAL_CODE'] = $data[13];
                            $myparams['SHIP_TO_ATTENTION_TO'] = $data[14];
                            $myparams['SHIP_TO_PHONE_NUM'] = $data[15];
                            $myparams['SHIP_TO_EMAIL_ADDRESS'] = $data[16];
                            $myparams = save();

                           /* $sql = "exec dbo.Portal_3PL_ShipmentEntry_Header '".$myparams['SHIPMENT_ID']."','".$myparams['COMPANY']."','".$myparams['CARRIER']."','".$myparams['CARRIER_SERVICE']."','".$myparams['CUSTOMER']."','".$myparams['CUSTOMER_NAME']."','".$myparams['SHIP_TO_NAME']."','".$myparams['SHIP_TO_ADDRESS1']."','".$myparams['SHIP_TO_ADDRESS2']."','".$myparams['SHIP_TO_ADDRESS3']."','".$myparams['SHIP_TO_CITY']."','".$myparams['SHIP_TO_COUNTRY']."','".$myparams['SHIP_TO_POSTAL_CODE']."','".$myparams['SHIP_TO_ATTENTION_TO']."','".$myparams['SHIP_TO_PHONE_NUM']."','".$myparams['SHIP_TO_EMAIL_ADDRESS']."'";
                            $sql_result = odbc_exec($conn, $sql);
                            if (odbc_error())
                            {
                                echo odbc_errormsg($conn);
                                $error = 1;

                            }
                            $ERP_ORDER_LINE_NUM = 1;
                            $shipment_header = odbc_fetch_array($sql_result);*/
                        }
                        // For shipment detail
                        else
//                        {
//                            $ITEM = $data[1];
//                            $QUANTITY = intval($data[2]);
//                            $INTERNAL_SHIPMENT_NUM = $shipment_header['INTERNAL_SHIPMENT_NUM'];
//
//                            $query2 = "exec dbo.Portal_3PL_ShipmentEntry_Detail '".$INTERNAL_SHIPMENT_NUM."','".$myparams['COMPANY']."',".$ERP_ORDER_LINE_NUM.",'".$ITEM."','".$QUANTITY."',NULL,'N'";
//                            echo $query2.PHP_EOL;
//                            $query_result2 = odbc_exec($conn, $query2);
//                            if (odbc_error())
//                            {
//                                echo odbc_errormsg($conn);
//                                $error = 1;
//
//                            }else{
//                                $ERP_ORDER_LINE_NUM++;
//                            }
//                            $shipment_detail = odbc_fetch_array($query_result2);
//
//                            echo trim($shipment_detail['Result'])."@".trim($shipment_detail['Comment'])."@".trim($shipment_detail['INTERNAL_SHIPMENT_LINE_NUM']);
//                        }
                        $row++;
                    }


                    if($error == 1)
                    {
                        $failed_file = "FAILED/".basename($withoutExt).".FAIL";
                        $file_to_move = "IN/".basename($rename_filename);

                        fclose($handle);
                        rename($file_to_move, $failed_file);

//                        $sql = "INSERT INTO qcimportlog (filename, recordprocess, status) VALUES
//                                                                        ('$file_name', '$row', 'failed')";

//                        $result = mysql_query($sql) or die(mysql_error());

                    }
                    else
                    {
                        $processed_file = "PROCESSED/".basename($rename_filename);
                        $file_to_move = "IN/".basename($rename_filename);
                        echo $processed_file;

                        fclose($handle);
                        rename($file_to_move, $processed_file);

//                        $sql = "INSERT INTO qcimportlog (filename, recordprocess, status) VALUES
//                                                                        ('$file_name', '$row', 'success')";

//                        $result = mysql_query($sql) or die(mysql_error());
                    }
                }

            }
        }
                else
                {
                    echo "No files to process";
                }

    }
Php

    protected $commands = [
         Commands\QuizStart::class,
         Commands\SendWelcomeEmailCommand::class,
        Commands\shipdata::class,

    ];
错误:
D:\xampp\htdocs\lara12>php artisan发布:开始 PHP致命错误:在第26行的D:\xampp\htdocs\lara12\App\Console\Commands\shipdata.PHP中找不到类“App\Console\Commands\ShipNow”

[Symfony\Component\Debug\Exception\FatalErrorException] 找不到类“App\Console\Commands\ShipNow”

ShipNow::ShipNow()
应该是
Ship::ShipNow()
,因为这是模型的名称,您将其称为静态方法,所以它必须是Ship文件中的静态方法:

public static function ShipNow()
{
...

您会遇到什么错误?D:\xampp\htdocs\lara12>php artisan ship:start php致命错误:在第26行[Symfony\Component\Debug\Exception\FatalErrorException]的D:\xampp\htdocs\lara12\App\Console\Commands\shipdata.php中找不到类“App\Console\Commands\ShipNow”类“App\Console\Commands\ShipNow”未找到您必须导入ShipNow类而不是Ship。@JuhG ShipNow是一个函数名,model的类名为Ship@rameez.hashmi那么可能是输入错误:
ShipNow::ShipNow()应该是
Ship::ShipNow()