donnykurnia

datatable edited

Jun 28th, 2016
381
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <?php
  2.  
  3. namespace App\Http\Controllers;
  4.  
  5. use Illuminate\Http\Request;
  6.  
  7. use App\Http\Requests;
  8. use Yajra\Datatables\Html\Builder;
  9. use Yajra\Datatables\Datatables;
  10. use App\Phonebook;
  11. use DB;
  12.  
  13. class PhonebooksController extends Controller
  14. {
  15.     /**
  16.      * Display a listing of the resource.
  17.      *
  18.      * @return \Illuminate\Http\Response
  19.      */
  20.     public function index(Request $request, Builder $htmlBuilder)
  21.     {
  22.        
  23.         if ($request->ajax()) {
  24.             DB::statement(DB::raw('set @nomor=0 '));
  25.             //$phonebooks = Phonebook::with('group');
  26.             //$phonebooks = Phonebook::select(DB::raw('@nomor := @nomor + 1 as no'), 'id', 'name', 'hp', 'created_at')->with('group');
  27.             $phonebooks = Phonebook::join('groups', 'phonebooks.id', '=', 'groups.id')
  28.                 ->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');
  29.             return Datatables::of($phonebooks)
  30.             ->addColumn('action', function($phonebook){
  31.             return view('datatable._action', [
  32.             'model' => $phonebook,
  33.             'form_url' => route('phonebooks.destroy', $phonebook->id),
  34.             'edit_url' => route('phonebooks.edit', $phonebook->id),
  35.             'confirm_message' => 'Yakin mau menghapus ' . $phonebook->name . '?'
  36.             ]);
  37.             })->make(true);
  38.         }
  39.         $html = $htmlBuilder
  40.         ->addColumn(['data' => 'no',         'name'=>'no',                    'title'=>'#', 'orderable'=>false, 'searchable'=>false])
  41.         ->addColumn(['data' => 'name',       'name'=>'phonebooks.name',       'title'=>'Nama'])
  42.         ->addColumn(['data' => 'hp',         'name'=>'phonebooks.hp',         'title'=>'HP'])
  43.         ->addColumn(['data' => 'group',      'name'=>'groups.group',          'title'=>'Group'])
  44.         ->addColumn(['data' => 'created_at', 'name'=>'phonebooks.created_at', 'title'=>'Created At'])
  45.         ->addColumn(['data' => 'action',     'name'=>'action',                'title'=>'', 'orderable'=>false, 'searchable'=>false]);
  46.         return view('phonebooks.index')->with(compact('html'));
  47.     }
  48.  
  49.     /**
  50.      * Show the form for creating a new resource.
  51.      *
  52.      * @return \Illuminate\Http\Response
  53.      */
  54.     public function create()
  55.     {
  56.         //
  57.     }
  58.  
  59.     /**
  60.      * Store a newly created resource in storage.
  61.      *
  62.      * @param  \Illuminate\Http\Request  $request
  63.      * @return \Illuminate\Http\Response
  64.      */
  65.     public function store(Request $request)
  66.     {
  67.         //
  68.     }
  69.  
  70.     /**
  71.      * Display the specified resource.
  72.      *
  73.      * @param  int  $id
  74.      * @return \Illuminate\Http\Response
  75.      */
  76.     public function show($id)
  77.     {
  78.         //
  79.     }
  80.  
  81.     /**
  82.      * Show the form for editing the specified resource.
  83.      *
  84.      * @param  int  $id
  85.      * @return \Illuminate\Http\Response
  86.      */
  87.     public function edit($id)
  88.     {
  89.         //
  90.     }
  91.  
  92.     /**
  93.      * Update the specified resource in storage.
  94.      *
  95.      * @param  \Illuminate\Http\Request  $request
  96.      * @param  int  $id
  97.      * @return \Illuminate\Http\Response
  98.      */
  99.     public function update(Request $request, $id)
  100.     {
  101.         //
  102.     }
  103.  
  104.     /**
  105.      * Remove the specified resource from storage.
  106.      *
  107.      * @param  int  $id
  108.      * @return \Illuminate\Http\Response
  109.      */
  110.     public function destroy($id)
  111.     {
  112.         //
  113.     }
  114. }
Advertisement
Add Comment
Please, Sign In to add comment