Guest User

Phonebooks Controller

a guest
Jun 28th, 2016
176
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 3.35 KB | None | 0 0
  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'=>'name', 'title'=>'Nama'])
  42.         ->addColumn(['data' => 'hp', 'name'=>'hp', 'title'=>'HP'])
  43.         ->addColumn(['data' => 'group', 'name'=>'group', 'title'=>'Group'])
  44.         ->addColumn(['data' => 'created_at', 'name'=>'created_at', 'title'=>'Created At'])
  45.         ->addColumn(['data' => 'action', 'name'=>'action', 'title'=>'', 'orderable'=>false, 'searchable'=>false]);
  46.  
  47.         return view('phonebooks.index')->with(compact('html'));
  48.     }
  49.  
  50.     /**
  51.      * Show the form for creating a new resource.
  52.      *
  53.      * @return \Illuminate\Http\Response
  54.      */
  55.     public function create()
  56.     {
  57.         //
  58.     }
  59.  
  60.     /**
  61.      * Store a newly created resource in storage.
  62.      *
  63.      * @param  \Illuminate\Http\Request  $request
  64.      * @return \Illuminate\Http\Response
  65.      */
  66.     public function store(Request $request)
  67.     {
  68.         //
  69.     }
  70.  
  71.     /**
  72.      * Display the specified resource.
  73.      *
  74.      * @param  int  $id
  75.      * @return \Illuminate\Http\Response
  76.      */
  77.     public function show($id)
  78.     {
  79.         //
  80.     }
  81.  
  82.     /**
  83.      * Show the form for editing the specified resource.
  84.      *
  85.      * @param  int  $id
  86.      * @return \Illuminate\Http\Response
  87.      */
  88.     public function edit($id)
  89.     {
  90.         //
  91.     }
  92.  
  93.     /**
  94.      * Update the specified resource in storage.
  95.      *
  96.      * @param  \Illuminate\Http\Request  $request
  97.      * @param  int  $id
  98.      * @return \Illuminate\Http\Response
  99.      */
  100.     public function update(Request $request, $id)
  101.     {
  102.         //
  103.     }
  104.  
  105.     /**
  106.      * Remove the specified resource from storage.
  107.      *
  108.      * @param  int  $id
  109.      * @return \Illuminate\Http\Response
  110.      */
  111.     public function destroy($id)
  112.     {
  113.         //
  114.     }
  115. }
Advertisement
Add Comment
Please, Sign In to add comment