### 前提・実現したいこと
初学者です。laravelでアプリを作っています。
以下のことで困っております。
どなたか、ご教授いただければと思い、投稿させていただきました。
どうぞよろしくお願いいたします。
発生している問題・エラーメッセージ
Class "App\Shop" not found
該当のソースコード
PHP
ShopController.php <?php namespace App\Http\Controllers; use App\Shop; use Illuminate\Http\Request; class ShopController extends Controller { /** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { //shopモデルのデータを全て取り出して、indexビューに送る $shops = Shop::all(); return view('index', ['shops' => $shops]); } /** * Show the form for creating a new resource. * * @return \Illuminate\Http\Response */ public function create() { // } /** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { // } /** * Display the specified resource. * * @param \App\Models\Shop $shop * @return \Illuminate\Http\Response */ public function show(Shop $shop) { // } /** * Show the form for editing the specified resource. * * @param \App\Models\Shop $shop * @return \Illuminate\Http\Response */ public function edit(Shop $shop) { // } /** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param \App\Models\Shop $shop * @return \Illuminate\Http\Response */ public function update(Request $request, Shop $shop) { // } /** * Remove the specified resource from storage. * * @param \App\Models\Shop $shop * @return \Illuminate\Http\Response */ public function destroy(Shop $shop) { // } }
PHP
web.php <?php //ドメイン名に続けてshopsの場合shopControllerのindexメソッドを呼び出す Route::get('/shops', 'App\Http\Controllers\ShopController@index')->name('shop.list'); Route::get('/', function () { return redirect('/shops'); });
PHP
index.blade.php <!DOCTYPE html> <html lang="ja"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>Bestラーメン</title> <style> body { padding: 10px } ; </style> </head> <body> <h1>お店一覧</h1> @foreach ($shops as $shop) <p> {{ $shop->category->name }}, {{ $shop->name}}, {{$shop->addres}} </p> @endforeach </body> </html>
PHP
Shop.php <?php namespace App; use Illuminate\Database\Eloquent\Model; class Shop extends Model { //shopモデルとcategoryモデルの関連付 public function category() { //belongToは所属する return $this->belongsTo('App\Category'); } }
PHP
"autoload": { "psr-4": { "App\": "app/", "Database\Factories\": "database/factories/", "Database\Seeders\": "database/seeders/" } }, "autoload-dev": { "psr-4": { "Tests\": "tests/" } },
試したこと
Appフォルダの中に指定されたファイルがあるのにかかわらずnot foundが出てしまいます。composer dump-autoloadでプロジェクト内のクラスを再生成しましたが解消できませんでした
補足情報(FW/ツールのバージョンなど)
PHP 8.0.3
Laravel Framework 8.67.0
まだ回答がついていません
会員登録して回答してみよう