Update Module User
- Add Nik and branch,
This commit is contained in:
parent
18f0f68f1a
commit
d3baaa31c1
@ -20,6 +20,8 @@ class UsersExport implements WithColumnFormatting, WithHeadings, FromCollection,
|
|||||||
$row->id,
|
$row->id,
|
||||||
$row->name,
|
$row->name,
|
||||||
$row->email,
|
$row->email,
|
||||||
|
$row->nik,
|
||||||
|
$row->branch->name,
|
||||||
$row->created_at
|
$row->created_at
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
@ -28,6 +30,8 @@ class UsersExport implements WithColumnFormatting, WithHeadings, FromCollection,
|
|||||||
'ID',
|
'ID',
|
||||||
'Name',
|
'Name',
|
||||||
'Email',
|
'Email',
|
||||||
|
'NIK',
|
||||||
|
'Branch',
|
||||||
'Created At'
|
'Created At'
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
@ -35,7 +39,7 @@ class UsersExport implements WithColumnFormatting, WithHeadings, FromCollection,
|
|||||||
public function columnFormats(): array{
|
public function columnFormats(): array{
|
||||||
return [
|
return [
|
||||||
'A' => \PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_NUMBER,
|
'A' => \PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_NUMBER,
|
||||||
'C' => \PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_DATE_DATETIME
|
'F' => \PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_DATE_DATETIME
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
use App\Http\Controllers\Controller;
|
use App\Http\Controllers\Controller;
|
||||||
use Illuminate\Http\Request;
|
use Illuminate\Http\Request;
|
||||||
use Maatwebsite\Excel\Facades\Excel;
|
use Maatwebsite\Excel\Facades\Excel;
|
||||||
|
use Modules\Lpj\Models\Branch;
|
||||||
use Modules\Usermanagement\Exports\UsersExport;
|
use Modules\Usermanagement\Exports\UsersExport;
|
||||||
use Modules\Usermanagement\Http\Requests\User as UserRequest;
|
use Modules\Usermanagement\Http\Requests\User as UserRequest;
|
||||||
use Modules\Usermanagement\Models\Role;
|
use Modules\Usermanagement\Models\Role;
|
||||||
@ -73,7 +74,8 @@
|
|||||||
if ($request->has('search') && !empty($request->get('search'))) {
|
if ($request->has('search') && !empty($request->get('search'))) {
|
||||||
$search = $request->get('search');
|
$search = $request->get('search');
|
||||||
$query->where(function ($q) use ($search) {
|
$query->where(function ($q) use ($search) {
|
||||||
$q->where('name', 'LIKE', "%$search%")
|
$q
|
||||||
|
->where('name', 'LIKE', "%$search%")
|
||||||
->orWhere('email', 'LIKE', "%$search%");
|
->orWhere('email', 'LIKE', "%$search%");
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
@ -101,7 +103,7 @@
|
|||||||
$filteredRecords = $query->count();
|
$filteredRecords = $query->count();
|
||||||
|
|
||||||
// Get the data for the current page
|
// Get the data for the current page
|
||||||
$users = $query->get();
|
$users = $query->with('branch')->get();
|
||||||
|
|
||||||
// Calculate the page count
|
// Calculate the page count
|
||||||
$pageCount = ceil($totalRecords / $request->get('size'));
|
$pageCount = ceil($totalRecords / $request->get('size'));
|
||||||
@ -137,7 +139,8 @@
|
|||||||
|
|
||||||
$user = User::find($id);
|
$user = User::find($id);
|
||||||
$roles = Role::all();
|
$roles = Role::all();
|
||||||
return view('usermanagement::users.create', compact('user', 'roles'));
|
$branches = Branch::all();
|
||||||
|
return view('usermanagement::users.create', compact('user', 'roles', 'branches'));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -240,7 +243,8 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
$roles = Role::all();
|
$roles = Role::all();
|
||||||
return view('usermanagement::users.create', compact('roles'));
|
$branches = Branch::all();
|
||||||
|
return view('usermanagement::users.create', compact('roles', 'branches'));
|
||||||
}
|
}
|
||||||
|
|
||||||
public function export()
|
public function export()
|
||||||
|
@ -20,9 +20,11 @@
|
|||||||
public function rules()
|
public function rules()
|
||||||
: array
|
: array
|
||||||
{
|
{
|
||||||
|
|
||||||
$rules = [
|
$rules = [
|
||||||
'name' => 'required|string|max:255',
|
'name' => 'required|string|max:255',
|
||||||
|
'nik' => 'nullable|string|max:6|unique:users,nik',
|
||||||
|
'branch_id' => 'nullable|exists:branches,id',
|
||||||
|
'profile_photo_path' => 'nullable|image|mimes:jpeg,png,jpg|max:2048',
|
||||||
];
|
];
|
||||||
|
|
||||||
if ($this->password || $this->method() === 'POST') {
|
if ($this->password || $this->method() === 'POST') {
|
||||||
@ -40,7 +42,7 @@
|
|||||||
public function passedValidation()
|
public function passedValidation()
|
||||||
{
|
{
|
||||||
$this->merge([
|
$this->merge([
|
||||||
'password' => Hash::make($this->password)
|
'password' => Hash::make($this->password),
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -5,6 +5,7 @@
|
|||||||
use Illuminate\Database\Eloquent\SoftDeletes;
|
use Illuminate\Database\Eloquent\SoftDeletes;
|
||||||
use Illuminate\Foundation\Auth\User as Authenticatable;
|
use Illuminate\Foundation\Auth\User as Authenticatable;
|
||||||
use Illuminate\Notifications\Notifiable;
|
use Illuminate\Notifications\Notifiable;
|
||||||
|
use Modules\Lpj\Models\Branch;
|
||||||
use Spatie\Permission\Traits\HasRoles;
|
use Spatie\Permission\Traits\HasRoles;
|
||||||
use Wildside\Userstamps\Userstamps;
|
use Wildside\Userstamps\Userstamps;
|
||||||
|
|
||||||
@ -38,6 +39,11 @@
|
|||||||
'name',
|
'name',
|
||||||
'email',
|
'email',
|
||||||
'password',
|
'password',
|
||||||
|
'nik',
|
||||||
|
'branch_id',
|
||||||
|
'profile_photo_path',
|
||||||
|
'last_login_at',
|
||||||
|
'last_login_ip',
|
||||||
];
|
];
|
||||||
|
|
||||||
/**
|
/**
|
||||||
@ -69,5 +75,9 @@
|
|||||||
'id' => 'string',
|
'id' => 'string',
|
||||||
];
|
];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public function branch(){
|
||||||
|
return $this->belongsTo(Branch::class);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
32
database/migrations/2024_08_27_071158_update_users_table.php
Normal file
32
database/migrations/2024_08_27_071158_update_users_table.php
Normal file
@ -0,0 +1,32 @@
|
|||||||
|
<?php
|
||||||
|
|
||||||
|
use Illuminate\Database\Migrations\Migration;
|
||||||
|
use Illuminate\Database\Schema\Blueprint;
|
||||||
|
use Illuminate\Support\Facades\Schema;
|
||||||
|
use Modules\Lpj\Models\Branch;
|
||||||
|
|
||||||
|
return new class extends Migration
|
||||||
|
{
|
||||||
|
/**
|
||||||
|
* Run the migrations.
|
||||||
|
*/
|
||||||
|
public function up(): void
|
||||||
|
{
|
||||||
|
Schema::table('users', function (Blueprint $table) {
|
||||||
|
$table->string('nik')->nullable()->after('email');
|
||||||
|
$table->foreignIdFor(Branch::class)->nullable()->after('nik')->constrained('branches');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reverse the migrations.
|
||||||
|
*/
|
||||||
|
public function down(): void
|
||||||
|
{
|
||||||
|
Schema::table('users', function (Blueprint $table) {
|
||||||
|
$table->dropColumn('nik');
|
||||||
|
$table->dropForeign(['branch_id']);
|
||||||
|
$table->dropColumn('branch_id');
|
||||||
|
});
|
||||||
|
}
|
||||||
|
};
|
@ -20,7 +20,7 @@
|
|||||||
"classes": "",
|
"classes": "",
|
||||||
"attributes": [],
|
"attributes": [],
|
||||||
"permission": "",
|
"permission": "",
|
||||||
"roles": [],
|
"roles": ["Administrator"],
|
||||||
"sub": [
|
"sub": [
|
||||||
{
|
{
|
||||||
"title": "Users",
|
"title": "Users",
|
||||||
|
@ -52,6 +52,43 @@
|
|||||||
@enderror
|
@enderror
|
||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
<div class="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
|
||||||
|
<label class="form-label max-w-56">
|
||||||
|
NIK
|
||||||
|
</label>
|
||||||
|
<div class="flex flex-wrap items-baseline w-full">
|
||||||
|
<input class="w-full input @error('nik') border-danger @enderror" type="number" name="nik" value="{{ $user->nik ?? '' }}">
|
||||||
|
@error('nik')
|
||||||
|
<em class="alert text-danger text-sm">{{ $message }}</em>
|
||||||
|
@enderror
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div class="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
|
||||||
|
<label class="form-label max-w-56">
|
||||||
|
Branch
|
||||||
|
</label>
|
||||||
|
<div class="flex flex-wrap items-baseline w-full">
|
||||||
|
<select class="input tomselect w-full @error('branch_id') border-danger @enderror" name="branch_id" id="branch_id">
|
||||||
|
<option value="">Pilih Branch</option>
|
||||||
|
@if(isset($branches))
|
||||||
|
@foreach($branches as $row)
|
||||||
|
@if(isset($user))
|
||||||
|
<option value="{{ $row->id }}" {{ isset($user->branch_id) && $user->branch_id == $row->id?'selected' : '' }}>
|
||||||
|
{{ $row->name }}
|
||||||
|
</option>
|
||||||
|
@else
|
||||||
|
<option value="{{ $row->id }}">
|
||||||
|
{{ $row->name }}
|
||||||
|
</option>
|
||||||
|
@endif
|
||||||
|
@endforeach
|
||||||
|
@endif
|
||||||
|
</select>
|
||||||
|
@error('branch_id')
|
||||||
|
<em class="alert text-danger text-sm">{{ $message }}</em>
|
||||||
|
@enderror
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
<div class="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
|
<div class="flex items-baseline flex-wrap lg:flex-nowrap gap-2.5">
|
||||||
<label class="form-label max-w-56">
|
<label class="form-label max-w-56">
|
||||||
Password
|
Password
|
||||||
|
@ -64,6 +64,14 @@
|
|||||||
<span class="sort"> <span class="sort-label"> Email </span>
|
<span class="sort"> <span class="sort-label"> Email </span>
|
||||||
<span class="sort-icon"> </span> </span>
|
<span class="sort-icon"> </span> </span>
|
||||||
</th>
|
</th>
|
||||||
|
<th class="min-w-[185px]" data-datatable-column="nik">
|
||||||
|
<span class="sort"> <span class="sort-label"> NIK </span>
|
||||||
|
<span class="sort-icon"> </span> </span>
|
||||||
|
</th>
|
||||||
|
<th class="min-w-[185px]" data-datatable-column="branch">
|
||||||
|
<span class="sort"> <span class="sort-label"> Branch </span>
|
||||||
|
<span class="sort-icon"> </span> </span>
|
||||||
|
</th>
|
||||||
<th class="min-w-[50px] text-center" data-datatable-column="actions">Action</th>
|
<th class="min-w-[50px] text-center" data-datatable-column="actions">Action</th>
|
||||||
</tr>
|
</tr>
|
||||||
</thead>
|
</thead>
|
||||||
@ -145,6 +153,15 @@
|
|||||||
email: {
|
email: {
|
||||||
title: 'Email',
|
title: 'Email',
|
||||||
},
|
},
|
||||||
|
nik: {
|
||||||
|
title: 'NIK',
|
||||||
|
},
|
||||||
|
branch: {
|
||||||
|
title: 'Branch',
|
||||||
|
render: (item, data) => {
|
||||||
|
return data.branch.name;
|
||||||
|
},
|
||||||
|
},
|
||||||
actions: {
|
actions: {
|
||||||
title: 'Status',
|
title: 'Status',
|
||||||
render: (item, data) => {
|
render: (item, data) => {
|
||||||
|
Loading…
Reference in New Issue
Block a user