ご覧いただきありがとうございます。
Laravel8.83.7
で編集画面を作成しています。
Controllerに更新の処理を書いたのですが
PHP
1<?php 2 3namespace App\Http\Controllers; 4 5use Illuminate\Http\Request; 6use App\Models\Shop; 7use Illuminate\Support\Facades\Auth; 8use Illuminate\Support\Facades\DB; 9 10class ShopController extends Controller 11{ 12 13 public function update(Request $request, $shop_id ){ 14 if(!ctype_digit($shop_id)){ 15 return redirect('/list')->with('flash_message',__('Invalid operation was performed')); 16 } 17 18 $shop = DB::table('shops')->where('shop_id',$shop_id)->first(); 19 $shop->fill($request->all())->save(); 20 21 return redirect('/list')->with('flash_message',__('Updated')); 22 23 } 24} 25
表題のエラーが出てしまいます。
modelのコードは
PHP
1<?php 2 3namespace App\Models; 4 5use Illuminate\Database\Eloquent\Factories\HasFactory; 6use Illuminate\Database\Eloquent\Model; 7 8class Shop extends Model 9{ 10 use HasFactory; 11 12 protected $fillable = [ 13 'shop_name', 14 'shop_pref', 15 'shop_city', 16 'nearest_station', 17 'budget_min', 18 'budget_max', 19 'party', 20 'small', 21 'girls', 22 'seafood', 23 'brandcow', 24 'localsake', 25 'craftbeer' 26 ]; 27 28} 29
で更新のための情報を入力する画面は
PHP
1@extends('layouts.app', ['authgroup' => 'admin']) 2 3@section('content') 4<div class="container"> 5 <div class="row justify-content-center"> 6 <div class="col-md-8"> 7 <div class="card"> 8 <div class="card-header">{{ __('Edit Shop')}}</div> 9 10 <div class="card-body"> 11 <form method="POST" action="{{ route('update',['shop_id'=>$shop->shop_id]) }}"> 12 @csrf 13 14 <div class="row mb-3"> 15 <label for="shop_name" class="col-md-4 col-form-label text-md-end">{{ __('Shop Name') }}</label> 16 17 <div class="col-md-6"> 18 <input id="shop_name" type="text" class="form-control @error('shop_mame') is-invalid @enderror" name="shop_name" value="{{$shop->shop_name}}" required autocomplete="shop_name" autofocus> 19 20 @error('shop_name') 21 <span class="invalid-feedback" role="alert"> 22 <strong>{{ $message }}</strong> 23 </span> 24 @enderror 25 </div> 26 </div> 27 28 <div class="row mb-3"> 29 <label for="shop_pref" class="col-md-4 col-form-label text-md-end">{{ __('Shop Pref') }}</label> 30 31 <div class="col-md-6"> 32 <input id="shop_pref" type="text" class="form-control @error('shop_pref') is-invalid @enderror" name="shop_pref" value="{{$shop->shop_pref}}" required autocomplete="shop_pref" autofocus> 33 34 @error('shop_pref') 35 <span class="invalid-feedback" role="alert"> 36 <strong>{{ $message }}</strong> 37 </span> 38 @enderror 39 </div> 40 </div> 41 42 <div class="row mb-3"> 43 <label for="shop_city" class="col-md-4 col-form-label text-md-end">{{ __('Shop City') }}</label> 44 45 <div class="col-md-6"> 46 <input id="shop_city" type="text" class="form-control @error('shop_city') is-invalid @enderror" name="{{$shop->shop_city}}" value="{{$shop->shop_city}}" required autocomplete="shop_city"> 47 48 @error('shop_city') 49 <span class="invalid-feedback" role="alert"> 50 <strong>{{ $message }}</strong> 51 </span> 52 @enderror 53 </div> 54 </div> 55 56 <div class="row mb-3"> 57 <label for="nearest_station" class="col-md-4 col-form-label text-md-end">{{ __('Nearest Station') }}</label> 58 59 <div class="col-md-6"> 60 <input id="nearest_station" type="text" class="form-control @error('nearest_station') is-invalid @enderror" name="nearest_station" value="{{$shop->nearest_station}}" required autocomplete="nearest_afstation"> 61 62 @error('nearest_station') 63 <span class="invalid-feedback" role="alert"> 64 <strong>{{ $message }}</strong> 65 </span> 66 @enderror 67 </div> 68 </div> 69 70 <div class="row mb-3"> 71 <label for="budget_min" class="col-md-4 col-form-label text-md-end">{{ __('Budget Min') }}</label> 72 73 <div class="col-md-6"> 74 <input id="budget_min" type="number" class="form-control @error('budget_min') is-invalid @enderror" name="budget_min" value="{{$shop->budget_min}}" required autocomplete="budget_min" autofocus> 75 76 @error('budget_min') 77 <span class="invalid-feedback" role="alert"> 78 <strong>{{ $message }}</strong> 79 </span> 80 @enderror 81 </div> 82 </div> 83 84 <div class="row mb-3"> 85 <label for="budget_max" class="col-md-4 col-form-label text-md-end">{{ __('Budget Max') }}</label> 86 87 <div class="col-md-6"> 88 <input id="budget_max" type="number" class="form-control @error('budget_max') is-invalid @enderror" name="budget_max" value="{{$shop->budget_max}}" required autocomplete="budget_max"> 89 90 @error('budget_max') 91 <span class="invalid-feedback" role="alert"> 92 <strong>{{ $message }}</strong> 93 </span> 94 @enderror 95 </div> 96 </div> 97 <div class="row mb-0"> 98 <div class="col-md-8 offset-md-4"> 99 <button type="submit" class="btn btn-primary"> 100 {{ __('Update') }} 101 </button> 102 103 </div> 104 </div> 105 </form> 106 </div> 107 </div> 108 </div> 109 </div> 110</div> 111@endsection 112
になります

回答1件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。
2022/04/24 00:10