解决了我不是拉勒维尔的专家。刚开始做网络开发。我被要求对我从c Panel下载的一个现有项目进行更改。在服务器上,该项目运行良好。但是在下载之后,我得到了下面的错误,并且不太确定发生了什么。
SQLSTATE42S02:未找到基表或视图: 1146表'xyz.testimonials‘不存在(SQL: select * from
testimonials)
下载该项目后,我可以
php手工缓存:清除 作曲家更新 php手工迁移 php手工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();
}
}Testimonial.php
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class Testimonial extends Model
{
public $guarded = [];
public function allTestimonials()
{
return self::all();
}
}发布于 2019-09-06 05:46:37
确保在您的xyz DB中存在表。如果您已经用另一个名称创建了表,那么就必须在模型中定义它。
比方说,你用了一个桌子的名字作为证明。那么在您的模型中,受保护的字段将是,
class Testimonial extends Model
{
protected $table = 'testimonial';
}发布于 2019-09-06 11:16:09
在Laravel中有两种定义表的方法。
testimonials。每当您不将$table定义为模型时,就意味着Laravel自动搜索表。$table添加到模型文件中,如下所示。当你不在的时候
以复数形式创建表名,如下所示。
protected $table =‘证言’;https://stackoverflow.com/questions/57816313
复制相似问题