dimanche 28 octobre 2018

Laravel 5.2 - Delete from db

I am using Laravel Framework version 5.2.45.

I have created a simple view that outputs my todos:

        @foreach($todos as $todo)
             <button href="" class="btn btn-danger">x</button>

            <hr>
        @endforeach

Within my routes I have created the following route to delete a todo:

Route::get('/todo/delete/{id}', [
    'uses' => 'TodosController@delete',
    'as' => 'todo.delete'
]);

Within my TodosController I created the following delete method:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

use App\Http\Requests;
use App\Todo;

class TodosController extends Controller
{

    public function delete($id) {
        $todo = Todo::find($id);

        $todo->delete();

        return redirect()->back();
    }
// ...

When I press the button in the frontend nothing happens. I do not get any error...

Any suggestions what is wrong with my implementation?

Appreciate your replies!



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire