ここにより詳細な情報を記載してください。
前提・実現したいこと
初学者です。laravelでラーメン屋投稿アプリを作っています。お店の投稿画面作成中にclass SubCategoryが見つからないとのエラーで詰まっています。色々ググりましたがこの先有益な情報が見つけられそうにないので、投稿させていただきました。どうかよろしくお願いいたします。
発生している問題・エラーメッセージ
Class 'APP\SubCategory' not found
該当のソースコード
php
1### new.blade.php ### 2 3@extends('layout') 4 5@section('content') 6 <h2>お店投稿</h2> 7 {{ Form::open(['route' => 'shop.store']) }} 8 <div class="form-group"> 9 {{ Form::label('name', '店名') }} 10 {{ Form::text('name', null) }} 11 </div> 12 <div class="form-group"> 13 {{ Form::label('address', '住所') }} 14 {{ Form::text('address', null) }} 15 </div> 16 <div class="form-group"> 17 {{ Form::label('category', 'カテゴリ') }} 18 {{ Form::select('category_id', $categories) }} 19 </div> 20 <div class="form-group"> 21 {{ Form::label('subcategories','サブカテゴリ') }} 22 23 {{ Form::select('subcategory_id', $subcategories) }} 24 </div> 25 26 27 <div class="form-submit"> 28 <button type="submit">投稿する</button> 29 </div> 30 </div> 31 </form> 32 {{ Form::close() }} 33 <div> 34 <a href="{{ route('shop.list') }}">一覧に戻る</a> 35 </div> 36@endsection 37
php
1### SubCategory.php ### 2 3<?php 4 5namespace App; 6 7use Illuminate\Database\Eloquent\Model; 8 9class SubCategory extends Model 10{ 11 protected $table = 'subcategories'; 12} 13
php
1### ShopController.php ### 2 3<?php 4namespace App\Http\Controllers; 5 6use App\Shop; 7use App\Category; 8use APP\SubCategory; 9use Illuminate\Http\Request; 10 11class ShopController extends Controller 12{ 13 /** 14 * Display a listing of the resource. 15 * 16 * @return \Illuminate\Http\Response 17 */ 18 public function index() 19 { 20 $shops = Shop::all(); 21 return view('index', ['shops' => $shops]); 22 } 23 24 /** 25 * Show the form for creating a new resource. 26 * 27 * @return \Illuminate\Http\Response 28 */ 29 public function create() 30 { 31 $categories = Category::all()->pluck('name', 'id'); 32 $subcategories = SubCategory::all()->pluck('name', 'id'); 33 return view('new', ['categories' => $categories, 'subcategories' => $subcategories]); 34 } 35 36 /** 37 * Store a newly created resource in storage. 38 * 39 * @param \Illuminate\Http\Request $request 40 * @return \Illuminate\Http\Response 41 */ 42 public function store(Request $request) 43 { 44 // 45 } 46 47 /** 48 * Display the specified resource. 49 * 50 * @param \App\Shop $shop 51 * @return \Illuminate\Http\Response 52 */ 53 public function show($id) 54 { 55 $shop = Shop::find($id); 56 return view('show', ['shop' => $shop]); 57 } 58 59 /** 60 * Show the form for editing the specified resource. 61 * 62 * @param \App\Shop $shop 63 * @return \Illuminate\Http\Response 64 */ 65 public function edit(Shop $shop) 66 { 67 // 68 } 69 70 /** 71 * Update the specified resource in storage. 72 * 73 * @param \Illuminate\Http\Request $request 74 * @param \App\Shop $shop 75 * @return \Illuminate\Http\Response 76 */ 77 public function update(Request $request, Shop $shop) 78 { 79 // 80 } 81 82 /** 83 * Remove the specified resource from storage. 84 * 85 * @param \App\Shop $shop 86 * @return \Illuminate\Http\Response 87 */ 88 public function destroy(Shop $shop) 89 { 90 // 91 } 92} 93
php
1### Web.php ### 2<?php 3 4Route::get('/shops', 'ShopController@index')->name('shop.list'); 5Route::get('/shop/new', 'ShopController@create')->name('shop.new'); 6Route::post('/shop', 'ShopController@store')->name('shop.store'); 7Route::get('/shop/{id}', 'ShopController@show')->name('shop.detail'); 8 9Route::get('/', function() { 10 return redirect('/shops'); 11}); 12
補足情報(FW/ツールのバージョンなど)
PHP 7.1.23
Laravel Framework 5.7.28
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2019/08/17 05:59