OkuribitoLaravel can monitor view loading and record it. This helps to remove unused view files.
This package is inspired by Ruby's Okuribito gem.
OkuribitoLaravel has the following requirements:
- PHP >= 7.1.3
- Laravel >= 5.5
Execute the require
Composer command:
composer require ngmy/okuribito-laravel
This will update your composer.json
file and install this package into the vendor
directory.
Execute the migrate
Artisan command:
php artisan migrate
This will create the view_load_logs
table in your database.
Execute the vendor:publish
Artisan command:
php artisan vendor:publish
This will publish the configuration file to the config/ngmy-okuribito-laravel.php
file.
You can also use the tag to execute the command:
php artisan vendor:publish --tag=ngmy-okuribito-laravel
You can also use the service provider to execute the command:
php artisan vendor:publish --provider="Ngmy\OkuribitoLaravel\OkuribitoServiceProvider"
Update the config/ngmy-okuribito-laravel.php
file's monitor_views
option to the view you want to monitor loading:
'monitor_views' => 'your.view.foo',
You can also specify multiple views:
'monitor_views' => [
'your.view.bar',
'your.view.baz',
],
You can also use a wildcard:
'monitor_views' => 'your.view.*',
This value is specified in the same format as the first argument of Laravel's View::composer
method.
When the specified view is loaded, it is recorded to the view_load_logs
table in your database.
You have other options available. See the config/ngmy-okuribito-laravel.php
file for details.
Creating your implementation of the ViewLoadLogRepositoryInterface
interface.
<?php
declare(strict_types=1);
namespace Your\Namespace;
use Ngmy\OkuribitoLaravel\Domain\Model\View\View;
use Ngmy\OkuribitoLaravel\Domain\Model\ViewLoadLog\ViewLoadLog;
use Ngmy\OkuribitoLaravel\Domain\Model\ViewLoadLog\ViewLoadLogRepositoryInterface;
class YourViewLoadLogRepository implements ViewLoadLogRepositoryInterface
{
public function existsByView(View $view): bool
{
// Implement your existsByView() method here
}
public function save(ViewLoadLog $log): void
{
// Implement your save() method here
}
}
Binding the ViewLoadLogRepositoryInterface
interface to your implementation in your service provider's register
method.
$this->app->bind(
\Ngmy\OkuribitoLaravel\Domain\Model\ViewLoadLog\ViewLoadLogRepositoryInterface::class,
\Your\Namespace\YourViewLoadLogRepository::class
);
OkuribitoLaravel is open-sourced software licensed under the MIT license.