creative-syntax/page-loader
Add a simple customizable page loading indicator to your Laravel app. Install via Composer, optionally register the service provider, publish the config, and toggle the loader or change its color in config/page-loader.php.
Installation
composer require dev-arindam-roy/laravel-page-loader-package
Publish the config file (if needed):
php artisan vendor:publish --provider="DevArindamRoy\PageLoader\PageLoaderServiceProvider"
Basic Usage
Define a page in config/page-loader.php:
'pages' => [
'home' => [
'view' => 'pages.home',
'middleware' => ['web'],
'data' => ['title' => 'Home Page'],
],
'about' => [
'view' => 'pages.about',
'middleware' => ['web'],
],
],
First Use Case Load a page dynamically in a controller:
use DevArindamRoy\PageLoader\Facades\PageLoader;
public function loadPage($pageName)
{
return PageLoader::load($pageName);
}
Route it:
Route::get('/{page}', [PageController::class, 'loadPage']);
Route-Based Pages Useful for marketing sites or CMS-like structures where pages are defined in config but rendered dynamically.
Route::get('/{page}', function ($page) {
return PageLoader::load($page);
})->where('page', 'home|about|contact');
Conditional Page Loading Load pages based on user roles or other logic:
if (auth()->check()) {
return PageLoader::load('dashboard');
}
return PageLoader::load('home');
Pass dynamic data to pages:
PageLoader::load('home', [
'posts' => Post::latest()->take(5)->get(),
]);
Attach middleware per page (defined in config) or globally:
// In config/page-loader.php
'global_middleware' => ['auth'],
Define a fallback page for 404s:
// In config/page-loader.php
'fallback_page' => 'not-found',
Missing Config
Ensure config/page-loader.php exists and is properly structured. The package may silently fail if misconfigured.
View File Not Found
Double-check the view key in the config matches an existing Blade file (e.g., resources/views/pages/home.blade.php).
Middleware Conflicts If a page’s middleware conflicts with route middleware, the last defined middleware takes precedence. Test thoroughly.
Caching Issues If using Laravel’s cache, clear it after updating the config:
php artisan cache:clear
Check Loaded Pages Temporarily add logging to verify pages are loading correctly:
PageLoader::load('home')->withDebug(function ($page) {
\Log::info('Loaded page:', ['page' => $page]);
});
Validate Config
Use php artisan config:clear if changes to page-loader.php aren’t reflected.
Custom Page Resolvers Extend the package by binding a custom resolver to load pages from a database or API:
// In a service provider
$this->app->bind(\DevArindamRoy\PageLoader\Contracts\PageResolver::class, CustomPageResolver::class);
Event Listeners Listen for page load events (if the package emits them) to log or modify page data:
// In EventServiceProvider
protected $listen = [
\DevArindamRoy\PageLoader\Events\PageLoaded::class => [
\App\Listeners\LogPageLoad::class,
],
];
Dynamic Config Loading
Override the config dynamically (e.g., from a database) by extending the PageLoader facade or service.
How can I help you explore Laravel packages today?