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 run an artisan command from a controller

How to replace values in a string, in JS

How to add comments in PHP

How to change the order that migrations happen?

How to block IP addresses in Apache by using regular expressions (regex) in .htaccess

How to check if a string contains a certain substring?

What are the predefined variables in PHP?

How to get the type of a variable in JS?

What are the main error types in PHP

Why should you update APP_URL from from http://localhost?