Created
June 25, 2020 14:39
-
-
Save infinitbility/209ce03cda17523650a7e69fbed91563 to your computer and use it in GitHub Desktop.
Datatable controller example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?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