first init

This commit is contained in:
ISMAIL MASSERAN
2026-06-08 11:37:14 +08:00
commit 94ecbe5887
1058 changed files with 87732 additions and 0 deletions
+5
View File
@@ -0,0 +1,5 @@
<?php
return [
'name' => 'ActivityLog',
];
@@ -0,0 +1,16 @@
<?php
namespace Modules\ActivityLog\Database\Seeders;
use Illuminate\Database\Seeder;
class ActivityLogDatabaseSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{
// $this->call([]);
}
}
@@ -0,0 +1,97 @@
<?php
namespace Modules\ActivityLog\Http\Controllers;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Spatie\Activitylog\Models\Activity;
use App\Services\ActivityLogger;
class ActivityLogController extends Controller
{
/**
* Display a listing of the resource.
*/
public function index(Request $request)
{
// ActivityLogger::logView(new Activity, 'Viewed activity logs');
$perPage = $request->get('per_page', 10);
$perPage = min($perPage, 1000); // Limit max per page to 100
$search = trim((string) $request->get('search', ''));
$query = Activity::latest()->with(['causer']);
if (! empty($search)) {
$query->where(function ($q) use ($search) {
$q->where('description', 'ILIKE', "%{$search}%")
->orWhere('subject_type', 'ILIKE', "%{$search}%")
->orWhere('event', 'ILIKE', "%{$search}%")
->orWhere('causer.name', 'ILIKE', "%{$search}%")
->orWhere('causer.email', 'ILIKE', "%{$search}%");
});
}
$activities = $query->paginate($perPage);
return response()->json([
'success' => true,
'data' => $activities->items(),
'pagination' => [
'current_page' => $activities->currentPage(),
'per_page' => $activities->perPage(),
'total' => $activities->total(),
'last_page' => $activities->lastPage(),
'from' => $activities->firstItem(),
'to' => $activities->lastItem(),
'has_more_pages' => $activities->hasMorePages(),
'links' => [
'first' => $activities->appends(request()->query())->url(1),
'last' => $activities->appends(request()->query())->url($activities->lastPage()),
'prev' => $activities->appends(request()->query())->previousPageUrl(),
'next' => $activities->appends(request()->query())->nextPageUrl(),
]
],
'message' => 'Activity logs retrieved successfully',
]);
}
/**
* Show the form for creating a new resource.
*/
public function create()
{
return view('activitylog::create');
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request) {}
/**
* Show the specified resource.
*/
public function show($id)
{
return view('activitylog::show');
}
/**
* Show the form for editing the specified resource.
*/
public function edit($id)
{
return view('activitylog::edit');
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, $id) {}
/**
* Remove the specified resource from storage.
*/
public function destroy($id) {}
}
@@ -0,0 +1,27 @@
<?php
namespace Modules\ActivityLog\Policies;
use Illuminate\Auth\Access\HandlesAuthorization;
use Spatie\Activitylog\Models\Activity;
class ActivityLogPolicy
{
use HandlesAuthorization;
/**
* Determine whether the user can view any models.
*/
public function viewAny($user): bool
{
return $user->hasPermissionTo('lihat log aktiviti');
}
/**
* Determine whether the user can view the model.
*/
public function view($user, ?Activity $activity = null): bool
{
return $user->hasPermissionTo('lihat log aktiviti');
}
}
@@ -0,0 +1,154 @@
<?php
namespace Modules\ActivityLog\Providers;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\ServiceProvider;
use Nwidart\Modules\Traits\PathNamespace;
use RecursiveDirectoryIterator;
use RecursiveIteratorIterator;
class ActivityLogServiceProvider extends ServiceProvider
{
use PathNamespace;
protected string $name = 'ActivityLog';
protected string $nameLower = 'activitylog';
/**
* Boot the application events.
*/
public function boot(): void
{
$this->registerCommands();
$this->registerCommandSchedules();
$this->registerTranslations();
$this->registerConfig();
$this->registerViews();
$this->loadMigrationsFrom(module_path($this->name, 'Database/Migrations'));
}
/**
* 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->nameLower);
if (is_dir($langPath)) {
$this->loadTranslationsFrom($langPath, $this->nameLower);
$this->loadJsonTranslationsFrom($langPath);
} else {
$this->loadTranslationsFrom(module_path($this->name, 'Lang'), $this->nameLower);
$this->loadJsonTranslationsFrom(module_path($this->name, 'Lang'));
}
}
/**
* Register config.
*/
protected function registerConfig(): void
{
$configPath = module_path($this->name, config('modules.paths.generator.config.path'));
if (is_dir($configPath)) {
$iterator = new RecursiveIteratorIterator(new RecursiveDirectoryIterator($configPath));
foreach ($iterator as $file) {
if ($file->isFile() && $file->getExtension() === 'php') {
$config = str_replace($configPath.DIRECTORY_SEPARATOR, '', $file->getPathname());
$config_key = str_replace([DIRECTORY_SEPARATOR, '.php'], ['.', ''], $config);
$segments = explode('.', $this->nameLower.'.'.$config_key);
// Remove duplicated adjacent segments
$normalized = [];
foreach ($segments as $segment) {
if (end($normalized) !== $segment) {
$normalized[] = $segment;
}
}
$key = ($config === 'config.php') ? $this->nameLower : implode('.', $normalized);
$this->publishes([$file->getPathname() => config_path($config)], 'config');
$this->merge_config_from($file->getPathname(), $key);
}
}
}
}
/**
* Merge config from the given path recursively.
*/
protected function merge_config_from(string $path, string $key): void
{
$existing = config($key, []);
$module_config = require $path;
config([$key => array_replace_recursive($existing, $module_config)]);
}
/**
* Register views.
*/
public function registerViews(): void
{
$viewPath = resource_path('views/modules/'.$this->nameLower);
$sourcePath = module_path($this->name, 'Resources/Views');
$this->publishes([$sourcePath => $viewPath], ['views', $this->nameLower.'-module-views']);
$this->loadViewsFrom(array_merge($this->getPublishableViewPaths(), [$sourcePath]), $this->nameLower);
Blade::componentNamespace(config('modules.namespace').'\\' . $this->name . '\\View\\Components', $this->nameLower);
}
/**
* Get the services provided by the provider.
*/
public function provides(): array
{
return [];
}
private function getPublishableViewPaths(): array
{
$paths = [];
foreach (config('view.paths') as $path) {
if (is_dir($path.'/modules/'.$this->nameLower)) {
$paths[] = $path.'/modules/'.$this->nameLower;
}
}
return $paths;
}
}
@@ -0,0 +1,27 @@
<?php
namespace Modules\ActivityLog\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.
*/
protected function configureEmailVerification(): void {}
}
@@ -0,0 +1,49 @@
<?php
namespace Modules\ActivityLog\Providers;
use Illuminate\Foundation\Support\Providers\RouteServiceProvider as ServiceProvider;
use Illuminate\Support\Facades\Route;
class RouteServiceProvider extends ServiceProvider
{
protected string $name = 'ActivityLog';
/**
* 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();
}
/**
* 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($this->name, '/Routes/web.php'));
}
/**
* Define the "api" routes for the application.
*
* These routes are typically stateless.
*/
protected function mapApiRoutes(): void
{
Route::middleware('api')->name('api.')->group(module_path($this->name, '/Routes/api.php'));
}
}
+8
View File
@@ -0,0 +1,8 @@
<?php
use Illuminate\Support\Facades\Route;
use Modules\ActivityLog\Http\Controllers\ActivityLogController;
Route::middleware(['auth:sanctum'])->prefix('v1')->group(function () {
Route::apiResource('activitylogs', ActivityLogController::class)->names('activitylog');
});
+30
View File
@@ -0,0 +1,30 @@
{
"name": "nwidart/activitylog",
"description": "",
"authors": [
{
"name": "Nicolas Widart",
"email": "n.widart@gmail.com"
}
],
"extra": {
"laravel": {
"providers": [],
"aliases": {
}
}
},
"autoload": {
"psr-4": {
"Modules\\ActivityLog\\": "App",
"Modules\\ActivityLog\\Database\\Factories\\": "database/factories/",
"Modules\\ActivityLog\\Database\\Seeders\\": "database/seeders/"
}
},
"autoload-dev": {
"psr-4": {
"Modules\\ActivityLog\\Tests\\": "tests/"
}
}
}
+11
View File
@@ -0,0 +1,11 @@
{
"name": "ActivityLog",
"alias": "activitylog",
"description": "",
"keywords": [],
"priority": 0,
"providers": [
"Modules\\ActivityLog\\Providers\\ActivityLogServiceProvider"
],
"files": []
}
+15
View File
@@ -0,0 +1,15 @@
{
"private": true,
"type": "module",
"scripts": {
"dev": "vite",
"build": "vite build"
},
"devDependencies": {
"axios": "^1.1.2",
"laravel-vite-plugin": "^0.7.5",
"sass": "^1.69.5",
"postcss": "^8.3.7",
"vite": "^4.0.0"
}
}