PHP code example of maatwebsite / usher
1. Go to this page and download the library: Download maatwebsite/usher 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/ */
maatwebsite / usher example snippets
'Brouwers\LaravelDoctrine\DoctrineServiceProvider',
'Maatwebsite\Usher\UsherServiceProvider'
php artisan vendor:publish --provider="Maatwebsite\Usher\UsherServiceProvider"
use Doctrine\ORM\Mapping as ORM;
use Maatwebsite\Usher\Domain\Users\User;
use Maatwebsite\Usher\Contracts\Users\User as UserInterface;
/**
* @ORM\Entity(repositoryClass="DoctrineCustomerRepository")
* @ORM\Table(name="customers")
* @ORM\HasLifecycleCallbacks()
*/
class Customer extends User implements UserInterface
{
/**
* @ORM\ManyToMany(targetEntity="Group", inversedBy="customers")
* @ORM\JoinTable(name="customer_groups")
* @var ArrayCollection|\App\Domain\Customers\Entities\Role[]
*/
protected $groups;
/**
* Customer Constructor
*/
public function __construct()
{
$this->groups = new ArrayCollection();
}
/**
* @return ArrayCollection|\Maatwebsite\Usher\Contracts\Roles\Role[]
*/
public function getRoles()
{
return $this->groups;
}
}
/**
* @ORM\Entity(repositoryClass="DoctrineRoleRepository")
* @ORM\Table(name="groups")
* @ORM\HasLifecycleCallbacks()
*/
class Group extends Role implements RoleInterface
{
/**
* @ORM\ManyToMany(targetEntity="Customer", mappedBy="groups")
* @var ArrayCollection|Customer[]
**/
protected $customers;
/**
* Role Constructor
*/
public function __construct()
{
$this->customers = new ArrayCollection();
}
/**
* @return ArrayCollection|\Maatwebsite\Usher\Contracts\Users\User[]
*/
public function getUsers()
{
return $this->customers;
}
}
return [
'users' => [
'entity' => 'Customer'
],
'roles' => [
'entity' => 'Group'
]
]