使用laravel-admin grid 大多时候我们单表model或者多表简单联接(参考 model如何联表)就可以满足我们的需求了。一些特殊需求时不得不使用比较复杂的查询结果作为grid的数据源,接下来看看如何使用。
首先同样要先创建一个model:
$> php artisan make:model AppModelsUser
然后编辑model文件:
通过覆盖模型的paginate和with方法获取数据。
<?phpnamespace AppAdminModels;use IlluminateSupportFacadesDB;use IlluminateSupportFacadesRequest;use IlluminatePaginationLengthAwarePaginator;use EncoreAdminGridColumn;/** * Class User * * @property mixed id * @property mixed name * @property mixed nick * @property mixed profile * @property mixed created_at * * @method Column id(string $fieldName) * @method Column name(string $fieldName) * @method Column nick(string $fieldName) * @method Column profile(string $fieldName) * @method Column created_at(string $fieldName) * * @package AppAdminModelsAbstractModel */class User extends Abstr