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
webdevetc

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



More...


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 split a string into an array, in JS

How do you access the php://input stream?

How to show (or log) all SQL queries executed by Laravel

How to check if two strings are anagrams in PHP?

What is the difference between reference and primitive data types types in Javascript?

How could you include a custom function for every single time PHP runs?

How to force SSL in Apache's .htaccess?

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 Extract Query String (from a URL) Into an Associative Array in PHP

What are generators in PHP, and how do they compare to arrays?