##前提、実現したい事
<環境>
OS : macOS Big Sur 11.4
MAMP
Laravel : 6.2
<実現したい事>
登録したユーザーの更新処理を行いたい
##ソースコード
php
1Route::prefix('users')->name('users.')->group(function() { 2 Route::get('/list','UserController@list')->name('list'); 3 Route::get('/edit/{producer_name}', 'UserController@getEdit')->name('edit')->middleware('auth'); 4 Route::post('/edit/{producer_name}', 'UserController@postEdit')->name('postEdit')->middleware('auth'); 5 Route::get('/{producer_name}','UserController@show')->name('show')->middleware('auth'); 6});
php
1//マイページ更新画面表示 2 public function getEdit(string $producer_name) 3 { 4 $user = User::where('producer_name', $producer_name)->first(); 5 6 return view('users.edit', [ 7 'user' => $user, 8 ]); 9 } 10 11 //マイページ更新処理 12 public function postEdit($producer_name, Request $request) 13 { 14 $producer_name->fill($request->all())->save(); 15 return redirect()->route('users.edit', ['producer_name' => $producer_name]); 16 17 }
php
1@extends('app') 2 3@section('title', '生産者ユーザー登録') 4 5@section('content') 6@include('nav') 7 8 <div> 9 <h1 class="text-center mt-100">生産者情報更新ページ</h1> 10 </div> 11 <div class="card mw-1000 center mt-5"> 12 <div class="card-body text-center"> 13 <h2 class="card-title text-center">ユーザー登録更新</h2> 14 @include('error_card_list') 15 <div class="card-text"> 16 <form method="POST" action="{{ route('users.postEdit', ['producer_name' => $user->producer_name]) }}" enctype="multipart/form-data"> 17 @csrf 18 <div class="md-form"> 19 <label for="producer_name">生産者名</label> 20 <input class="form-control" type="text" id="producer_name" name="producer_name" required 21 value="{{ $user->producer_name }}"> 22 </div> 23 <div class="md-form"> 24 <label for="name">担当者名</label> 25 <input class="form-control" type="text" id="name" name="name" required value="{{ $user->name }}"> 26 </div> 27 <div class="md-form"> 28 <label for="introduction"></label> 29 <textarea name="introduction" id="introduction" required class="form-control" rows="16" 30 placeholder="紹介文">{{ $user->introduction }}</textarea> 31 </div> 32 33 <div class="md-form"> 34 <label for="address">住所</label> 35 <input class="form-control" type="text" id="address" name="address" required 36 value="{{ $user->address }}"> 37 </div> 38 39 <div class="md-form"> 40 <label for="email">メール</label> 41 <input class="form-control" type="text" id="email" name="email" required 42 value="{{ $user->email }}"> 43 </div> 44 <div class="md-form"> 45 <label for="password">パスワード</label> 46 <input class="form-control" type="password" id="password" name="password" required> 47 </div> 48 49 <div class="introduction_image"> 50 <label class="form-label" for="image">紹介画像</label> 51 <input class="form-control-file" type="file" id="image" name="image"> 52 </div> 53 54 <button class="btn btn-block btn-outline-primary" data-mdb-ripple-color="dark" type="submit">生産者情報登録</button> 55 </form> 56 </div> 57 </div> 58 </div> 59 60 @include('footer') 61 62@endsection 63
##試した事
postEdit
の引数にstring
をつけましたが、エラーが発生しました。
あなたの回答
tips
プレビュー