1.修改Nova配置文件config/nova.php
//guard修改为admin
'guard' => env('NOVA_GUARD', 'admin'),
Nova配置文件
config/nova.php
路径和名字也可以改了
//后台名称
'name' => 'Nova Site',
//后台路径,访问改为http://xxx.xxx.xxx/admin
'path' => '/admin',
2.添加guard守护,config/auth.php
的guards
和providers
添加如下
'guards' => [
'web' => [
'driver' => 'session',
'provider' => 'users',
],
'admin' => [
'driver' => 'session',
'provider' => 'admins',
],
'api' => [
'driver' => 'token',
'provider' => 'users',
],
],
//
'providers' => [
'users' => [
'driver' => 'eloquent',
'model' => App\User::class,
],
'admins' => [
'driver' => 'eloquent',
'model' => App\Model\Admin::class,
],
// 'users' => [
// 'driver' => 'database',
// 'table' => 'users',
// ],
],
3.修改app/Model/admin.php
<?php
namespace App\Model;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Notifications\Notifiable;
use Illuminate\Foundation\Auth\User as Authenticatable;
class Admin extends Authenticatable
{
use Notifiable;
//
}
4.新建Admin-resource 资源**
php artisan nova:resource Admin
修改app/Nova/Admin.php
<?php
namespace App\Nova;
use Laravel\Nova\Fields\ID;
use Laravel\Nova\Fields\Text;
use Laravel\Nova\Fields\Password;
use Illuminate\Http\Request;
class Admin extends Resource
{
/**
* The model the resource corresponds to.
*
* @var string
*/
public static $model = 'App\\Model\\Admin';
/**
* 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', 'nickname',
];
/**
* Get the fields displayed by the resource.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function fields(Request $request)
{
return [
ID::make()->sortable(),
Text::make('昵称','nickname')
->sortable()
->rules('required', 'max:255'),
Text::make('账号','name')
->sortable()
->rules('required', 'max:255'),
Password::make('Password')
->onlyOnForms()
->creationRules('required', 'string', 'min:6')
->updateRules('nullable', 'string', 'min:6'),
];
}
/**
* 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 [];
}
}
如果admins表没有创建email字段,搜索应取消email字段,否则搜索报错
fields
可以调整一下,avatar和email不用了,有nickname可以加进去
资源本地化,添加一个label方法
public static function label()
{
return __('管理员');
}
现在Nova后台可以直接使用admin表登录,这样与User用户分开使用
基本本地化使用差不多了。。。