PHP code example of atrauzzi / laravel-doctrine

1. Go to this page and download the library: Download atrauzzi/laravel-doctrine 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/ */

    

atrauzzi / laravel-doctrine example snippets


"minimum-stability": "dev",
"prefer-stable": true

"atrauzzi/laravel-doctrine": "dev-master"

Atrauzzi\LaravelDoctrine\ServiceProvider::class,

'EntityManager' => Atrauzzi\LaravelDoctrine\Support\Facades\Doctrine::class,


$user = new User;
$user->setName('Mr.Right');
EntityManager::persist($user);
EntityManager::flush();

namespace App\Lib\Domain\Entities;

use Doctrine\ORM\Mapping as ORM;
use Atrauzzi\LaravelDoctrine\Trait\Time;

/**
 * @ORM\Entity
 * @ORM\Table(name="Post")
 */
class Post
{
    use Time;

    /**
     * @ORM\Id
     * @ORM\GeneratedValue
     * @ORM\Column(type="integer")
     */
    private $id;
    /**
     * @ORM\Column(type="string")
     */
    private $title;
    /**
     * @ORM\Column(type="text")
     */
    private $body;
    public function __construct($input)
    {
        $this->setTitle($input['title']);
        $this->setBody($input['body']);
    }
    public function getId()
    {
        return $this->id;
    }
    public function getTitle()
    {
        return $this->title;
    }
    public function setTitle($title)
    {
        $this->title=$title;
    }
    public function setBody($body)
    {
        $this->body=$body;
    }
    public function getBody()
    {
        return $this->body;
    }
}


use Doctrine\ORM\Tools\Console\ConsoleRunner;
use Illuminate\Foundation\Application;

lluminate\Contracts\Http\Kernel $kernel */
$kernel = $app->make('Illuminate\Contracts\Console\Kernel');
$kernel->bootstrap();

$app->boot();

$entityManager = $app->make('Doctrine\ORM\EntityManager');

return ConsoleRunner::createHelperSet($entityManager);

namespace App\Models;

use Illuminate\Contracts\Auth\Authenticatable;

/**
 * Class User
 * @entity
 * @table(name="users")
 */
class User implements Authenticatable {

    /**
     * @var int
     * @column(type="integer", name="id_user")
     * @generatedValue(strategy="AUTO")
     * @id
     */
    protected $id;

    /**
     * @var string
     * @column(type="string", unique=true)
     */
    protected $email;

    /**
     * @var string
     * @column(type="string")
     */
    protected $password;

    /**
     * @var string
     * @column(type="string")
     */
    protected $token;

    public function getEmail()
    {
        return $this->email;
    }

    public function getPassword()
    {
        return $this->password;
    }


    /**
     * Get the unique identifier for the user.
     *
     * @return mixed
     */
    public function getAuthIdentifier()
    {
        return $this->id;
    }

    /**
     * Get the password for the user.
     *
     * @return string
     */
    public function getAuthPassword()
    {
        return $this->password;
    }

    /**
     * Get the token value for the "remember me" session.
     *
     * @return string
     */
    public function getRememberToken()
    {
        return $this->token;
    }

    /**
     * Set the token value for the "remember me" session.
     *
     * @param  string $value
     * @return void
     */
    public function setRememberToken($value)
    {
        $this->token = $value;
    }

    /**
     * Get the column name for the "remember me" token.
     *
     * @return string
     */
    public function getRememberTokenName()
    {
        return 'remember_me_token';
    }
}

'auth' => [
    'authenticator' => 'Atrauzzi\LaravelDoctrine\DoctrineAuthenticator',
    'model' => 'App\Models\User',
]

'driver' => 'doctrine.auth',