How to select what columns to return when calling ::all()

Laravel: How to select what columns to return when calling ::all()

You can provide an array of column names to returns, such as:

  1. $posts = Posts::all(["post_name","id"]);

webdevetc profile pic

I am a 29 year old backend web developer from London, mostly focusing on PHP and Laravel lately. This ( is my blog where I write about some web development topics (PHP, Laravel, Javascript, and some server stuff). contact me here.


Comments and discussion about How to select what columns to return when calling ::all()

Found this interesting? Maybe you want to read some more in this series?

Or see other topics in the Laravel language

Or see other languages/frameworks:
PHP Laravel Composer Apache CentOS and Linux Stuff WordPress General Webdev and Programming Stuff JavaScript
Or see random questions

How to check if a (blade) view file exists

What are the SPL Iterators in PHP?

How to get the first row that matches some where queries, or create it if it doesn't exist (in Laravel's Eloquent)?

How to set custom HTTP headers in Apache (by editing .htaccess)

How to force gzip compression in Apache with .htaccess

What are the predefined variables in PHP?

How to show a specific view file for certain error codes?

How to find the average value of items in a Laravel Collection?

How to review blog posts (written by other users) before they get published on your WordPress blog?

How to check if a user is logged in, inside a blade file?