1. Go to this page and download the library: Download mhamzeh/presenter-filter 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/ */
mhamzeh / presenter-filter example snippets
artisan vendor:publish
artisan make:filter UserFilter
artisan make:filter UserFilter --model=User
artisan make:presenter UserPresenter
artisan make:presenter UserPresenter --model=User
artisan make:filter PostFilter --model=Post
namespace App\Filters;
use mhamzeh\packageFp\Filters\contracts\QueryFilter;
class UserFilter extends QueryFilter
{
public function name($value){
return $this->builder->where('name','LIKE',"%$value%");
}
}
use mhamzeh\packageFp\Filters\contracts\Filterable;
...
class User extends Model
{
use Filterable;
...
}
use App\Filters\UserFilter;
...
public function index()
{
return User::filters(new UserFilter())->paginate();
}
artisan make:presenter UserPresenter --model=User
namespace App\Presenter;
use mhamzeh\packageFp\Presenter\Contracts\Presenter;
class UserPresenter extends Presenter
{
public function full_name(){
return $this->entity->name ." ".$this->entity->full_name;
}
}
use mhamzeh\packageFp\Presenter\Contracts\Presentable;
...
class User extends Model
{
use Presentable;
protected $presenter = UserPresenter::class;
...
}
@foreach($users as $user)
<div>
<p>fullname : $user->present()->full_name </p>
</div>
@endforeach
class UserResource extends JsonResource
{
/**
* Transform the resource into an array.
*
* @param \Illuminate\Http\Request $request
* @return array
*/
public function toArray($request)
{
return [
'id'=>$this->id,
'full_name'=> $this->present()->full_name,
'email'=>$this->email
];
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.