簡體   English   中英

錯誤 Class 未找到“App\Models\GateWay”

[英]Error Class 'App\Models\GateWay' not found

你能告訴我為什么你找不到圖書館嗎?

錯誤 Class 未找到“App\Models\GateWay”

在 /var/www/html/demo//var/www/html/demo/core/resources/views/templates/basic/sections/payment.blade.php(第 2 行)

<?php
$payments = App\Models\GateWay::where('status', 1)->latest()->get();
$paymentData = getContent('payment.content', true);
?>

位置正確 /var/www/html/demo/core/app/Models/Gateway.php

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Gateway extends Model
{
    protected $guarded = ['id'];

    protected $casts = ['status' => 'boolean', 'code' => 'string', 'extra' => 'object','input_form'=> 'object'];

    public function currencies()
    {
        return $this->hasMany(GatewayCurrency::class, 'method_code', 'code');
    }

    public function single_currency()
    {
        return $this->hasOne(GatewayCurrency::class, 'method_code', 'code')->latest();
    }

    public function scopeCrypto()
    {
        return $this->crypto == 1 ? 'crypto' : 'fiat';
    }

    public function scopeAutomatic()
    {
        return $this->where('code', '<', 1000);
    }

    public function scopeManual()
    {
        return $this->where('code', '>=', 1000);
    }
}

我看到您傳遞給它的 class 的名稱是GateWay

$payments = App\Models\GateWay::where('status', 1)->latest()->get();

但在 Gateway.php 文件中,class 名稱為Gateway

class Gateway extends Model { ... }

它還會檢查 Gateway.php 文件的位置。 在導入或調用 class 時,我遇到了必須刪除App\的情況。

在 blade 文件中查詢不是好的做法,但如果文件位於正確的位置和命名空間並且 class 名稱正確,那么它應該可以正常工作。 即使它不起作用,請嘗試作曲家自動加載並清除緩存配置視圖和路由。

我已經嘗試過了,它對我有用。

 <?php 
 $payments = App\Models\User::where('id', 1)->get();
  dd($payments);
// $paymentData = getContent('payment.content', true);
?>

因為您在 model class 中使用網關名稱,並且在將其實施到 controller 中時,您使用的是 GateWay。

所以你必須把你的 model class 名字改成 GateWay

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM