Saturday, 23 December 2017

Update Function Modal Box

I encountered the same problem, here is how i solved it. My modal is on the index.blade page, as follows:
<a data-toggle="modal" role="button" href="{{ URL::to('user/'.$user->id.'/edit') }}" class="btn btn-default"><i class="icon-pencil"></i></a>
Then the modal:
    <!-- Form modal -->
            <div id="edit_modal" class="modal fade" tabindex="-1" role="dialog">
                <div class="modal-dialog">
                    <div class="modal-content">
                        <div class="modal-header">
                            <button type="button" class="close" data-dismiss="modal" aria-hidden="true">&times;</button>
                            <h4 class="modal-title"><i class="icon-paragraph-justify2"></i> Edit User</h4>

                        <!-- Form inside modal -->
                        {!! Form::model($user,array('route' => ['user.update', $user->id],'method'=>'PATCH')) !!}

                            <div class="modal-body with-padding">                               
                                <div class="form-group">
                                    <div class="row">
                                    <div class="col-sm-12">
                                        <label>First name</label>
                                        <input type="text" class="form-control" placeholder="Chinedu"
                                         name="name" value="{!! $user->name !!}">
                        {!! Form::close() !!}

$(function() {
My controller methods are:
public function index()
        //View all users
        $users= User::orderBy('name', 'ASC')->paginate(10);
        return view('user.index',compact('users'));

public function edit($id)
        $users= User::orderBy('name', 'ASC')->paginate(10);
        $user= User::findOrFail($id);
        return view('user.index',compact('users','user'));
Hope this helps


No comments:

Post a Comment