Comments (4)
@syflipper
Well, the repository will you return a instantiates your model , then you could use this method without problems. If you are using a presenter , simply ignore the presenter using the skipPresenter () method.
Try this:
//GamesController.php
public function __construct(GameRepository $repository){
$this->repository = $repository;
}
public function show($id)
{
try
{
$game = $this->repository->skipPresenter(true)->find($id);
$game->verifyOwnership(Auth::user());
//more logic
} catch (Exception $e) {
throw $e;
}
}
from l5-repository.
Thanks for your answer @andersao. The problem is that I have to present the data after it gets verified again (API output). Any tips on doing that?
from l5-repository.
@syflipper
You can do this by creating a customized presentation. Thus it will extract your model information to be displayed in their API , at that time you can treat the information that is displayed . See the example below :
https://github.com/prettus/l5-repository#create-a-presenter
//GameTransformer.php
use App\Post;
use League\Fractal\TransformerAbstract;
class GameTransformer extends TransformerAbstract
{
public function transform(Game $game)
{
$data = [];
$data = [
'id'=>$game->id,
'title'=>$game->title
];
if( $game->verifyOwnership(Auth::user()) )
{
$data = array_merge($data,[
'dataOnlyIfOwnership'=>$game->privateData,
....
]);
}
return $data;
}
}
//GamePresenter.php
use Prettus\Repository\Presenter\FractalPresenter;
class GamePresenter extends FractalPresenter {
/**
* Prepare data to present
*
* @return \League\Fractal\TransformerAbstract
*/
public function getTransformer()
{
return new GameTransformer();
}
}
//GameRepository.php
use Prettus\Repository\Eloquent\BaseRepository;
class GameRepository extends BaseRepository {
...
public function presenter()
{
return "YOUR_NAMESPACE\\GamePresenter";
}
}
I hope this works for you
from l5-repository.
from l5-repository.
Related Issues (20)
- RequestCriteria supports for Morph relationship
- Cache doesn't work
- Target class [] does not exist
- L9 Command "make:rest-controller" is not defined HOT 3
- depricated error on request citeria
- Do you have plans to update to support mongodb?
- time search on date not working HOT 2
- how to use it with yajra datatable
- Add Laravel 10 support HOT 4
- how to use exists() or doesntExist() method HOT 1
- Screenshot (Apr 25, 2023 11:23:51 PM)
- Invalid URL separator (semicolon) HOT 1
- how to search with the searchable fields with multiple values in one field ?
- Communication channel regarding security issue @andersao HOT 1
- Query Expression with laravel 10 and whereRaw query
- Can not use function simplePaginate with Presenter
- Laravel 10 criteria no longer work? HOT 2
- Hi HOT 1
- searchJoin=and doesn,t work HOT 1
- Need Laravel 11 Support HOT 13
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from l5-repository.