ajax()) { DB::statement(DB::raw('set @nomor=0 ')); //$phonebooks = Phonebook::with('group'); //$phonebooks = Phonebook::select(DB::raw('@nomor := @nomor + 1 as no'), 'id', 'name', 'hp', 'created_at')->with('group'); $phonebooks = Phonebook::join('groups', 'phonebooks.id', '=', 'groups.id') ->select(DB::raw('@nomor := @nomor + 1 as no'), 'phonebooks.id as id', 'phonebooks.name as name', 'phonebooks.hp as hp', 'phonebooks.created_at as created_at', 'groups.group as group'); return Datatables::of($phonebooks) ->addColumn('action', function($phonebook){ return view('datatable._action', [ 'model' => $phonebook, 'form_url' => route('phonebooks.destroy', $phonebook->id), 'edit_url' => route('phonebooks.edit', $phonebook->id), 'confirm_message' => 'Yakin mau menghapus ' . $phonebook->name . '?' ]); })->make(true); } $html = $htmlBuilder ->addColumn(['data' => 'no', 'name'=>'no', 'title'=>'#', 'orderable'=>false, 'searchable'=>false]) ->addColumn(['data' => 'name', 'name'=>'phonebooks.name', 'title'=>'Nama']) ->addColumn(['data' => 'hp', 'name'=>'phonebooks.hp', 'title'=>'HP']) ->addColumn(['data' => 'group', 'name'=>'groups.group', 'title'=>'Group']) ->addColumn(['data' => 'created_at', 'name'=>'phonebooks.created_at', 'title'=>'Created At']) ->addColumn(['data' => 'action', 'name'=>'action', 'title'=>'', 'orderable'=>false, 'searchable'=>false]); return view('phonebooks.index')->with(compact('html')); } /** * Show the form for creating a new resource. * * @return \Illuminate\Http\Response */ public function create() { // } /** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Request $request) { // } /** * Display the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function show($id) { // } /** * Show the form for editing the specified resource. * * @param int $id * @return \Illuminate\Http\Response */ public function edit($id) { // } /** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Request $request, $id) { // } /** * Remove the specified resource from storage. * * @param int $id * @return \Illuminate\Http\Response */ public function destroy($id) { // } }