Laravel - How to save checkbox choice in item list?

0

In a contact management system, I have a list of items which have a checkbox each (gmail style) so that I can select them and use some action related to the selected ones. What is the best way to save these selected items to each page accessed?

One of the Controllers that lists the items:

$request = DB::table('contatos')
            ->select('*')
            ->paginate(15);

        return view('list')
            ->with('request', $request);

And View :

    <table>
    <tr>
        <th><input type="checkbox" id="seleciona_todos" /></th>
        <th>Nome</th>
        <th>E-mail</th>
    </tr>

    @foreach($r as $p)
    <tr>
        <td><input type="checkbox" value="{{ $p->id }}" /></td>
        <td>{{ $p->nome }}</td>
        <td>{{ $p->email }}</td>
    </tr>
    @endforeach

    </table>
    {!! $r->appends(Input::except('page'))->links(); !!}

- Has pagination

- I use Laravel

- You will have other admin user accounts moving at the same time

I've thought of doing an ajax for a php file that writes and deletes items from an array in a session or even uses a table in the database to save the currently selected items (but will have other users currently picking and guessing that this was not going to work). What is the best way to resolve this?

    
asked by anonymous 11.05.2016 / 01:21

1 answer

0

I believe there are no problems using the database and ajax even though other users are currently moving. If this is the problem you can use DB::transaction() in the method that performs the action of deleting the items.

For example:

DB::transaction(function(){

  // ação de deletar, inserir e etc

});

If an error occurs in this action, the system will not change the database.

    
11.05.2016 / 18:11