PHP code example of zain / laravel-doctrine-jetpack

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

    

zain / laravel-doctrine-jetpack example snippets


 declare(strict_types=1);

namespace App\Entities;

use Illuminate\Contracts\Support\{Arrayable, Jsonable};
use JsonSerializable;
use Ramsey\Uuid\{Uuid, UuidInterface};
use Zain\LaravelDoctrine\Jetpack\Serializer\SerializesAttributes;

class MyEntity implements Arrayable, Jsonable, JsonSerializable
{
    use SerializesAttributes;

    protected UuidInterface $id;

    public function __construct()
    {
        $this->id = Uuid::uuid1();
    }

    public function getId(): string
    {
        return $this->id->toString();
    }
}

 declare(strict_types=1);

namespace App\Database\Doctrine\Mappings;

use App\Entities\MyEntity;
use LaravelDoctrine\Fluent\EntityMapping;
use LaravelDoctrine\Fluent\Fluent;

class MyEntityMapping extends EntityMapping
{
    public function mapFor()
    {
        return MyEntity::class;
    }

    public function map(Fluent $map)
    {
        $map->uuidPrimaryKey();
        // ...
        $map->timestamps();
    }
}

class Kernel extends HttpKernel
{
    // ...

    protected $middleware = [
        // ...
        \Zain\LaravelDoctrine\Jetpack\Middleware\FlushEntityManager::class,
    ];
}

use Illuminate\Contracts\Support\Arrayable;
use Illuminate\Contracts\Support\Jsonable;
use JsonSerializable;
use Zain\LaravelDoctrine\Jetpack\Serializer\SerializesAttributes;

class MyEntity implements Arrayable, Jsonable, JsonSerializable
{
    // Add this trait to your entities
    use SerializesAttributes;
}

return [
    'generators' => [
        'stubs_directory' => resource_path('jetpack/stubs/'),
        // ...
    ],
    // ...
];
bash
php artisan make:entity MyEntity
bash
php artisan make:mapping MyEntity
bash
php artisan vendor:publish --tag jetpack-config
bash
php artisan vendor:publish --tag jetpack-stubs