我正在创建一个网站。我创建了一个注册页面。我想更新我的详细信息。当我单击AdminPanel.blade.php中的“编辑”按钮时,它会向我提供AdminUpdate.blade.php中的所有详细信息。更改数据后,当我单击“更新用户”按钮时,它会给我这个错误。 - “抱歉,找不到您要找的页面。”
我该如何解决这个问题?
这是我的AdminPanel.blade.php
<table class="table table-bordered">
<tr>
<td> Name </td>
</tr>
@foreach($data as $value )
<tr>
<td> {{ $value->username }} </td>
<td> <a href="edit/{{ $value->id }}"><input type="submit" name="update" value="Update" class="btn-primary"></a> </td>
</tr>
@endforeach
</table>
这是我的AdminPanelController.php
public function edit($id)
{
$edd = User::find($id);
//dd($edd);
return view('AdminUpdate', ['edd' => $edd]);
}
public function adminedit($id, Request $request)
{
// Add Validation
$users = User::find($id);
$users->username = $request->get('username');
$users->email = $request->get('email');
$users->save();
return redirect('AdminPanel');
}
这是我的AdminUpdate.blade.php
<form action="adminedit/{{ $edd->id }}" method="post" enctype="multipart/form-data">
{{ method_field('PUT') }}
{{ csrf_field() }}
<div class="form-group">
<label>Username : *</label>
<input type="text" class="form-control" name="username" value="{{$edd->username}}" placeholder="Enter Your Username" required>
</div>
<div class="form-group">
<label>Email : *</label>
<input type="email" class="form-control" name="email" value="{{$edd->email}}" placeholder="Enter Your Username" required>
</div>
<div class="form-group">
<label>Password : *</label>
<input type="password" class="form-control" name="password" value="{{$edd->password}}" placeholder="Enter Your Password" required>
</div>
<div class="form-group">
<label>Upload Profile Picture :</label>
<input type="file" class="form-control-file" name="file_img" aria-describedby="fileHelp">
<small id="fileHelp" class="form-text text-muted">If U Want , U Can Skip Upload A Profile Picture</small>
</div>
<input type="submit" class="btn btn-primary" value="Update User">
</form>
这是我的路线。
Route::get('/edit/{id}', 'AdminPanelController@edit');
Route::put('/adminedit/{id}', 'AdminPanelController@adminedit');
更新至@Alex
<form action="/adminedit/2" method="post" enctype="multipart/form-data">
<input type="hidden" name="_method" value="PUT">
<input type="hidden" name="_token" value="eECno3BdT86XYW2PfLjxL4ABtekEBLbxFvDmxY9y">
<div class="form-group">
<label>Username : *</label>
<input type="text" class="form-control" name="username" value="head_slsoc_1" placeholder="Enter Your Username" required>
</div>
<div class="form-group">
<label>Email : *</label>
<input type="email" class="form-control" name="email" value="kistlakr@gmail.com" placeholder="Enter Your Username" required>
</div>
<div class="form-group">
<label>Password : *</label>
<input type="password" class="form-control" name="password" value="asd" placeholder="Enter Your Password" required>
</div>
<div class="form-group">
<label>Upload Profile Picture :</label>
<input type="file" class="form-control-file" name="file_img" aria-describedby="fileHelp">
<small id="fileHelp" class="form-text text-muted">If U Want , U Can Skip Upload A Profile Picture</small>
</div>
<input type="submit" class="btn btn-primary" value="Update User">
</form>
答案 0 :(得分:2)
由于您使用PUT
方法:
{{ method_field('PUT') }}
将路线更改为:
Route::put('/adminedit/{id}', 'AdminPanelController@adminedit');
答案 1 :(得分:2)
此更改method="post"
至method =“PUT”
并写下你的路线
Route::put('/adminedit/{id}', 'AdminPanelController@adminedit');