1. Go to this page and download the library: Download hthang369/laravel-grid library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
class UsersController extends Controller
{
/**
* Display a listing of the resource.
*
* @param UsersGridInterface $usersGrid
* @param Request $request
* @return \Illuminate\Http\Response
*/
public function index(UsersGridInterface $usersGrid, Request $request)
{
// the 'query' argument needs to be an instance of the eloquent query builder
// you can load relationships at this point
return $usersGrid
->create(['query' => User::query(), 'request' => $request])
->renderOn('welcome'); // render the grid on the welcome view
}
}
/**
* Register any application services.
*
* @return void
*/
public function register()
{
$this->app->bind(UsersGridInterface::class, UsersGrid::class);
}
/**
* Display a listing of the resource.
*
* @param Request $request
* @return \Illuminate\Http\Response
*/
public function index(Request $request)
{
$user = $request->user();
return (new UsersGrid(['user' => $user])) // you can then use it as $this->user within the class. It's set implicitly using the __set() call
->create(['query' => User::query(), 'request' => $request])
->renderOn('welcome');
}
/**
* Display a listing of the resource.
*
* @param Request $request
* @return \Illuminate\Http\Response
*/
public function index(Request $request)
{
$data = 'hello world';
return (new UsersGrid())
->create(['query' => User::query(), 'request' => $request])
->renderOn('welcome', compact('data'));
}
class UsersController extends Controller
{
/**
* Display a listing of the resource.
*
* @param UsersGridInterface $usersGrid
* @param Request $request
* @return \Illuminate\Http\Response
*/
public function index(UsersGridInterface $usersGrid, Request $request)
{
// load relationships
$query = User::with(['posts', 'activities'])
return $usersGrid
->create(['query' => $query, 'request' => $request])
->renderOn('welcome');
}
}