PHP code example of ozankurt / repoist

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

    

ozankurt / repoist example snippets




return [

	/**
	 * Namespaces are being prefixed with the applications base namespace.
	 */
	'namespaces' => [
	    'contracts' => 'Repositories\Contracts',
	    'repositories' => 'Repositories\Eloquent',
	],

	/**
	 * Paths will be used with the `app()->basePath().'/app/'` function to reach app directory.
	 */
	'paths' => [
	    'contracts' => 'Repositories/Contracts/',
	    'repositories' => 'Repositories/Eloquent/',
	],

];


namespace App\Models;

use Illuminate\Database\Eloquent\Model;

class Customer extends Model
{
    /**
     * Customer has many Tickets.
     *
     * @return \Illuminate\Database\Eloquent\Relations\HasMany
     */
    public function tickets()
    {
    	return $this->hasMany(Ticket::class, 'customer_id', 'id');
    }
}


namespace App\Repositories\Eloquent;

use App\Models\Customer;
use App\Repositories\Contracts\CustomerRepository;
use Kurt\Repoist\Repositories\Eloquent\AbstractRepository;

class EloquentCustomerRepository extends AbstractRepository implements CustomerRepository
{
    public function entity()
    {
        return Customer::class;
    }
}


namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Repositories\Contracts\CustomerRepository;
use Kurt\Repoist\Repositories\Eloquent\Criteria\EagerLoad;

class PagesController extends Controller
{
	private $customerRepository;

	function __construct(CustomerRepository $customerRepository)
	{
		$this->customerRepository = $customerRepository;
	}

    public function getHome()
    {
        $customersWithTickets = $this->customerRepository->withCriteria([
        	new EagerLoad(['tickets']),
        ])->all();

        return $customersWithTickets;
    }
}

php artisan make:repository Task

php artisan make:criterion Completed