1. Go to this page and download the library: Download kettasoft/booter 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/ */
kettasoft / booter example snippets
use Scaffolding\Booter\Traits\HasBooter;
class Post extends Model
{
use HasBooter;
/**
* The event-to-class mappings.
*
* @var array
*/
protected static $events = [
'created' => [
\App\Boot\AttachAuthorIdBoot::class,
],
'updated' => [
\App\Boot\LogChangesBoot::class,
],
];
}
namespace App\Boots;
use Scaffolding\Booter\HasBooter;
class AttachAuthorIdBoot extends HasBooter
{
/**
* Handle the model event.
*
* @param \Illuminate\Database\Eloquent\Model $model
* @return void
*/
public function handle(\Illuminate\Database\Eloquent\Model $model)
{
// Custom logic for 'created' event
$model->author_id = auth()->id();
$model->save();
}
}