imagina / ihelpers-module
Installs: 1 879
Dependents: 13
Suggesters: 0
Security: 0
Stars: 1
Watchers: 4
Forks: 7
Open Issues: 1
Type:asgard-module
Requires
- php: ^8.1
- composer/installers: ~1.0
- imagina/core-module: ^10.0
Requires (Dev)
- orchestra/testbench: ^8.5
- phpunit/phpunit: ^10
README
Based in: https://github.com/spatie/laravel-responsecache/tree/v1 https://github.com/JosephSilber/page-cache (For file cache redirections)
To activate the Cache System
Modify
// config/app.php 'providers' => [ ... Modules\Ihelpers\Other\ImResponseCache\ImResponseCacheServiceProvider::class, ];
This package also comes with a facade.
// config/app.php 'aliases' => [ ... 'ResponseCache' => Modules\Ihelpers\Other\ImResponseCache::class, ];
You can publish the config file with:
php artisan vendor:publish --provider="Modules\Ihelpers\Other\ImResponseCache\ImResponseCacheServiceProvider"
Command available to clear cache
php artisan pagecache:clear
URL rewriting
In order to serve the static files directly once they've been cached, you need to properly configure your web server to check for those static files.
-
For nginx:
Update your
location
block'stry_files
directive to include a check in thepage-cache
directory:location / { try_files $uri $uri/ /page-cache/$uri.html /index.php?$query_string; }
-
For apache:
Open
public/.htaccess
and add the following before the block labeledHandle Front Controller
:# Serve Cached Page If Available... RewriteCond %{REQUEST_URI} ^/?$ RewriteCond %{DOCUMENT_ROOT}/page-cache/pc__index__pc.html -f RewriteRule .? page-cache/pc__index__pc.html [L] RewriteCond %{DOCUMENT_ROOT}/page-cache%{REQUEST_URI}%{QUERY_STRING}.html -f RewriteRule . page-cache%{REQUEST_URI}.html [L]
CUSTOM include and relationship features:
You can set custom includes and relationships in any entity from any module as follows:
-
In Modules\Imodule\Config\config.php:
'includes'=>[ 'EntityTransformer'=>[ 'otherEntity'=>[ 'path'=>'Modules\Iothermodule\Transformers\OtherEntityTransformer', //this is the transformer path 'multiple'=>false, //if the relationship is one-to-many, multiple must be set to true ], ], ... ], 'relations' =>[ 'entity'=>[ 'otherEntity' => function () { return $this->hasOne( \Modules\Iothermodule\Entities\OtherEntity::class, 'model_id'); }, ], ... ],
-
In Modules\Imodule\Entities\Entity.php:
You must be use the trait for use the custom relations as follows:
use Modules\Ihelpers\Traits\Relationable; class Entity extends Model{ use Relationable;
-
In Modules\Imodule\Transformers\EntityTransformer.php:
You must be use the trait for use the custom includes as follows:
use Modules\Ihelpers\Traits\Transformeable; class EntityTransformer extends JsonResource{ use Transformeable;