PHP code example of plank / laravel-model-resolver
1. Go to this page and download the library: Download plank/laravel-model-resolver library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
plank / laravel-model-resolver example snippets
namespace App\Listeners;
use App\Contracts\Content;
use Plank\LaravelModelResolver\Facades\Models;
class PruneContent
{
public function handle()
{
Models::implements(Content::class)
->each(fn (Content $content) => $content->prune());
}
}
public function modelInstances()
{
Models::all()
->map(function (string $class) => new $class);
}
public function handle(TableCreated $event)
{
$model = Models::fromTable($event->table);
// ...
}
public function handle(Version $from, Version $to)
{
Models::implements(Versioned::class)
->each(fn (string $class) => $class::copyData($from, $to));
}
public function handle()
{
Models::implementsAll([Loggable::class, Titleable::class])
->each(function (string $class) {
$models = $class::query()
->whereCondition()
->cursor()
->each(fn (Loggable&Titleable $model) => $model->log($model->title().' has met some condition'));
});
}