PHP code example of okipa / laravel-base-repository
1. Go to this page and download the library: Download okipa/laravel-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/ */
okipa / laravel-base-repository example snippets
namespace App\Repositories;
interface BaseRepositoryInterface extends Okipa\LaravelBaseRepository\BaseRepositoryInterface
{
// add here your own custom method contracts (if necessary).
// they will be implemented in all your repositories.
}
namespace App\Repositories;
abstract class BaseRepository extends Okipa\LaravelBaseRepository\BaseRepository implements BaseRepositoryInterface
{
// add here your own custom method declarations (if necessary).
// they will be implemented in all your repositories.
}
namespace App\Repositories\Users;
interface UserRepositoryInterface
{
// add here the users method contracts.
/**
* @return void
*/
public function test();
}
namespace App\Repositories\Users;
use App\Repositories\BaseRepository;
use App\Models\User;
class UserRepository extends BaseRepository implements UserRepositoryInterface
{
protected $model = User::class;
// add here the users method declarations.
public function test()
{
\Log::info('test');
// manipulate your model as needed. Example : $this->model->create(['email' => '[email protected]']);
}
}
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use App\Repositories\User\UserRepositoryInterface;
class RepositoryServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @return void
*/
public function boot()
{
//
}
/**
* Register any application services.
*
* @return void
*/
public function register()
{
// users
$this->app->bind(UserRepositoryInterface::class, UserRepository::class);
// then, register all your other repositories here ...
}
}
namespace App\Http\Controllers;
use Illuminate\Foundation\Bus\DispatchesJobs;
use Illuminate\Routing\Controller as BaseController;
use Illuminate\Foundation\Validation\ValidatesRequests;
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
class Controller extends BaseController
{
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
protected $repository;
}
namespace App\Http\Controllers\Users;
use App\Http\Controllers\Controller;
use App\Repositories\Users\UserRepositoryInterface;
class UsersController extends Controller
{
/**BaseRepositoryInterface
* UsersController constructor.
*
* @param \App\Repositories\Users\UserRepositoryInterface $repository
*/
public function __construct(UserRepositoryInterface $repository)
{
parent::__construct();
$this->repository = $repository;
}
/**
* @param IndexUserRequest $request
*
* @return void
*/
public function index(IndexUserRequest $request)
{
// execute your repository custom methods
$this->repository->test();
// execute this package methods
$allStoredUsers = $this->repository->getAll();
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.