Specific With function laravel

Well I found the solution. It can be done one by passing a closure function in with() as second index of array like

Post::with(array('user'=>function($query){ $query->select('id','username'); }))->get();

It will only select id and username from other table. I hope this will help others.

No comments:

This will make you a better decision maker | Annie Duke (author of “Thinking in Bets” and “Quit”, former pro poker…

Annie is a former professional poker player, decision-making expert, author, and special partner at First Round Capital.  ͏     ­͏     ­͏   ...

Contact Form

Name

Email *

Message *