1. Go to this page and download the library: Download amin3520/anar 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/ */
amin3520 / anar example snippets
/**
* Register RepositoryServiceProvider .
* provide your repository and inject it any where below your app directoy, like in to your controller's app if you want to use it
* @return void
*/
public function register()
{
$names = [
//add Begin your repository name here like -> 'UserRepository',
];
foreach ($names as $name) {
$this->app->bind(
"App\\Repositories\\{$name}",
"App\\Repositories\\{$name}");
}
}
class Controller extends BaseController
{
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
private $userRepo;
/**
* Controller constructor.
*inject repo by service provider
*/
public function __construct(UserRepositoryImp $repositoryImp)
{
$this->userRepo=$repositoryImp;
//now u can use it
}
public function updateName(Request $request)
{
$this->userRepo->update(['name'=>'amin'],auth::id());
}
}
interface BaseRepositoryImp
{
public function create(array $attributes);
public function update(array $attributes, int $id);
public function all($columns = array('*'), string $orderBy = 'id', string $sortBy = 'desc');
public function find(int $id);
public function findOneOrFail(int $id);
public function findBy(array $data);
public function findOneBy(array $data);
public function findOneByOrFail(array $data);
public function paginateArrayResults(array $data, int $perPage = 50);
public function delete(int $id);
public function findWhere($where, $columns = ['*'], $or = false);
public function with(array $relations);
}