这是我的控制器代码:
public function update(Request $request, $id)
{
$currency = Currency::find($id);
$this->validate($request, [
'cur_name' => 'required',
'cur_price' => 'required|numeric',
'cur_icon' => 'required|image|max:100',
'cur_reserve' => 'required|numeric',
]);
$currency->cur_name = strip_tags($request->input('cur_name'));
$currency->cur_price = $request->input('cur_price');
// image
$file = $request->file('cur_icon');
if (isset($file)) {
$filename = Str::lower(
pathinfo($file->getClientOriginalName(), PATHINFO_FILENAME) . '-' . uniqid() . '.' . $file->getClientOriginalExtension()
);
$destination = 'uploads/';
$file->move($destination, $filename);
$currency->cur_icon = $filename;
}
$currency->cur_reserve = $request->input('cur_reserve');
$currency->slug = \Slug::make(strip_tags($request->input('cur_name')));
dd($currency);
$currency->save();
return redirect('/admin/currency');
}
edit.blade.php(简称):
<form class="form-horizontal" role="form" method="POST" enctype="multipart/form-data" action="/admin/currency/{{ $currency->id }}">
{{ csrf_field() }}
<input name="_method" type="hidden" value="PUT">
...
</form>
路线:
Route::group(['prefix' => 'admin', 'middleware' => 'auth'], function() {
Route::resource('currency', 'CurrencyController');
});
当我点击提交时 - 我没有被重定向,没有任何反应,只是页面重新加载 - 这就是全部。即使我修改了数据,也没有任何更改保存到数据库中。
答案 0 :(得分:2)
如果您未在dd($currency);
之前到达$currency->save()
?那么它可能是验证器重定向。在您的视图中尝试使用此方法进行调试以检查:
{{ count($errors) > 0 ? dd($errors->all()) : ''}}
答案 1 :(得分:1)
试试这个,你需要使用url()方法来获取完整的url。
action="{{ url('/admin/currency/' . $currency->id) }}">
答案 2 :(得分:0)
包括以下内容:
protected $fillable = [
'name', 'email', 'password',
'gender', 'phone' ,'isActive',
'photo','setup', 'address'
];
在您的模型中