mardi 23 octobre 2018

Edit user laravel using Vue

I have a modal component and a users component which has all the users in an HTML table.

so I decided to use modal to edit the user I Added the modal and linked a button to each user in the v-for loop

So my problem is how I can get the id of the current user?

My table :

<tr v-for="admin in filteredList" :key="admin.id">
                        <td></td>
                        <td></td>
                        <td></td>
                        <td></td>
                        <td></td>

                   <td>  
                     <button class="btn btn-success" data-toggle="modal" data-target="#edit-admin" >Edit account/button>
                     </td>

                      </tr>

                    </tbody>

My modal :

  <admin-edit-modal></admin-edit-modal>

usually, I pass the id to the modal as a prop in Laravel view but since I'm using a component I can't do it :\

in my admin edit modal Component :

this is my fetch method

   created(){
          axios.get(`api/admins/edit/{id}`,[

            ])
            .then(res=>{
              this.admin = res.data.data;

              console.log(res)
            }).then(res=>{

            })
        }

edit method :

 public function edit($id)
    {
       $admin = User::find($id);
        return response()->json($admin);
    }

I'm confused about this issue Any help is appreciated.

thanks



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire