0

I want to select all rows in datatable where inst_id = ?, this is my code

if(request()->ajax()) {
        return datatables()->of(Domain::select([
            'id', 'domain', 'logo', 'description', 'created_at'
        ]))
        ->addIndexColumn()
        ->addColumn('action', function($data){

               $btn = '<a href="" data-toggle="tooltip" data-original-title="Edit" class="edit btn btn-primary btn-sm">Edit</a>';

               $btn = $btn.' <a href="javascript:void(0)" data-toggle="tooltip"  data-id="" data-original-title="Delete" class="btn btn-danger btn-sm deleteTodo">Delete</a>';

                return $btn;
        })
        ->rawColumns(['action'])
        ->make(true);
    }
    return view('functions/study/domain');
4
  • Have you tried Domain::select([...])->where('inst_id', $id) ? Commented Sep 7, 2020 at 18:12
  • Watch closely the parentheses Commented Sep 7, 2020 at 18:32
  • Thanks it worked, Commented Sep 7, 2020 at 18:41
  • No problem. I posted it as answer so you can mark yourquestion as resolved. Thanks Commented Sep 7, 2020 at 18:45

1 Answer 1

0

You can add whatever queries you want with the base query

$id = 1;
if(request()->ajax()) {
        return datatables()->of(
            Domain::select([
                'id', 'domain', 'logo', 'description', 'created_at'
            ])
            ->where('inst_id', $id)
        )
        ->addIndexColumn()
        ->addColumn('action', function($data){

               $btn = '<a href="" data-toggle="tooltip" data-original-title="Edit" class="edit btn btn-primary btn-sm">Edit</a>';

               $btn = $btn.' <a href="javascript:void(0)" data-toggle="tooltip"  data-id="" data-original-title="Delete" class="btn btn-danger btn-sm deleteTodo">Delete</a>';

                return $btn;
        })
        ->rawColumns(['action'])
        ->make(true);
    }
    return view('functions/study/domain');

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.