Would you be so kind to explain to me why you can't find the library
Error Class 'App\Models\GateWay' not found
in /var/www/html/demo//var/www/html/demo/core/resources/views/templates/basic/sections/payment.blade.php (line 2)
<?php
$payments = App\Models\GateWay::where('status', 1)->latest()->get();
$paymentData = getContent('payment.content', true);
?>
the location is correct /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);
}
}
CodePudding user response:
It is not good practice to query in blade files, but if the files are in proper locations and namespace and class names are correct then it should work fine. Even if its not working please try composer autoload and clear cache config views and routes.
I have tried this and it worked for me.
<?php
$payments = App\Models\User::where('id', 1)->get();
dd($payments);
// $paymentData = getContent('payment.content', true);
?>
CodePudding user response:
I see that the name of the class you are passing to it is GateWay:
$payments = App\Models\GateWay::where('status', 1)->latest()->get();
But in the Gateway.php file the class name is as Gateway:
class Gateway extends Model { ... }
It also checks the location of the Gateway.php file. It has happened to me that I have to remove App\
when importing or calling the class.
CodePudding user response:
Because you are using Gateway name in your model class and while implementing it into controller, you are using GateWay.
So you have to change your model class name to GateWay