Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Datatable controller example
<?php
namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
use App\User;
use Auth;
use Hash;
use Illuminate\Http\Request;
use Yajra\Datatables\Datatables;
class UserController extends Controller
{
/**
* Users list page
*
* @param Illuminate\Http\Request
* @return view
*/
public function Users(Request $Request)
{
return view('user.list');
}
/**
* Fetch Users
*/
public function fetchUsers(){
// return json_encode(User::all());
# users list
$Users = User::where('is_deleted', 'N')->get();
return DataTables::of($Users)
->editColumn('created_at', function ($Users)
{
$date = date("Y-m-d", strtotime($Users->created_at));
return $date;
})->addColumn('update', function ($Users)
{
return $return = '<a class="btn btn-primary" href="'. url('update-user').'/'.encrypt($Users->id).'" >Update</a>';
})->addColumn('delete', function ($Users)
{
return $return = '<button data-id="'. encrypt($Users->id) .'" class="btn delete-user btn-danger">Delete</button>';
})->rawColumns(['update', 'delete'])->make(true);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment