PhoeniX5
4 months ago

Laravel mysql select all except an array of values ?

Posted 4 months ago by PhoeniX5

Hello, I am developing an application using yajra-datatables where I need to display a datatable of a certain model except for certain values of an attribute, how can I use laravel eloquent to do that ?

Here is my code :

Controller :

function getMateriel()
    {
        $data = Materiel::join('Types', 'Materiels.type_id', '=', 'Types.type_id')->join('Users', 'Materiels.user_id', '=', 'Users.id')
            ->select('Materiels.id', 'Materiels.mat_code', 'Materiels.mat_designation', 'Materiels.mat_ns', 'Types.type_designation', 'Materiels.mat_description', 'Materiels.note', 'Users.username', 'Materiels.mat_date');
        return DataTables::of($data)
            ->addColumn('modifier', function ($data) {
                return '<a href="#" class="Modifier" id="' . $data->id . '"><i class="material-icons">edit</i></a>';
            })
            ->addColumn('supprimer', function ($sup) {
                return '<a href="#" class="Supprimer" id="' . $sup->id . '"><i class="material-icons">delete</i></a>';
            })
            ->addColumn('check', function ($check) {
                return '<input type="checkbox" required="required" name="check" class="check" id="' . $check->id . ' value="' . $check->id . '">';
            })
            ->rawColumns(['modifier', 'supprimer', 'check'])
            ->make(true);
    }

View :

$('#m_table').DataTable({
                "bProcessing": true,
                "sAjaxSource": "{{ route('Materiel.getMateriel') }}",
               ...
                "columns": [{
                        "data": "id"
                    },
                    {
                        "data": "mat_code"
                    },
                    {
                        "data": "mat_designation"
                    },
                    {
                        "data": "mat_ns"
                    },
                    {
                        "data": "type_designation"
                    },
                    {
                        "data": "mat_description"
                    },
                    {
                        "data": "note"
                    },
                    {
                        "data": "username"
                    },
                    {
                        "data": "mat_date"
                    },
                    {
                        "data": "check"
                    }
                ]
            });

Please sign in or create an account to participate in this conversation.