Initial Commit

This commit is contained in:
Daeng Deni Mardaeni
2024-08-07 08:47:07 +07:00
commit 225b326a5e
60 changed files with 3408 additions and 0 deletions

View File

@@ -0,0 +1,38 @@
<?php
namespace Modules\Usermanagement\Exports;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithColumnFormatting;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\WithMapping;
use Modules\Usermanagement\Models\Role;
class RolesExport implements WithColumnFormatting, WithHeadings, FromCollection, withMapping
{
public function collection(){
return Role::all();
}
public function map($row): array{
return [
$row->id,
$row->name,
$row->created_at
];
}
public function headings(): array{
return [
'ID',
'Role',
'Created At'
];
}
public function columnFormats(): array{
return [
'A' => \PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_NUMBER,
'C' => \PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_DATE_DATETIME
];
}
}

View File

@@ -0,0 +1,41 @@
<?php
namespace Modules\Usermanagement\Exports;
use Maatwebsite\Excel\Concerns\FromCollection;
use Maatwebsite\Excel\Concerns\WithHeadings;
use Maatwebsite\Excel\Concerns\WithMapping;
use PhpOffice\PhpSpreadsheet\Style\NumberFormat;
use Maatwebsite\Excel\Concerns\WithColumnFormatting;
use Modules\Usermanagement\Models\User;
class UsersExport implements WithColumnFormatting, WithHeadings, FromCollection, withMapping
{
public function collection(){
return User::all();
}
public function map($row): array{
return [
$row->id,
$row->name,
$row->email,
$row->created_at
];
}
public function headings(): array{
return [
'ID',
'Name',
'Email',
'Created At'
];
}
public function columnFormats(): array{
return [
'A' => \PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_NUMBER,
'C' => \PhpOffice\PhpSpreadsheet\Style\NumberFormat::FORMAT_DATE_DATETIME
];
}
}

View File

View File

@@ -0,0 +1,69 @@
<?php
namespace Modules\Usermanagement\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
class PermissionsController extends Controller
{
/**
* Display a listing of the resource.
*
* @return \Illuminate\Contracts\View\View
* @return \Illuminate\Contracts\View\Factory
*/
public function index()
{
return view('usermanagement::index');
}
/**
* Show the form for creating a new resource.
*
* This function is responsible for displaying the form to create a new resource.
* It returns the view for creating a new resource, which is located at 'usermanagement::create'.
*
* @return \Illuminate\Contracts\View\View|\Illuminate\Contracts\View\Factory
* @return \Illuminate\Contracts\View\View
*/
public function create()
{
return view('usermanagement::create');
}
public function store(Request $request)
: RedirectResponse
{
//
}
public function show($id)
{
return view('usermanagement::show');
}
public function edit($id)
{
return view('usermanagement::edit');
}
public function update(Request $request, $id)
: RedirectResponse
{
//
}
public function destroy($id)
{
//
}
}

View File

