gpt4 book ai didi

php - 找不到基表或 View : 1146 Table 'xyz.testimonials' doesn't exist (SQL: select * from `testimonials` )

转载 作者:行者123 更新时间:2023-11-29 02:09:20 25 4
gpt4 key购买 nike

[已解决] 我不是 Laravel 专家。刚开始做网页开发。我被要求对从 c 面板下载的现有项目进行更改。在服务器上,该项目运行良好。但是在下载它之后,我收到以下错误并且不太确定发生了什么。

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'xyz.testimonials' doesn't exist (SQL: select * from testimonials)

下载项目后我可以进行以下操作

php artisan cache:clear

composer update

php artisan migrate

php artisan db:seed

下面是TestimonialController.php文件

<?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();
}
}

客户评价.php

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

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

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

最佳答案

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

  • 模型类名称(证明)= 单数和表格name(testimonials) = plural , 请检查 testimonials在您的数据库中是否可用。每当你不定义$table 放入模型中,表示Laravel自动搜索表。
  • 您必须手动将 $table 添加到模型文件中,如下所示。当你不在的时候
    按照以下第一条规则以复数形式创建表名。

    protected $table = 'testimonial';

关于php - 找不到基表或 View : 1146 Table 'xyz.testimonials' doesn't exist (SQL: select * from `testimonials` ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57816313/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com