0

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/{{ $currency->id }}">
                {{ csrf_field() }}
                <input name="_method" type="hidden" value="PUT">
...
</form>

routes:

Route::group(['prefix' => 'admin', 'middleware' => 'auth'], function() {
    Route::resource('currency', 'CurrencyController');
});

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.

1
  • 1
    share your routes too Commented Nov 15, 2016 at 17:27

3 Answers 3

3

If you aren't getting to dd($currency); before $currency->save()? then it may be the validator redirecting. Try debugging with this in your view to check:

{{ count($errors) > 0 ? dd($errors->all()) : ''}}
Sign up to request clarification or add additional context in comments.

2 Comments

array:1 [▼ 0 => "The cur icon field is required." ] You were right, that's validator. Could you tell, how can i separate validation rule if there's file input and when there's no file input in my case.
That's it. In your validator change 'cur_icon' => 'required|image|max:100', to 'cur_icon' => 'image', passing the required parameter looks for a field, not a file. image is enough to require a file be present and also be an image.
1

Try this, you need to use url() method to get full url.

action="{{ url('/admin/currency/' . $currency->id) }}">

1 Comment

Thank you for the tip, but same behavior.
0

Include something like:

protected $fillable = [
        'name', 'email', 'password',
        'gender', 'phone' ,'isActive', 
        'photo','setup', 'address'
 ];

In your Model

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.