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 use Anonymous classes in PHP 7?

How to check if a (blade) view file exists

How to block access to certain referrers in Apache using .htaccess

How to undelete a soft deleted Eloquent row?

How to get table column names from a database table in Eloquent?

How to check if a relation was loaded on an Eloquent model already?

What does 'final class' and 'final function' (final method) mean in PHP?

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

How to add a name prefix to all routes in a group?

What is Bubble sort, and how to write an implementation of it in PHP