PHP code example of uptoolkit / laravel-repository

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

    

uptoolkit / laravel-repository example snippets

 artisan make:apicontroller UserController
 artisan make:mutation UserUpdateMutation

php artisan make:repository UserRepository



namespace App\Repositories;

use App\User;
use Blok\Repository\AbstractEloquentRepository;

class UsersRepository extends AbstractEloquentRepository
{
    function model()
    {
        return User::class;
    }
}
`


namespace App\Http\Controllers\Api;

use App\Repositories\UsersRepository;
use Blok\Repository\Http\Controllers\AbstractApiController;

class UserController extends AbstractApiController
{
    function model()
    {
        return UsersRepository::class;
    }
}
`


namespace App\GraphQL\Mutations;

class UserUpdateMutation extends AbstractUpdateMutation
{
    function repository()
    {
        return \App\Repositories\UserRepository::class;
    }
}
 php artisan make:criteria OnlyPublicCriteria 



namespace App\Repositories\Criterias;

use Blok\Repository\AbstractCriteria;

class OnlyPublicCriteria extends AbstractCriteria
{
    public $type = "public";

    public function __construct($type = 'public'){
      $this->type = $type;
    }

    public function apply($model, $repository = null)
    {
        return $model->where('visibility', $this->type);
    }
}

public function all($columns = array('*'))
{
    if (!auth()->check()) {
        $this->pushCriteria(new OnlyPublicCriteria());
    }

    return parent::all($columns);
}



namespace App\Http\Controllers;

use App\Repositories\UserRepository;
use Illuminate\Http\Request;

class UserController extends Controller
{
    /**
     * @var UserRepository
     */
    private $userRepository;

    public function __construct(UserRepository $userRepository)
    {
        $this->userRepository = $userRepository;
    }

    /**
     * Display a listing of the resource.
     *
     * @param Request $request
     * @return \Illuminate\Http\Response
     */
    public function index(Request $request)
    {
        if(!auth()->check()){
          $this->userRepository->pushCriteria(new OnlyPublicCriteria('public'));
        }

        $users = $this->userRepository->paginate(12, $request->all());

        return view('users', compact('users'));
    }
}

$filters = "bookings->price_ht > 1000 || price_ht < 100 && socialUsers->provider = google";