Skip to content

Commit

Permalink
add emp user
Browse files Browse the repository at this point in the history
  • Loading branch information
xxl4 committed Sep 27, 2023
1 parent e45ed89 commit 507612b
Show file tree
Hide file tree
Showing 5 changed files with 62 additions and 125 deletions.
2 changes: 1 addition & 1 deletion config/admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -185,7 +185,7 @@

//Emp user tables and model
'emp_users_table' => 'admin_emp_users',
'emp_users_model' => Nicelizhi\Admin\Auth\Database\EmpUsers::class,
'emp_users_model' => Nicelizhi\Admin\Auth\Database\EmpUser::class,

// area tables and model
'area_table' => 'admin_area',
Expand Down
2 changes: 1 addition & 1 deletion src/Admin.php
Original file line number Diff line number Diff line change
Expand Up @@ -323,7 +323,7 @@ public function routes()
$router->resource('auth/menu', 'MenuController', ['except' => ['create']])->names('admin.auth.menu');
$router->resource('auth/logs', 'LogController', ['only' => ['index', 'destroy']])->names('admin.auth.logs');
$router->resource('auth/emp', 'EmpController', ['except' => ['create']])->names('admin.auth.emp');
$router->resource('auth/emp_users', 'EmpUsersController', ['except' => ['create']])->names('admin.auth.emp_users');
$router->resource('auth/emp-users', 'EmpUsersController')->names('admin.auth.emp_users');

$router->post('_handle_form_', 'HandleController@handleForm')->name('admin.handle-form');
$router->post('_handle_action_', 'HandleController@handleAction')->name('admin.handle-action');
Expand Down
40 changes: 40 additions & 0 deletions src/Auth/Database/EmpUser.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

namespace Nicelizhi\Admin\Auth\Database;

use Nicelizhi\Admin\Traits\DefaultDatetimeFormat;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;

class EmpUser extends Model
{
use DefaultDatetimeFormat;

protected $fillable = ['user_id', 'emp_name'];

/**
* Create a new Eloquent model instance.
*
* @param array $attributes
*/
public function __construct(array $attributes = [])
{
$connection = config('admin.database.connection') ?: config('database.default');

$this->setConnection($connection);

$this->setTable(config('admin.database.emp_users_table'));

parent::__construct($attributes);
}

/**
* Detach models from the relationship.
*
* @return void
*/
protected static function boot()
{
parent::boot();
}
}
112 changes: 0 additions & 112 deletions src/Auth/Database/EmpUsers.php

This file was deleted.

31 changes: 20 additions & 11 deletions src/Controllers/EmpUsersController.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ class EmpUsersController extends AdminController
*/
protected function title()
{
return trans('admin.roles');
return trans('admin.emp-users');
}

/**
Expand All @@ -23,9 +23,9 @@ protected function title()
*/
protected function grid()
{
$roleModel = config('admin.database.emp_users_model');
$Model = config('admin.database.emp_users_model');

$grid = new Grid(new $roleModel());
$grid = new Grid(new $Model());

$grid->column('id', 'ID')->sortable();
$grid->column('emp_name', trans('admin.slug'));
Expand Down Expand Up @@ -64,9 +64,9 @@ protected function grid()
*/
protected function detail($id)
{
$roleModel = config('admin.database.emp_users_model');
$Model = config('admin.database.emp_users_model');

$show = new Show($roleModel::findOrFail($id));
$show = new Show($Model::findOrFail($id));

$show->field('id', 'ID');
$show->field('slug', trans('admin.slug'));
Expand All @@ -87,16 +87,25 @@ protected function detail($id)
*/
public function form()
{
$permissionModel = config('admin.database.permissions_model');
$roleModel = config('admin.database.roles_model');
//$permissionModel = config('admin.database.permissions_model');
$Model = config('admin.database.emp_users_model');

$form = new Form(new $roleModel());
$form = new Form(new $Model());

$form->display('id', 'ID');

$form->text('slug', trans('admin.slug'))->rules('required');
$form->text('name', trans('admin.name'))->rules('required');
$form->listbox('permissions', trans('admin.permissions'))->options($permissionModel::all()->pluck('name', 'id'));
$form->text('emp_name', trans('admin.emp_name'))->rules('required');
$form->text('emp_name_en', trans('admin.emp_name_en'));
$form->text('office_code', trans('admin.office_code'));
$form->text('office_name', trans('admin.office_name'));
$form->text('company_code', trans('admin.company_code'));
$form->text('company_name', trans('admin.company_name'));
$form->text('remarks', trans('admin.remarks'));
$form->text('corp_code', trans('admin.corp_code'));
$form->text('corp_name', trans('admin.corp_name'));

//$form->text('name', trans('admin.name'))->rules('required');
//$form->listbox('permissions', trans('admin.permissions'))->options($permissionModel::all()->pluck('name', 'id'));

$form->display('created_at', trans('admin.created_at'));
$form->display('updated_at', trans('admin.updated_at'));
Expand Down

0 comments on commit 507612b

Please sign in to comment.