ご覧いただきありがとうございます。
Laravel8.83.7
で編集画面を作成しています。
Controllerに更新の処理を書いたのですが
PHP
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use App\Models\Shop; use Illuminate\Support\Facades\Auth; use Illuminate\Support\Facades\DB; class ShopController extends Controller { public function update(Request $request, $shop_id ){ if(!ctype_digit($shop_id)){ return redirect('/list')->with('flash_message',__('Invalid operation was performed')); } $shop = DB::table('shops')->where('shop_id',$shop_id)->first(); $shop->fill($request->all())->save(); return redirect('/list')->with('flash_message',__('Updated')); } }
表題のエラーが出てしまいます。
modelのコードは
PHP
<?php namespace App\Models; use Illuminate\Database\Eloquent\Factories\HasFactory; use Illuminate\Database\Eloquent\Model; class Shop extends Model { use HasFactory; protected $fillable = [ 'shop_name', 'shop_pref', 'shop_city', 'nearest_station', 'budget_min', 'budget_max', 'party', 'small', 'girls', 'seafood', 'brandcow', 'localsake', 'craftbeer' ]; }
で更新のための情報を入力する画面は
PHP
@extends('layouts.app', ['authgroup' => 'admin']) @section('content') <div class="container"> <div class="row justify-content-center"> <div class="col-md-8"> <div class="card"> <div class="card-header">{{ __('Edit Shop')}}</div> <div class="card-body"> <form method="POST" action="{{ route('update',['shop_id'=>$shop->shop_id]) }}"> @csrf <div class="row mb-3"> <label for="shop_name" class="col-md-4 col-form-label text-md-end">{{ __('Shop Name') }}</label> <div class="col-md-6"> <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> @error('shop_name') <span class="invalid-feedback" role="alert"> <strong>{{ $message }}</strong> </span> @enderror </div> </div> <div class="row mb-3"> <label for="shop_pref" class="col-md-4 col-form-label text-md-end">{{ __('Shop Pref') }}</label> <div class="col-md-6"> <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> @error('shop_pref') <span class="invalid-feedback" role="alert"> <strong>{{ $message }}</strong> </span> @enderror </div> </div> <div class="row mb-3"> <label for="shop_city" class="col-md-4 col-form-label text-md-end">{{ __('Shop City') }}</label> <div class="col-md-6"> <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"> @error('shop_city') <span class="invalid-feedback" role="alert"> <strong>{{ $message }}</strong> </span> @enderror </div> </div> <div class="row mb-3"> <label for="nearest_station" class="col-md-4 col-form-label text-md-end">{{ __('Nearest Station') }}</label> <div class="col-md-6"> <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"> @error('nearest_station') <span class="invalid-feedback" role="alert"> <strong>{{ $message }}</strong> </span> @enderror </div> </div> <div class="row mb-3"> <label for="budget_min" class="col-md-4 col-form-label text-md-end">{{ __('Budget Min') }}</label> <div class="col-md-6"> <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> @error('budget_min') <span class="invalid-feedback" role="alert"> <strong>{{ $message }}</strong> </span> @enderror </div> </div> <div class="row mb-3"> <label for="budget_max" class="col-md-4 col-form-label text-md-end">{{ __('Budget Max') }}</label> <div class="col-md-6"> <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"> @error('budget_max') <span class="invalid-feedback" role="alert"> <strong>{{ $message }}</strong> </span> @enderror </div> </div> <div class="row mb-0"> <div class="col-md-8 offset-md-4"> <button type="submit" class="btn btn-primary"> {{ __('Update') }} </button> </div> </div> </form> </div> </div> </div> </div> </div> @endsection
になります
まだ回答がついていません
会員登録して回答してみよう