PHP code example of wilkques / repositories

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

    

wilkques / repositories example snippets


namespace App\Repositories\UserRepository;

use App\User;
use Wilkques\Repositories\Repository;

class UserRepository extends Repository
{
    public function __construct(User $user)
    {
        parent::__construct($user);
    }

    public function whereName(string $name)
    {
        return $this->where("name", $name);
    }
}

// other class

use App\Repositories\UserRepository;
use App\User;

class UserController extends Controller
{
    protected $userRepository;

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

    public function index(Request $request)
    {
        $user = User::where("name", $request->name)->get()->toArray();

        // same

        $user = $this->userRepository->where("name", $request->name)->get()->toArray();

        // same

        $user = $this->userRepository->whereName($request->name)->get()->toArray();
    }
}