mercredi 31 août 2016

Laravel - Deleting a row (table)

I'm using laravel 5.2 and I'm studying the manipulation of datas with Eloquent. I have a table in which I need to delete a row with a button.

Problem : The server returns a route error (NotFoundHttpException)

Guideline : I watched this video https://www.youtube.com/watch?v=1EyoZhfZ2TY in order to inspire me for the datas.

Here is the Route (routes.php)

Route::delete('players&/{id}', 'PlayersController@deletePlayer');

Here is the template (players.blade.php) Pay attention of the last table data (td)

     <tbody>
    <?php
        foreach($players as $player) {
    ?>
    <tr>
        <td><?php echo $player->PLA_ID?></td>
        <td><?php echo $player->PLA_Name?></td>
        <td><?php echo $player->PLA_Surname?></td>
        <td><?php echo $player->PLA_Pseudo?></td>
        <td><span class="glyphicon glyphicon-pencil"></span></td>
        <td><a href="delete&<?php echo $player->PLA_ID?>"><span class="glyphicon glyphicon-trash"></span></a></td>
    </tr>
    <?php }
    ?>
    </tbody>

Finally the function (PlayersController.php)

    public function deletePlayer($id){

    Player::destroy($id);
    return redirect('players');
}

I will search on my side too and thank you for taking time on my problem =)

P.S. I need the best practices with this framework, so if you have some ideas that allow me to code better, I could help some beginners like me =)



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/2bBBFNW
via IFTTT

Aucun commentaire:

Enregistrer un commentaire