【问题标题】:Problem of Class not found on Laravel for a form在 Laravel 上找不到表格的类问题
【发布时间】:2019-01-10 20:57:00
【问题描述】:

我尝试按照本教程在 Laravel 上进行工作:https://vegibit.com/how-to-set-up-form-submission-in-laravel/ 但我遇到了一个奇怪的错误,我找不到修复它的方法,我想制作一个表单来在我的数据库中插入一些东西,然后在另一个页面显示它(显示是正确的,它只是出现这个问题的表单页面)这是一个截图:

代码:

namespace Doreas\Http\Controllers;

use Illuminate\Http\Request;
use App\Demand;
class DemandeController extends Controller
{
    public function index()
    {
        $demande = Demand::all();
        return view('demande.index', ['demande' => $demande]);
    }

    public function show($id)
    {
        $demande = Demande::find($id);
        return view('demande.show', ['demande' => $demande]);
    }

    public function create()
    {
        return 'it works';
    }
}

不明白Demand的问题从何而来

<?php

namespace App\Doreas;

use Illuminate\Database\Eloquent\Model;

class Demand extends Model
{
    public function scopeTest($query)
    {
        return $query->where('title', '=', 'test');
    }
}

我在哪里声明类

【问题讨论】:

  • 请在问题中复制粘贴您的代码,带有代码的屏幕截图不是获得帮助的最佳方式
  • 你也可以包括声明类Demand的文件的代码吗?

标签: php laravel class crud


【解决方案1】:

问题是您使用use App\Demand; 导入了Demand

但是它的命名空间实际上是App\Doreas 所以你应该做use App\Doreas\Demand;

【讨论】:

  • 遗憾的是问题还是一样,即使使用namespace App\Doreas\Demand;namespace Doreas\Demand;,它仍然显示"Class 'App\Demand' not found"
  • @JorgeSalomon 我不是要更改类的命名空间,而是要更改 import。所以在DemandeController所在的同一个文件中,将use App\Demand;更改为use App\Doreas\Demand;
  • 我改成Class 'Doreas\Demand' not found,因为使用应用程序它不起作用,现在我收到另一个错误SQLSTATE[42S02]: Base table or view not found: 1146 Table 'laravel_app.demands' doesn't exist (SQL: select * from demands),但这意味着这个问题已经解决:D
  • 这是另一种问题 :) 看起来您的数据库没有表 laravel_app.demands
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-03-20
  • 2020-03-31
  • 2014-10-03
  • 2015-09-07
  • 2020-07-10
相关资源
最近更新 更多