@@ -0,0 +1,291 @@
<?php
namespace Modules\Usermanagement\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Maatwebsite\Excel\Facades\Excel;
use Modules\Usermanagement\Exports\RolesExport;
use Modules\Usermanagement\Http\Requests\RoleRequest;
use Modules\Usermanagement\Models\Role;
/**
* Class RolesController
*
* This controller is responsible for managing user roles within the application.
*
* @package Modules\Usermanagement\Http\Controllers
*/
class RolesController extends Controller
{
/**
* @var \Illuminate\Contracts\Auth\Authenticatable|null
*/
public $user;
/**
* UsersController constructor.
*
* Initializes the user property with the authenticated user.
*
public function __construct()
{
$this->middleware(function ($request, $next) {
$this->user = Auth::guard('web')->user();
return $next($request);
});
}*/
/**
* Display a listing of the resource.
*
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
* @throws \Illuminate\Auth\Access\AuthorizationException
*/
public function index()
{
// Check if the authenticated user has the required permission to view roles
if (is_null($this->user) || !$this->user->can('roles.view')) {
//abort(403, 'Sorry! You are not allowed to view roles.');
}
// Fetch all roles from the database
$roles = Role::all();
// Return the view for displaying the roles
return view('usermanagement::roles.index', compact('roles'));
}
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
*
* @return \Illuminate\Http\RedirectResponse
* @throws \Illuminate\Auth\Access\AuthorizationException
*/
public function store(RoleRequest $request)
{
// Check if the authenticated user has the required permission to store roles
if (is_null($this->user) || !$this->user->can('roles.store')) {
//abort(403, 'Sorry! You are not allowed to store roles.');
}
// Create a new role using the provided request data
Role::create($request->all());
// Redirect back to the roles index with a success message
return redirect()->route('users.roles.index')->with('success', 'Role created successfully.');
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
* @throws \Illuminate\Auth\Access\AuthorizationException
*/
public function create()
{
// Check if the authenticated user has the required permission to create roles
if (is_null($this->user) || !$this->user->can('roles.create')) {
//abort(403, 'Sorry! You are not allowed to create roles.');
}
// Return the view for creating a new role
return view('usermanagement::roles.create');
}
/**
* Display the specified resource.
*
* @param int $id
*
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
* @throws \Illuminate\Auth\Access\AuthorizationException
*/
public function show($id)
{
// Check if the authenticated user has the required permission to view roles
if (is_null($this->user) || !$this->user->can('roles.view')) {
abort(403, 'Sorry! You are not allowed to view roles.');
}
// Fetch the specified role from the database
$role = Role::find($id);
// Return the view for displaying the role
return view('usermanagement::roles.show', compact('role'));
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
*
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
* @throws \Illuminate\Auth\Access\AuthorizationException
*/
public function edit($id)
{
// Check if the authenticated user has the required permission to edit roles
if (is_null($this->user) || !$this->user->can('roles.edit')) {
//abort(403, 'Sorry! You are not allowed to edit roles.');
}
// Fetch the specified role from the database
$role = Role::find($id);
// Return the view for editing the role
return view('usermanagement::roles.create', compact('role'));
}
/**
* Update the specified role in storage.
*
* @param \Modules\Usermanagement\Http\Requests\RoleRequest $request The request object containing the role data.
* @param int $id The unique identifier of the role to be updated.
*
* @return \Illuminate\Http\RedirectResponse Redirects back to the roles index with a success message upon successful update.
*
* @throws \Illuminate\Auth\Access\AuthorizationException If the authenticated user does not have the required permission to update roles.
*/
public function update(RoleRequest $request, $id)
{
// Check if the authenticated user has the required permission to update roles
if (is_null($this->user) || !$this->user->can('roles.update')) {
//abort(403, 'Sorry! You are not allowed to update roles.');
}
// Fetch the specified role from the database
$role = Role::find($id);
// Update the role using the provided request data
$role->update($request->all());
// Redirect back to the roles index with a success message
return redirect()->route('users.roles.index')->with('success', 'Role updated successfully.');
}
/**
* Remove the specified resource from storage.
*
* @param int $id
*
* @return \Illuminate\Http\RedirectResponse
* @throws \Illuminate\Auth\Access\AuthorizationException
*/
public function destroy($id)
{
// Check if the authenticated user has the required permission to delete roles
if (is_null($this->user) || !$this->user->can('roles.delete')) {
//abort(403, 'Sorry! You are not allowed to delete roles.');
}
// Fetch the specified role from the database
$role = Role::find($id);
// Delete the role
$role->delete();
// Redirect back to the roles index with a success message
echo json_encode(['message' => 'User deleted successfully.', 'success' => true]);
}
/**
* Restore a deleted role.
*
* @param int $id
*
* @return \Illuminate\Http\RedirectResponse
* @throws \Illuminate\Auth\Access\AuthorizationException
*/
public function restore($id)
{
// Check if the authenticated user has the required permission to restore roles
if (is_null($this->user) || !$this->user->can('roles.restore')) {
abort(403, 'Sorry! You are not allowed to restore roles.');
}
// Fetch the specified role from the database
$role = Role::withTrashed()->find($id);
// Restore the role
$role->restore();
// Redirect back to the roles index with a success message
return redirect()->route('users.roles.index')->with('success', 'Role restored successfully.');
}
/**
* Process support datatables ajax request.
*
* @param \Illuminate\Http\Request $request
*
* @return \Illuminate\Http\JsonResponse
* @throws \Illuminate\Auth\Access\AuthorizationException
*/
public function dataForDatatables(Request $request)
{
if (is_null($this->user) || !$this->user->can('roles.view')) {
//abort(403, 'Sorry! You are not allowed to view users.');
}
// Retrieve data from the database
$query = Role::query();
// Apply search filter if provided
if ($request->has('search') && !empty($request->get('search'))) {
$search = $request->get('search');
$query->where(function ($q) use ($search) {
$q->where('name', 'LIKE', "%$search%");
});
}
// Apply sorting if provided
if ($request->has('sortOrder') && !empty($request->get('sortOrder'))) {
$order = $request->get('sortOrder');
$column = $request->get('sortField');
$query->orderBy($column, $order);
}
// Get the total count of records
$totalRecords = $query->count();
// Apply pagination if provided
if ($request->has('start') && $request->has('length')) {
$start = $request->get('start');
$length = $request->get('length');
$query->skip($start)->take($length);
}
// Get the filtered count of records
$filteredRecords = $query->count();
// Get the data for the current page
$roles = $query->get();
// Calculate the page count
$pageCount = ceil($totalRecords);
// Calculate the current page number
$currentPage = 0 + 1;
// Return the response data as a JSON object
return response()->json([
'draw' => $request->get('draw'),
'recordsTotal' => $totalRecords,
'recordsFiltered' => $filteredRecords,
'pageCount' => $pageCount,
'page' => $currentPage,
'totalCount' => $totalRecords,
'data' => $roles,
]);
}
public function export()
{
return Excel::download(new RolesExport, 'roles.xlsx');
}
}

View File

@@ -0,0 +1,249 @@
<?php
namespace Modules\Usermanagement\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Maatwebsite\Excel\Facades\Excel;
use Modules\Usermanagement\Exports\UsersExport;
use Modules\Usermanagement\Http\Requests\User as UserRequest;
use Modules\Usermanagement\Models\Role;
use Modules\Usermanagement\Models\User;
/**
* Class UsersController
*
* This controller is responsible for managing user within the application.
*
* @package Modules\Usermanagement\Http\Controllers
*/
class UsersController extends Controller
{
/**
* @var \Illuminate\Contracts\Auth\Authenticatable|null
*/
public $user;
/**
* UsersController constructor.
*
* Initializes the user property with the authenticated user.
*/
// public function __construct()
// {
// $this->middleware(function ($request, $next) {
// $this->user = Auth::guard('web')->user();
// return $next($request);
// });
// }
/**
* Display a listing of the resource.
*
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
* @throws \Illuminate\Auth\Access\AuthorizationException
*/
public function index()
{
if (is_null($this->user) || !$this->user->can('users.view')) {
//abort(403, 'Sorry! You are not allowed to view users.');
}
return view('usermanagement::users.index');
}
/**
* Process support datatables ajax request.
*
* @param \Illuminate\Http\Request $request
*
* @return \Illuminate\Http\JsonResponse
* @throws \Illuminate\Auth\Access\AuthorizationException
*/
public function dataForDatatables(Request $request)
{
if (is_null($this->user) || !$this->user->can('users.view')) {
//abort(403, 'Sorry! You are not allowed to view users.');
}
// Retrieve data from the database
$query = User::query();
// Apply search filter if provided
if ($request->has('search') && !empty($request->get('search'))) {
$search = $request->get('search');
$query->where(function ($q) use ($search) {
$q->where('name', 'LIKE', "%$search%")
->orWhere('email', 'LIKE', "%$search%");
});
}
// Apply sorting if provided
if ($request->has('sortOrder') && !empty($request->get('sortOrder'))) {
$order = $request->get('sortOrder');
$column = $request->get('sortField');
$query->orderBy($column, $order);
}
// Get the total count of records
$totalRecords = $query->count();
// Apply pagination if provided
if ($request->has('start') && $request->has('length')) {
$start = $request->get('start');
$length = $request->get('length');
$query->skip($start)->take($length);
}
// Get the filtered count of records
$filteredRecords = $query->count();
// Get the data for the current page
$users = $query->get();
// Calculate the page count
$pageCount = ceil($totalRecords);
// Calculate the current page number
$currentPage = 0 + 1;
// Return the response data as a JSON object
return response()->json([
'draw' => $request->get('draw'),
'recordsTotal' => $totalRecords,
'recordsFiltered' => $filteredRecords,
'pageCount' => $pageCount,
'page' => $currentPage,
'totalCount' => $totalRecords,
'data' => $users,
]);
}
/**
* Show the form for editing the specified resource.
*
* @param int $id
*
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
* @throws \Illuminate\Auth\Access\AuthorizationException
*/
public function edit($id)
{
if (is_null($this->user) || !$this->user->can('users.edit')) {
//abort(403, 'Sorry! You are not allowed to edit users.');
}
$user = User::find($id);
$roles = Role::all();
return view('usermanagement::users.create', compact('user', 'roles'));
}
/**
* Update the specified resource in storage.
*
* @param \Modules\Usermanagement\Http\Requests\User $request
* @param int $id
*
* @return \Illuminate\Http\RedirectResponse
* @throws \Illuminate\Auth\Access\AuthorizationException
*/
public function update(UserRequest $request, $id)
{
if (is_null($this->user) || !$this->user->can('users.update')) {
//abort(403, 'Sorry! You are not allowed to update users.');
}
$user = User::find($id);
$user->update($request->all());
return redirect()->route('users.index')->with('success', 'User updated successfully.');
}
/**
* Remove the specified resource from storage.
*
* @param int $id
*
* @return \Illuminate\Http\RedirectResponse
* @throws \Illuminate\Auth\Access\AuthorizationException
*/
public function destroy($id)
{
if (is_null($this->user) || !$this->user->can('users.delete')) {
//abort(403, 'Sorry! You are not allowed to delete users.');
}
$user = User::find($id);
$user->delete();
echo json_encode(['message' => 'User deleted successfully.', 'success' => true]);
}
/**
* Restore the specified resource from storage.
*
* @param int $id
*
* @return \Illuminate\Http\RedirectResponse
* @throws \Illuminate\Auth\Access\AuthorizationException
*/
public function restore($id)
{
if (is_null($this->user) || !$this->user->can('users.restore')) {
abort(403, 'Sorry! You are not allowed to restore users.');
}
$user = User::withTrashed()->find($id);
$user->restore();
return redirect()->route('users.index')->with('success', 'User restored successfully.');
}
/**
* Store a newly created resource in storage.
*
* This function handles the creation of a new user in the application. It validates the incoming request data,
* creates a new user record in the database, and redirects the user to the users index page with a success message.
*
* @param \Modules\Usermanagement\Http\Requests\User $request The incoming request containing the user data.
*
* @return \Illuminate\Http\RedirectResponse Redirects to the users index page with a success message upon successful creation.
* @return \Illuminate\Http\RedirectResponse Redirects to the users create page upon validation failure.
*/
public function store(UserRequest $request)
{
$validated = $request->validated();
if ($validated) {
$user = User::create($validated);
if ($user) {
return redirect()->route('users.index')->with('success', 'User created successfully.');
}
}
return redirect()->route('users.create');
}
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Contracts\View\Factory|\Illuminate\View\View
* @throws \Illuminate\Auth\Access\AuthorizationException
*/
public function create()
{
if (is_null($this->user) || !$this->user->can('users.create')) {
//abort(403, 'Sorry! You are not allowed to create a user.');
}
$roles = Role::all();
return view('usermanagement::users.create', compact('roles'));
}
public function export()
{
return Excel::download(new UsersExport, 'users.xlsx');
}
}

View File

@@ -0,0 +1,23 @@
<?php
namespace Modules\Usermanagement\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class ChangePassword extends FormRequest
{
/**
* Returns an array of validation rules for the password and current password fields.
*
* @return array The validation rules for the password and current password fields.
*/
public function rules()
: array
{
return [
'password' => 'required|string|min:8|confirmed',
'current_password' => 'required|string|min:8'
];
}
}

View File

@@ -0,0 +1,22 @@
<?php
namespace Modules\Usermanagement\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
class Login extends FormRequest
{
/**
* Returns an array of validation rules for the login form.
*
* @return array The validation rules.
*/
public function rules()
: array
{
return [
'email' => 'required|email',
'password' => 'required'
];
}
}

View File

@@ -0,0 +1,46 @@
<?php
namespace Modules\Usermanagement\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Facades\Hash;
class RoleRequest extends FormRequest
{
public function authorize()
{
return true;
}
/**
* Returns an array of validation rules for the registration form.
*
* @return array The validation rules.
*/
public function rules()
: array
{
$rules = [
'guard_names' => 'required|string|in:web,api',
];
if ($this->method() === 'PUT') {
$rules['name'] = 'required|string|max:255|unique:roles,name,' . $this->id;
} else {
$rules['name'] = 'required|string|max:255';
}
return $rules;
}
public function prepareForValidation()
{
$this->merge([
'guard_names' => 'web',
]);
}
}

View File

@@ -0,0 +1,49 @@
<?php
namespace Modules\Usermanagement\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
use Illuminate\Support\Facades\Hash;
class User extends FormRequest
{
public function authorize()
{
return true;
}
/**
* Returns an array of validation rules for the registration form.
*
* @return array The validation rules.
*/
public function rules()
: array
{
$rules = [
'name' => 'required|string|max:255',
];
if ($this->password || $this->method() === 'POST') {
$rules['email'] = 'required|email|unique:users,email';
$rules['password'] = 'required|string|min:8|confirmed';
}
if ($this->method() === 'PUT') {
$rules['email'] = 'required|email|unique:users,email,' . $this->id;
}
return $rules;
}
public function passedValidation()
{
$this->merge([
'password' => Hash::make($this->password)
]);
}
}

51
app/Models/Base.php Normal file
View File

@@ -0,0 +1,51 @@
<?php
namespace Modules\Usermanagement\Models;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\SoftDeletes;
use Spatie\Activitylog\LogOptions;
use Spatie\Activitylog\Traits\LogsActivity;
use Wildside\Userstamps\Userstamps;
/**
*
*/
class Base extends Model
{
use LogsActivity, SoftDeletes, Userstamps;
protected $connection;
/**
* Constructs a new instance of the class.
*
* @param array $attributes Optional attributes to initialize the object with.
*
* @return void
*/
public function __construct(array $attributes = [])
{
parent::__construct($attributes);
// Retrieve the module configuration from the module.json file
$modulePath = dirname(__FILE__, 3) . '/module.json';
$module = file_get_contents($modulePath);
$module = json_decode($module);
// Set the connection property to the database connection specified in the module configuration
$this->connection = $module->database;
}
/**
* Retrieves the activity log options for the User Management.
*
* @return LogOptions The activity log options.
*/
public function getActivitylogOptions()
: LogOptions
{
return LogOptions::defaults()->logAll()->useLogName('User Management : ');
}
}

33
app/Models/Permission.php Normal file
View File

@@ -0,0 +1,33 @@
<?php
namespace Modules\Usermanagement\Models;
use Spatie\Activitylog\LogOptions;
use Spatie\Activitylog\Traits\LogsActivity;
use Spatie\Permission\Models\Permission as SpatiePermission;
class Permission extends SpatiePermission
{
use LogsActivity;
/**
* Retrieve the activity log options for this permission.
*
* @return LogOptions The activity log options.
*/
public function getActivitylogOptions()
: LogOptions
{
return LogOptions::defaults()->logAll()->useLogName('User Management|Permissions : ');
}
/**
* Retrieve the permission group associated with this permission.
*
* @return \Illuminate\Database\Eloquent\Relations\BelongsTo The permission group relationship.
*/
public function group()
{
return $this->belongsTo(PermissionGroup::class, 'permission_group_id');
}
}

View File

@@ -0,0 +1,60 @@
<?php
namespace Modules\Usermanagement\Models;
use Spatie\Permission\Models\Role;
class PermissionGroup extends Base
{
protected $fillable = [
'name',
'slug'
];
/**
* Retrieves all permissions associated with a given permission group ID.
*
* @param int $id The ID of the permission group.
*
* @return \Illuminate\Database\Eloquent\Collection The collection of permissions.
*/
public static function getpermissionsByGroupId($id)
{
return Permission::where('permission_group_id', $id)->get();
}
/**
* Returns a relationship instance for the Permission model.
*
* @return \Illuminate\Database\Eloquent\Relations\HasMany
*/
public function permission()
{
return $this->hasMany(Permission::class);
}
/**
* Retrieves the roles associated with a given permission group.
*
* @param object $group The permission group object.
*
* @return array The array of roles associated with the permission group.
*/
public function roles($group)
{
$permission = Permission::where('permission_group_id', $group->id)->first();
$data = [];
$roles = Role::all();
foreach ($roles as $role) {
if ($role->hasPermissionTo($permission->name)) {
array_push($data, $role);
}
}
return $data;
}
}

25
app/Models/Role.php Normal file
View File

@@ -0,0 +1,25 @@
<?php
namespace Modules\Usermanagement\Models;
use Illuminate\Database\Eloquent\SoftDeletes;
use Spatie\Activitylog\LogOptions;
use Spatie\Activitylog\Traits\LogsActivity;
use Spatie\Permission\Models\Role as SpatieRole;
class Role extends SpatieRole
{
use softDeletes, LogsActivity;
/**
* Retrieve the activity log options for this role.
*
* @return LogOptions The activity log options.
*/
public function getActivitylogOptions()
: LogOptions
{
return LogOptions::defaults()->logAll()->useLogName('User Management|Roles : ');
}
}

73
app/Models/User.php Normal file
View File

@@ -0,0 +1,73 @@
<?php
namespace Modules\Usermanagement\Models;
use Illuminate\Database\Eloquent\SoftDeletes;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Spatie\Permission\Traits\HasRoles;
use Wildside\Userstamps\Userstamps;
/**
* Class User
*
* This class extends the Laravel's Authenticatable class and represents a User in the application.
* It includes traits for using factories, notifications, API tokens, and UUIDs.
*
* @property string $name The name of the user.
* @property string $email The email of the user.
* @property string $password The hashed password of the user.
* @property string $remember_token The token used for "remember me" functionality.
*
* @package App\Models
*/
class User extends Authenticatable
{
use Notifiable, Userstamps, HasRoles, softDeletes;
protected $guard_name = ['web'];
/**
* The attributes that are mass assignable.
*
* These are the attributes that can be set in bulk during a create or update operation.
*
* @var array<int, string>
*/
protected $fillable = [
'name',
'email',
'password',
];
/**
* The attributes that should be hidden for serialization.
*
* These are the attributes that will be hidden when the model is converted to an array or JSON.
*
* @var array<int, string>
*/
protected $hidden = [
'password',
'remember_token',
];
/**
* Get the attributes that should be cast.
*
* This method defines how the attributes should be cast when accessed.
* In this case, 'email_verified_at' is cast to 'datetime', 'password' is cast to 'hashed', and 'id' is cast to 'string'.
*
* @return array<string, string>
*/
protected function casts()
: array
{
return [
'email_verified_at' => 'datetime',
'password' => 'hashed',
'id' => 'string',
];
}
}

0
app/Providers/.gitkeep Normal file
View File

View File

@@ -0,0 +1,32 @@
<?php
namespace Modules\Usermanagement\Providers;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;
class EventServiceProvider extends ServiceProvider
{
/**
* The event handler mappings for the application.
*
* @var array<string, array<int, string>>
*/
protected $listen = [];
/**
* Indicates if events should be discovered.
*
* @var bool
*/
protected static $shouldDiscoverEvents = true;
/**
* Configure the proper event listeners for email verification.
*
* @return void
*/
protected function configureEmailVerification(): void
{
}
}

View File

@@ -0,0 +1,49 @@
<?php
namespace Modules\Usermanagement\Providers;
use Illuminate\Support\Facades\Route;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
class RouteServiceProvider extends ServiceProvider
{
/**
* Called before routes are registered.
*
* Register any model bindings or pattern based filters.
*/
public function boot(): void
{
parent::boot();
}
/**
* Define the routes for the application.
*/
public function map(): void
{
$this->mapApiRoutes();
$this->mapWebRoutes();
}
/**
* Define the "web" routes for the application.
*
* These routes all receive session state, CSRF protection, etc.
*/
protected function mapWebRoutes(): void
{
Route::middleware('web')->group(module_path('Usermanagement', '/routes/web.php'));
}
/**
* Define the "api" routes for the application.
*
* These routes are typically stateless.
*/
protected function mapApiRoutes(): void
{
Route::middleware('api')->prefix('api')->name('api.')->group(module_path('Usermanagement', '/routes/api.php'));
}
}

View File

@@ -0,0 +1,124 @@
<?php
namespace Modules\Usermanagement\Providers;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\ServiceProvider;
class UsermanagementServiceProvider extends ServiceProvider
{
protected string $moduleName = 'Usermanagement';
protected string $moduleNameLower = 'usermanagement';
/**
* Boot the application events.
*/
public function boot(): void
{
$this->registerCommands();
$this->registerCommandSchedules();
$this->registerTranslations();
$this->registerConfig();
$this->registerViews();
$this->loadMigrationsFrom(module_path($this->moduleName, 'database/migrations'));
if (class_exists('Breadcrumbs')) {
require __DIR__ . '/../../routes/breadcrumbs.php';
}
}
/**
* Register the service provider.
*/
public function register(): void
{
$this->app->register(EventServiceProvider::class);
$this->app->register(RouteServiceProvider::class);
}
/**
* Register commands in the format of Command::class
*/
protected function registerCommands(): void
{
// $this->commands([]);
}
/**
* Register command Schedules.
*/
protected function registerCommandSchedules(): void
{
// $this->app->booted(function () {
// $schedule = $this->app->make(Schedule::class);
// $schedule->command('inspire')->hourly();
// });
}
/**
* Register translations.
*/
public function registerTranslations(): void
{
$langPath = resource_path('lang/modules/'.$this->moduleNameLower);
if (is_dir($langPath)) {
$this->loadTranslationsFrom($langPath, $this->moduleNameLower);
$this->loadJsonTranslationsFrom($langPath);
} else {
$this->loadTranslationsFrom(module_path($this->moduleName, 'lang'), $this->moduleNameLower);
$this->loadJsonTranslationsFrom(module_path($this->moduleName, 'lang'));
}
}
/**
* Register config.
*/
protected function registerConfig(): void
{
$this->publishes([module_path($this->moduleName, 'config/config.php') => config_path($this->moduleNameLower.'.php')], 'config');
$this->mergeConfigFrom(module_path($this->moduleName, 'config/config.php'), $this->moduleNameLower);
}
/**
* Register views.
*/
public function registerViews(): void
{
$viewPath = resource_path('views/modules/'.$this->moduleNameLower);
$sourcePath = module_path($this->moduleName, 'resources/views');
$this->publishes([$sourcePath => $viewPath], ['views', $this->moduleNameLower.'-module-views']);
$this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), $this->moduleNameLower);
$componentNamespace = str_replace('/', '\\', config('modules.namespace').'\\'.$this->moduleName.'\\'.ltrim(config('modules.paths.generator.component-class.path'), config('modules.paths.app_folder', '')));
Blade::componentNamespace($componentNamespace, $this->moduleNameLower);
}
/**
* Get the services provided by the provider.
*
* @return array<string>
*/
public function provides(): array
{
return [];
}
/**
* @return array<string>
*/
private function getPublishableViewPaths(): array
{
$paths = [];
foreach (config('view.paths') as $path) {
if (is_dir($path.'/modules/'.$this->moduleNameLower)) {
$paths[] = $path.'/modules/'.$this->moduleNameLower;
}
}
return $paths;
}
}