working on omis setup

This commit is contained in:
2024-04-07 17:59:05 +05:45
parent 4f34db3381
commit 09222c8a3a
43 changed files with 237 additions and 2190 deletions

View File

@ -6,12 +6,20 @@ use App\Http\Controllers\Controller;
use App\Models\User;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Modules\User\Repositories\UserRepository;
class UserController extends Controller
{
/**
* Display a listing of the resource.
*/
protected $userRepository;
public function __construct(UserRepository $userRepository){
$this->userRepository = $userRepository;
}
public function index()
{
$data = User::latest()->get();
@ -25,6 +33,7 @@ class UserController extends Controller
public function create()
{
$data['title'] = "Create User";
$data['users'] = User::latest()->get();
return view('user::create', $data);
}
@ -33,12 +42,21 @@ class UserController extends Controller
*/
public function store(Request $request): RedirectResponse
{
//
$validatedData = $request->validate([
'name' => 'required|min:5',
'email' => 'required',
'password' => 'required',
]);
$user = $this->userRepository->create($validatedData, $request->role);
toastr()->success('User has been created!');
return redirect()->route('users.index');
}
/**
* Show the specified resource.
*/
public function show($id)
{
return view('user::show');

View File

@ -0,0 +1,12 @@
<?php
namespace Modules\User\Repositories;
interface UserInterface
{
public function findAll();
public function getUserById($userId);
public function delete($userId);
public function create(array $UserDetails, array $role);
public function update($userId, array $newDetails);
}

View File

@ -0,0 +1,35 @@
<?php
namespace Modules\User\Repositories;
use App\Models\User;
class UserRepository implements UserInterface
{
public function findAll()
{
return User::get();
}
public function getUserById($userId)
{
return User::findOrFail($userId);
}
public function delete($userId)
{
User::destroy($userId);
}
public function create(array $userDetails, array $role)
{
$user = User::create($userDetails);
return $user->roles()->attach($role);
}
public function update($userId, array $newDetails)
{
return User::whereId($userId)->update($newDetails);
}
}

View File

@ -0,0 +1,28 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::table('users', function (Blueprint $table) {
$table->unsignedInteger('employee_id');
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::table('users', function (Blueprint $table) {
});
}
};

View File

@ -15,13 +15,12 @@
<li class="breadcrumb-item active">{{ $title }}</li>
</ol>
</div>
</div>
</div>
</div>
<!-- end page title -->
<div class="row">
<div class="col-lg-8">
<div class="col-lg-12">
<div class="card">
<div class="card-body">
<form action="{{ route('user.store') }}" class="needs-validation" novalidate method="post">

View File

@ -6,56 +6,46 @@
<div class="col-lg-12">
<div class="card">
<div class="card-header d-flex justify-content-between align-items-center">
<h4>{{ label('Users List') }}</h4>
<a href="{{ route('user.create') }}" class="btn btn-info"><span>{{ label('Create New') }}</span></a>
<div class="card-header d-flex justify-content-between align-users-center">
<h5 class="card-title flex-grow-1 mb-0">User Lists</h5>
<a href="{{ route('user.create') }}" class="btn btn-info btn-sm"><span>Add New</span></a>
</div>
<div class="card-body">
<div class="table-responsive">
<table id="buttons-datatables" class="display table-sm table-bordered table" style="width:100%">
<thead class="">
<tr>
<th class="tb-col"><span class="overline-title">{{ label('Sn.') }}</span></th>
<th class="tb-col"><span class="overline-title">{{ label('Name') }}</span></th>
<th class="tb-col"><span class="overline-title">{{ label('Email') }}</span></th>
<th class="tb-col"><span class="overline-title">{{ label('User Name') }}</span></th>
<th class="tb-col"><span class="overline-title">{{ label('Role') }}</span></th>
<th class="tb-col"><span class="overline-title">{{ label('Branch') }}</span></th>
<th class="tb-col"><span class="overline-title">{{ label('Employee') }}</span></th>
<th class="tb-col" data-sortable="false"><span class="overline-title">{{ label('Action') }}</span>
<th class="tb-col"><span class="overline-title">S.N</span></th>
<th class="tb-col"><span class="overline-title">Name</span></th>
<th class="tb-col"><span class="overline-title">Email</span></th>
<th class="tb-col"><span class="overline-title">Employee</span></th>
<th class="tb-col"><span class="overline-title">Role</span></th>
{{-- <th class="tb-col"><span class="overline-title">Branch</span></th> --}}
<th class="tb-col" data-sortable="false"><span class="overline-title">Action</span>
</th>
</tr>
</thead>
<tbody>
@php
$i = 1;
@endphp
@foreach ($data as $item)
<tr data-id="{{ $item->id }}" data-display_order="{{ $item->display_order }}"
@foreach ($data as $index => $user)
<tr data-id="{{ $user->id }}" data-display_order="{{ $user->display_order }}"
class="draggable-row">
<td class="tb-col">{{ $i++ }}</td>
<td class="tb-col">{{ $item->name }}</td>
<td class="tb-col">{{ $item->email }}</td>
<td class="tb-col">{{ $item->username }}</td>
<td class="tb-col">{!! getFieldData('tbl_roles', 'title', 'role_id', $item->roles_id) !!}
<td class="tb-col">{!! getFieldData('tbl_branches', 'title', 'branch_id', $item->branches_id) !!}
<td class="tb-col">{!! getFieldData('tbl_employees', 'title', 'employee_id', $item->employees_id) !!}
</td>
<td class="tb-col">{{ $index + 1 }}</td>
<td class="tb-col">{{ $user->name }}</td>
<td class="tb-col">{{ $user->email }}</td>
<td class="tb-col">{{ optional($user->employee)->employee_id }}</td>
<td class="tb-col">{{ $user->roles->first()->id }}</td>
<td class="tb-col">
<div class="hstack flex-wrap gap-3">
<a href="javascript:void(0);" class="link-info fs-15 view-item-btn" data-bs-toggle="modal"
<a href="javascript:void(0);" class="link-info fs-15 view-user-btn" data-bs-toggle="modal"
data-bs-target="#viewModal">
<i class="ri-eye-line"></i>
</a>
<a href="{{ route('user.edit', $item->id) }}" class="link-success fs-15 edit-item-btn"><i
<a href="{{ route('user.edit', $user->id) }}" class="link-success fs-15 edit-user-btn"><i
class="ri-edit-2-line"></i></a>
<a href="javascript:void(0);" data-link="{{ route('user.destroy', $item->id) }}"
data-id="{{ $item->id }}" class="link-danger fs-15 remove-item-btn"><i
<a href="javascript:void(0);" data-link="{{ route('user.destroy', $user->id) }}"
data-id="{{ $user->id }}" class="link-danger fs-15 remove-user-btn"><i
class="ri-delete-bin-line"></i></a>
</div>
</td>
</tr>

View File

@ -1,23 +1,33 @@
<div class="mb-3">
<label for="name" class="form-label">Name</label>
<input type="text" class="form-control" id="name" placeholder="Enter name" name="name"
value="{{ old('end_date', $leave->name ?? '') }}" required>
<div class="invalid-feedback">
Please enter employee name.
<div class="row gy-4">
<div class="col-md-4">
{{ html()->label('For Employee')->class('form-label') }}
{{ html()->select('employee_id', ['1', '2'])->class('form-select')->placeholder('Select Employee')->required() }}
</div>
</div>
<div class="mb-3">
<label for="email" class="form-label">Email</label>
<input type="text" class="form-control" id="email" name="email"
value="{{ old('email', $leave->email ?? '') }}">
</div>
<div class="col-md-4">
{{ html()->label('Role')->class('form-label') }}
{{ html()->select('role_id', ['1', '2'])->class('form-select')->placeholder('Select Role')->required() }}
</div>
<div class="col-md-4">
{{ html()->label('Username')->class('form-label') }}
{{ html()->text('name')->class('form-control')->placeholder('Enter Username')->required() }}
</div>
<div class="col-md-4">
{{ html()->label('Email')->class('form-label') }}
{{ html()->email('email')->class('form-control')->placeholder('Enter Email')->required() }}
</div>
<div class="col-md-4">
{{ html()->label('Password')->class('form-label') }}
{{ html()->password('password')->class('form-control')->placeholder('Enter Password')->required() }}
</div>
</div>
<div class="text-end">
<button type="submit" class="btn btn-primary">{{ $btnType }}</button>
</div>
@push('js')
<script src="{{ asset('assets/js/pages/form-validation.init.js') }}"></script>
@endpush