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守護(hù)往枣,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表沒有創(chuàng)建email字段肛根,搜索應(yīng)取消email字段,否則搜索報錯
fields
可以調(diào)整一下活鹰,avatar和email不用了哈恰,有nickname可以加進(jìn)去
資源本地化,添加一個label方法
public static function label()
{
return __('管理員');
}
現(xiàn)在Nova后臺可以直接使用admin表登錄志群,這樣與User用戶分開使用
基本本地化使用差不多了蕊蝗。。赖舟。