PHP code example of pektiyaz / laravel-repository

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

    

pektiyaz / laravel-repository example snippets


use Pektiyaz\LaravelRepository\AbstractRepository;
/**
 * @method PostEntity findById(int|string $id)
 * @method PostEntity findOneBy(array $conditions)
 * @method PostEntity[] findAllBy(array $conditions)
 * @method PostEntity[] findAll()
 * @method PostEntity create(array $data)
 * @method PostEntity restore(int $id)
 * @method PostEntity[] paginate(int $page, int $perPage, array $conditions = [])
 * @method PostEntity[] findTrashed()
 * @method PostEntity findTrashedById(int|string $id)
 * @method PostEntity[] findByCallback(callable $callback)
 * @method PostEntity[] bulkCreate(array $records)
 * @method PostEntity[] filter(QueryFilterContract $filter)
 */
class PostRepository extends AbstractRepository
{
    public function getModel(): string
    {
        return \App\Models\Post::class;
    }

    public function getEntity(): string
    {
        return \App\Entities\PostEntity::class;
    }

    public function getEventPrefix(): string
    {
        return 'post';
    }
}


use Pektiyaz\LaravelRepository\AbstractEntity;

class PostEntity extends AbstractEntity
{
    protected ?string $title = null;

    public function getTitle(): ?string
    {
        return $this->title;
    }

    public function setTitle(?string $title): void
    {
        $this->title = $title;
    }

    // Add other fields as needed...
}