lundi 30 janvier 2017

How do I toggle a boolean value with a button?

I have a table that lists some tasks, with a column to show if they are completed or not. I have added a button to toggle the "Completed" column, but I can't seem to get the row I select to update. Can someone show me where I am going wrong?

I have created the route, button and method, and it all seems to work but the DB doesn't update (for now I just have the code to change the "completed" column to 1).

Routes:

Route::patch('tasks/complete/{id}', 'TaskController@updateCompleted');
Route::resource('tasks' , 'TaskController');

Button in view:


    
    


Controller:

public function updateCompleted($id)
{

    $task = Task::findOrFail($id);

    $task->completed == 1;

    $task->update();

    Session::flash('message', 'Task updated!');
    return redirect('tasks');

}

Thanks!



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

Aucun commentaire:

Enregistrer un commentaire