首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >没有找到基表或视图: 1146表'xyz.testimonials‘不存在(SQL: select * from’`testimonials`‘)

没有找到基表或视图: 1146表'xyz.testimonials‘不存在(SQL: select * from’`testimonials`‘)
EN

Stack Overflow用户
提问于 2019-09-06 05:42:56
回答 2查看 929关注 0票数 2

解决了我不是拉勒维尔的专家。刚开始做网络开发。我被要求对我从c Panel下载的一个现有项目进行更改。在服务器上,该项目运行良好。但是在下载之后,我得到了下面的错误,并且不太确定发生了什么。

SQLSTATE42S02:未找到基表或视图: 1146表'xyz.testimonials‘不存在(SQL: select * from testimonials)

下载该项目后,我可以

php手工缓存:清除 作曲家更新 php手工迁移 php手工db:seed

下面的TestimonialController.php文件

代码语言:javascript
复制
<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Testimonial;

class TestimonialController extends Controller
{
    public function index()
    {
        $testimonials = Testimonial::all();
        return view('dashboard.testimonials.index')->withTestimonials($testimonials);
    }

    public function create()
    {
        return view('dashboard.testimonials.create');
    }

    public function store(Request $request)
    {
        $request->validate(['testimonial_text'=>'required']);
        $testimonial = Testimonial::create($request->all());
        if($testimonial)
        {
            $this->success('Testimonial added successfully');
        }
        else
        {
            $this->error();
        }
        return redirect()->back();
    }

    public function edit(Testimonial $testimonial)
    {
        return view('dashboard.testimonials.edit')->withTestimonial($testimonial);
    }

    public function update(Testimonial $testimonial,Request $request)
    {
        if($testimonial->update($request->all()))
        {
            $this->success('Testimonial Updated Successfully');
        }
        else
        {
            $this->error();
        }
        return redirect()->route('dashboard.testimonials.index');
    }

    public function destroy(Testimonial $testimonial)
    {
        if($testimonial->delete())
        {
            $this->success('Testimonial Deleted Successfully');
        }
        else
        {
            $this->error();
        }
        return redirect()->back();
    }
}

Testimonial.php

代码语言:javascript
复制
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Testimonial extends Model
{
    public $guarded = [];

    public function allTestimonials()
    {
        return self::all();
    }
}
EN

回答 2

Stack Overflow用户

回答已采纳

发布于 2019-09-06 05:46:37

确保在您的xyz DB中存在表。如果您已经用另一个名称创建了表,那么就必须在模型中定义它。

比方说,你用了一个桌子的名字作为证明。那么在您的模型中,受保护的字段将是,

代码语言:javascript
复制
class Testimonial extends Model
{
    protected $table = 'testimonial';
}
票数 1
EN

Stack Overflow用户

发布于 2019-09-06 11:16:09

在Laravel中有两种定义表的方法。

  • 模型类名(证明)=单数和表名(证明)=复数,请检查数据库中是否存在testimonials。每当您不将$table定义为模型时,就意味着Laravel自动搜索表。
  • 您必须手动将$table添加到模型文件中,如下所示。当你不在的时候 以复数形式创建表名,如下所示。 protected $table =‘证言’;
票数 2
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/57816313

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档