我不是 Laravel 的專家。剛開始做web開發。我被要求對從 c Panel 下載的現有項目進行更改。在服務器上,該項目運行良好。但是下載后我收到以下錯誤并且不太確定發生了什么。SQLSTATE[42S02]:未找到基表或視圖:1146 表 'xyz.testimonials' 不存在(SQL:select * from testimonials)下載項目后,我可以進行以下操作php artisan 緩存:清除作曲家更新php工匠遷移php工匠數據庫:種子下面的TestimonialController.php文件<?phpnamespace 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<?phpnamespace App;use Illuminate\Database\Eloquent\Model;class Testimonial extends Model{ public $guarded = []; public function allTestimonials() { return self::all(); }}
2 回答

小怪獸愛吃肉
TA貢獻1852條經驗 獲得超1個贊
Laravel 中有兩種表定義方式。
模型類名 (testimonial) = 單數和表名 (testimonials) = 復數,請檢查
testimonials
您的數據庫中是否可用。每當你沒有定義$table
到模型中時,就意味著 Laravel 自動搜索表。您必須手動添加
$table
到模型文件中,如下所示。每當您不
按照第一條規則以復數形式創建表名時。受保護的 $table = '推薦';

皈依舞
TA貢獻1851條經驗 獲得超3個贊
確保您的xyz數據庫中存在推薦表。如果您使用另一個名稱創建了表,那么您必須在模型中定義它。
比方說,您已將表名作為證明。然后在您的模型中,受保護的字段將是,
class Testimonial extends Model
{
protected $table = 'testimonial';
}
- 2 回答
- 0 關注
- 592 瀏覽
添加回答
舉報
0/150
提交
取消