PHP code example of cuongdv / base-repository

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

    

cuongdv / base-repository example snippets


'providers' => [
    // Other service providers...

    Softel\RepositoryServiceProvider::class,
],



namespace App\Repositories;

use App\Models\User;
use Softel\Repository\AbstractRepository;
use App\Repositories\Contracts\UserRepositoryInterface;

class UserRepository extends AbstractRepository implements UserRepositoryInterface
{
    protected $model;

    /**
     * UserRepository construct
     *
     * @param  mixed $model
     *
     * @return void
     */
    public function __construct(User $model)
    {
        parent::__construct($model);
    }
}



namespace App\Providers;

use Illuminate\Support\ServiceProvider;
use App\Repositories\UserRepository;
use App\Repositories\Contracts\UserRepositoryInterface;


class AppServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        //
    }

    /**
     * Register any application services.
     *
     * @return void
     */
    public function register()
    {
        $this->app->bind(UserRepositoryInterface::class, UserRepository::class);
    }
}



namespace App\Http\Controllers\Auth;

use App\Http\Controllers\Controller;
use App\Repositories\Contracts\UserRepositoryInterface;

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

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

    public function show($id) 
    {

        $user = $this->userRepository->findById($id);

        return response()->json($user);
    }
}

    public function find(array $conditions = []);
    public function findOne(array $conditions);
    public function findById(int $id);
    public function create(array $attributes);
    public function update(Model $model, array $attributes = []);
    public function save(Model $model);
    public function delete(Model $model);
    public function get($query);
    public function destroy(array $ids);
    public function findCount(array $conditions);
    public function toBase($query);
    public function updateMultiple(Builder $query, array $attributes = []);
    public function updateOrCreate(array $attributes, array $values);
    public function findAll();
    public function findByIds(array $ids);
    public function model();
    public function makeModel();
    public function resetModel();