Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace App\Http\Controllers;
- use Illuminate\Http\Request;
- use App\Http\Requests;
- use Yajra\Datatables\Html\Builder;
- use Yajra\Datatables\Datatables;
- use App\Phonebook;
- use DB;
- class PhonebooksController extends Controller
- {
- /**
- * Display a listing of the resource.
- *
- * @return \Illuminate\Http\Response
- */
- public function index(Request $request, Builder $htmlBuilder)
- {
- if ($request->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'=>'name', 'title'=>'Nama'])
- ->addColumn(['data' => 'hp', 'name'=>'hp', 'title'=>'HP'])
- ->addColumn(['data' => 'group', 'name'=>'group', 'title'=>'Group'])
- ->addColumn(['data' => 'created_at', 'name'=>'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)
- {
- //
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment