Comments (6)
Hi @dixitchopra,
When you use the Filter, the Model will only return the columns requested in the case, id and title. In PostTransformer if you are prepared to make the Model with all its attributes, and when the filter is activated, the other columns are not returned and so it comes as null.
I think that a solution would be to perform a check on your PostTransformer, and only display columns that are defined, or another solution would be to use the method toArray () of the Model.
Ex:
use App\Post;
use League\Fractal\TransformerAbstract;
class PostTransformer extends TransformerAbstract
{
public function transform(Post $post)
{
$data = [];
if( isset($post->id) )
$data['id'] = (int) $post->id;
if( isset($post->title) )
$data['title'] = $post->title;
if( isset($post->text) )
$data['text'] = $post->text;
return $data;
}
}
Ex 2:
use App\Post;
use League\Fractal\TransformerAbstract;
class PostTransformer extends TransformerAbstract
{
public function transform(Post $post)
{
$avaliable = ['id','title','text'];
$data = array_only($post->toArray(), $avaliable);
return $data;
}
}
I hope I help!
from l5-repository.
@andersao did you find a solution to him? I'm interested to apply this
from l5-repository.
Thanks for your reply. I am using second option in my code. There are two issues here.
- How can I change the column name title to Name?
- This won't work with 'With'. return $this->postRepository->with(['user'])->all(); I
am getting only Post model columns and not User columns. Earlier it was working.
from l5-repository.
@dixitchopra I'll get a solution for you :)
from l5-repository.
@dixitchopra Are you still having problems?
from l5-repository.
@andersao i'm still having problems.
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.