Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/laravel/11.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_Php_Laravel_Shell_Ubuntu - Fatal编程技术网

Php 未捕获错误:未找到类-Laravel

Php 未捕获错误:未找到类-Laravel,php,laravel,shell,ubuntu,Php,Laravel,Shell,Ubuntu,当我在处理model类not found错误时,我正在尝试在我的laravel项目中运行脚本 我的模型课位于: App\UserLoginAudit 我这样称呼我的班级: <?php namespace App\Scripts; use App\UserLoginAudit as user_login_audit; use Illuminate\Support\Facades\DB; class UserSignOut { private $currentDate; private

当我在处理model类not found错误时,我正在尝试在我的laravel项目中运行脚本

我的模型课位于:

App\UserLoginAudit

我这样称呼我的班级:

<?php

namespace App\Scripts;

use App\UserLoginAudit as user_login_audit;
use Illuminate\Support\Facades\DB;

class UserSignOut {
private $currentDate;
private $report;
public function __construct() {
    $this->currentDate = date('Y-m-d H:i:s');
    $this->doQuery();
}

private function doQuery () {
    $this->report = new user_login_audit();

    //die(print_r($this->report,true));

    $this->report->select(
        DB::raw('TIMEDIFF(NOW(),user_login_audit.last_accessed) as time_difference'),
        'user.user_id',
        'user_login_audit.ip_address'
    )
    ->join(
        'tutor_times.user',
        'user.user_id',
        '=',
        'user_login_audit.user_id'
    )
    ->whereNull('user_login_audit.time_out_type')
    ->where('last_accessed','<=',$this->currentDate)
    ->get()
    ->toArray();

    die(print_r($this->report,true));

    $this->processQuery();
}

private function processQuery () {
    foreach ($this->report as $record) {
        if ($record['time_difference'] > 5) {
            $lookup = user_login_audit
                ::where('user_id','=',$record['user_id'])
                ->where('ip_address','=',$record['ip_address'])
                ->whereNull('time_out_type')
                ->first();

            if (!empty($lookup)) {
                $lookup->time_out_type = "system";
                $lookup->save();
            }
        }
    }
}
}
$obj = new UserSignOut();
试试这个

 use \App\UserLoginAudit as user_login_audit;
试试这个

 use \App\UserLoginAudit as user_login_audit;

是的,那不行。要使用Laravel类,您需要Laravel的自动加载器


正确的方法是一个。

是的,那不行。要使用Laravel类,您需要Laravel的自动加载器


正确的方法是。

根据文件和类的名称,我可以理解您是手动运行/加载脚本的。 在这种情况下,您不会加载应该为您加载类的作曲家的自动加载器

尝试创建自定义artisan命令并使用
php artisan{commandName}
运行它

有关自定义artisan命令的创建,请参见

****更新****

根据您的需要,使用以下命令(不要忘记注册):


通过文件和类的名称,我可以理解您是手动运行/加载脚本的。 在这种情况下,您不会加载应该为您加载类的作曲家的自动加载器

尝试创建自定义artisan命令并使用
php artisan{commandName}
运行它

有关自定义artisan命令的创建,请参见

****更新****

根据您的需要,使用以下命令(不要忘记注册):



如何运行脚本?如果您直接运行它,自动加载程序将无法注册,PHP将无法找到classSudo PHP文件名。因此,自动加载将无法工作,请查看下面的解决方案。您是如何运行脚本的?如果您直接运行它,自动加载程序将无法注册,PHP将无法找到classSudo PHP文件名。如果自动加载无法工作,请查看下面的解决方案(除非您需要,否则您不应该使用
sudo
。此脚本根本不需要它。)(除非需要,否则不应使用
sudo
。此脚本根本不需要它。)@jomin_george94 UserLoginAudi的命名空间是什么?这是它:namespace App;@jomin_george94 UserLoginAudi的命名空间是什么?这是它:namespace App;需要“../../vendor/autoload.php”;这会有什么区别吗?因为我不太确定如何使用自定义artisan命令?这是编写自定义脚本的正确方法在Laravel中。你可以像@jomin_george94所说的那样添加require行,但将来你可能会遇到更多相关的bug。你能给我举个例子,说明如何创建customer artisan命令,以及如何在这里使用它吗?我知道如何创建custome artisan命令,但这是否意味着我正在使用该类来编写脚本??您可以运行artisan命令,或者使用Laravel调度并定义代码何时在您的代码中运行。require“../../vendor/autoload.php”;这会有什么不同吗?因为我不太确定如何使用自定义artisan命令?这是在Laravel中编写自定义脚本的正确方法。您可以将require行添加为@jomin_george94说,但是你将来可能会面临更多相关的bug。你能给我举个例子,说明如何创建customer artisan命令,以及如何在这里使用它吗?我知道如何创建custome artisan命令,但这是否意味着我使用该类来编写脚本?你可以运行artisan命令,或者使用Laravel scheduling并定义代码在代码中运行的时间。
php artisan user-sign-our