PHP code example of peltonsolutions / laravel-ownerable
1. Go to this page and download the library: Download peltonsolutions/laravel-ownerable 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/ */
peltonsolutions / laravel-ownerable example snippets
use PeltonSolutions\LaravelOwnerable\Contracts\CanHavePossessions;
class Account extends Model implements CanHavePossessions
{
// Return the currently active owner instance (e.g. from session or auth)
public static function getCurrent(): ?static
{
return static::find(session('account_id'));
}
// Associate a possessed model with this owner
public function addPossession(CanBePossessed $possession)
{
$possession->ownerable()->associate($this)->save();
}
public function getKey()
{
return $this->id;
}
}
use PeltonSolutions\LaravelOwnerable\Contracts\CanBePossessed as CanBePossessedContract;
use PeltonSolutions\LaravelOwnerable\Traits\CanBePossessed;
class BlogPost extends Model implements CanBePossessedContract
{
use CanBePossessed;
}
Schema::create('blog_posts', function (Blueprint $table) {
$table->id();
$table->nullableMorphs('ownerable');
// ... other columns
$table->timestamps();
});