[已解决] 我不是 Laravel 的专业人士。刚刚开始网络开发。我被要求对从 c Panel 下载的现有项目进行更改。在服务器上,该项目运行良好。但下载后我收到以下错误,不太确定发生了什么。
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) = 复数,请检查
testimonials
在您的数据库中是否可用。每当你没有定义时$table
到 model 中,表示 Laravel 自动搜索 table。 您必须手动将
$table
添加到模型文件中,如下所示。每当你不在的时候
按照第一条规则创建复数形式的表名。protected $table = 'testimonial';
关于php - 未找到基表或 View : 1146 Table 'xyz.testimonials' doesn't exist (SQL: select * from `testimonials` ),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57816313/