mardi 15 novembre 2016

Laravel update method not working correctly

Here's my controller code:

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 (short):

<form class="form-horizontal" role="form" method="POST" enctype="multipart/form-data" action="/admin/currency/">
                
                <input name="_method" type="hidden" value="PUT">
...
</form>

When i click on submit - i am not being redirected and nothing happens, just page reloads - that's all. Even if i modify data no changes are saved to database.



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire