我想在我的laravel項目中運行腳本時,遇到模型類未找到錯誤的困難。未捕獲的錯誤:類未找到 - 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();
我錯過了什麼東西出來?請有人可以幫助我這個問題
當我運行該腳本,這是錯誤我得到:
未捕獲的錯誤:類「應用程序\ UserLoginAudit」在/ home /公/ TutorTimes /應用/腳本未找到/user_sign_out.php:17
你如何運行腳本?如果你直接運行它,自動加載器將不會被註冊,並且PHP將無法找到類 – Idob
Sudo php php文件名 –
所以自動加載將不起作用,在我的解決方案下采取戰利品 – Idob