1. Go to this page and download the library: Download bardoqi/sight 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/ */
namespace App\Presenter
use Bardoqi\Sight\Presenter;
class ArticlePresenter extents Presenter
{
public function __construct(){
parent::__construct();
}
}
namespace App\Presenter
use Bardoqi\Sight\Presenter;
use Bardoqi\Sight\Traits\PresenterTrait;
use Bardoqi\Sight\Enums\MappingTypeEnum
use Bardoqi\Sight\Enums\PaginateTypeEnum
use App\Repositories\ArticleRepository;
use App\Repositories\UserRepository;
class ArticlePresenter extents Presenter
{
use PresenterTrait;
public function getArticleList($where)
{
$articleArray = ArticleRepository::getList($where);
$user_ids = $this->selectFields('id','title','created_at','created_by')
->fromLocal($articleArray,'articles')
->pluck('created_by');
$users = UserRepository::getUsersWithIds($user_ids);
$this->innerJoinForeign($users,'userss')
->onRelationByObject(Relation::of()
->localAlias('articles')
->localField('created_by')
->foreignAlias('users')
->foreighField('id'))
->addFieldMappingByObject(FieldMapping::of()
->key('created_at')
->src('created_at')
->type(MappingTypeEnum::METHOD_NAME))
->addFieldMappingByObject(FieldMapping::of()
->key('created_by')
->src('user_name')
->type(MappingTypeEnum::JOIN_FIELD));
return $this->toPaginateArray(PaginateTypeEnum::PAGINATE_API);
}
}