DBに登録している情報を表示したく、何かアドバイスをいただければと思います。phpMyAdminにてテーブルが存在していることは確認できるのですが、テーブルがないとエラーが発生しているものです。
テーブル(phpMyAdmin)
エラー内容
Illuminate\Database\QueryException SQLSTATE[42S02]: Base table or view not found: 1146 Table 'sample1.employees' doesn't exist (SQL: select * from `employees` order by `id` desc)
web.php
<?php Route::get('/', function () { return view('index'); }); Auth::routes(); Route::get('index', 'HomeController@index')->name('index'); Route::group(['middleware' => 'auth'], function () { Route::resource('goods', 'GoodsController', ['only' => ['create', 'store', 'destroy']]); Route::resource('index', 'EmployeesController', ['only' => ['index']]); });
EmployeesContrller.php
namespace App\Http\Controllers; use Illuminate\Http\Request; use App\Employee; class EmployeesController extends Controller { public function index() { $employees = Employee::orderBy('id','desc')->get(); return view('index', ['employees' => $employees, ]); } }
Employee.php
<?php namespace App; use IlluminateSupportFacadesDB; use Illuminate\Database\Eloquent\Model; class Employee extends Model { protected $fillable = ['id','emlpoyee_id','employee_name']; public function employees() { return $this->hasMany(Goods::class); } }
index.blade.php
@extends('layouts.app') @section('content') <table class="table table-hover"> <thead class="thead-dark"> <tr> <th scope="col">社員番号</th> <th scope="col">氏名</th> <th scope="col" colspan="4">貸与品</th> </tr> </thead> <tbody> @foreach($employees as $employee) <tr> <td scope="row">{{ $employee->employee_id }}</td> <td scope="row">{{ $employee->employee_name }}</td> </tr> @endforeach </tbody> </table> @endsection
route:list
回答1件
あなたの回答
tips
プレビュー