php 具有自定义访问器的Laravel Nova用户资源
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 具有自定义访问器的Laravel Nova用户资源相关的知识,希望对你有一定的参考价值。
<?php
namespace App\Nova;
use Illuminate\Http\Request;
use Laravel\Nova\Fields\Gravatar;
use Laravel\Nova\Fields\ID;
use Laravel\Nova\Fields\MorphToMany;
use Laravel\Nova\Fields\Password;
use Laravel\Nova\Fields\Text;
class User extends Resource
{
/**
* The logical group associated with the resource.
*
* @var string
*/
public static $group = 'Administration';
/**
* The model the resource corresponds to.
*
* @var string
*/
public static $model = 'App\\User';
/**
* The single value that should be used to represent the resource when being displayed.
*
* @var string
*/
public static $title = 'name';
/**
* The columns that should be searched.
*
* @var array
*/
public static $search = [
'id', 'name', 'email',
];
/**
* The relationships that should be eager loaded on index queries.
*
* @var array
*/
public static $with = ['roles', 'permissions'];
/**
* Get the fields displayed by the resource.
*
* @param \Illuminate\Http\Request $request
*
* @return array
*/
public function fields(Request $request)
{
return [
ID::make()
->hideFromIndex()
->hideFromDetail()
->sortable(),
Gravatar::make(),
Text::make('Name')
->sortable()
->rules('required', 'max:255'),
Text::make('Email')
->sortable()
->rules('required', 'email', 'max:254')
->creationRules('unique:users,email')
->updateRules('unique:users,email,{{resourceId}}'),
Password::make('Password')
->onlyOnForms()
->creationRules('required', 'string', 'min:6')
->updateRules('nullable', 'string', 'min:6'),
Text::make('Roles', 'role_names')
->exceptOnForms(),
MorphToMany::make(
'Roles',
'roles',
\Vyuldashev\NovaPermission\Role::class
),
MorphToMany::make(
'Permissions',
'permissions',
\Vyuldashev\NovaPermission\Permission::class
),
];
}
/**
* Get the cards available for the request.
*
* @param \Illuminate\Http\Request $request
*
* @return array
*/
public function cards(Request $request)
{
return [];
}
/**
* Get the filters available for the resource.
*
* @param \Illuminate\Http\Request $request
*
* @return array
*/
public function filters(Request $request)
{
return [];
}
/**
* Get the lenses available for the resource.
*
* @param \Illuminate\Http\Request $request
*
* @return array
*/
public function lenses(Request $request)
{
return [];
}
/**
* Get the actions available for the resource.
*
* @param \Illuminate\Http\Request $request
*
* @return array
*/
public function actions(Request $request)
{
return [];
}
}
以上是关于php 具有自定义访问器的Laravel Nova用户资源的主要内容,如果未能解决你的问题,请参考以下文章
php 具有Spatie Peermission包的Laravel Nova用户模型
Laravel Nova:如何创建自定义字段及其 crud 方法?