PHP code example of jobmetric / laravel-membership
1. Go to this page and download the library: Download jobmetric/laravel-membership 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/ */
jobmetric / laravel-membership example snippets
namespace App\Models;
use Illuminate\Foundation\Auth\User as Authenticatable;
use JobMetric\Membership\CanMember;
class User extends Authenticatable
{
use CanMember;
}
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
use JobMetric\Membership\Contracts\MemberContract;
use JobMetric\Membership\HasMember;
class Order extends Model implements MemberContract
{
use HasMember;
/**
* allow the member collection.
*
* @return array
*/
public function allowMemberCollection(): array
{
return [
'owner' => 'single',
'members' => 'multiple'
];
}
}
use JobMetric\Membership\Events\PersonableResourceEvent;
class AddUserResourceToPersonableResourceListener
{
public function handle(PersonableResourceEvent $event)
{
$personable = $event->personable;
if (personable instanceof \App\Models\User) {
$event->resource = new \App\Http\Resources\UserResource($personable);
}
}
}
use JobMetric\Membership\Events\MemberableResourceEvent;
class AddOrderResourceToMemberableResourceListener
{
public function handle(MemberableResourceEvent $event)
{
$memberable = $event->memberable;
if ($memberable instanceof \App\Models\User) {
$event->resource = new \App\Http\Resources\OrderResource($memberable);
}
}
}