paint-brush
7 Laravel Tips You Should Knowby@adidragocea
2,382 reads
2,382 reads

7 Laravel Tips You Should Know

by Adrian
Adrian HackerNoon profile picture

Adrian

@adidragocea

DigitalOcean Backups - Weap.io

March 14th, 2020
Read on Terminal Reader
Read this story in a terminal
Print this story
Read this story w/o Javascript
Read this story w/o Javascript
tldt arrow

Too Long; Didn't Read

7 Laravel Tips You Should Know: 7 Eloquent Tricks Every Laravel Developer Should Know. The get() method can accept an array with the columns which should be returned. Allow access to specific IP addresses when your application is in maintenance mode using the command artisan down. Unsigned columns in migrations are a common case for almost all applications. There is a better way to get the ID of the authenticated user using Auth::user()->id to retrieve the id of an authenticated user.

Company Mentioned

Mention Thumbnail
Different
featured image - 7 Laravel Tips You Should Know
1x
Read by Dr. One voice-avatar

Listen to this story

Adrian HackerNoon profile picture
Adrian

Adrian

@adidragocea

DigitalOcean Backups - Weap.io

Learn More
LEARN MORE ABOUT @ADIDRAGOCEA'S
EXPERTISE AND PLACE ON THE INTERNET.

Hello, my name is Adrian. After writing an article about 6 Eloquent Tricks Every Laravel Developer Should Know and receiving a better than expected feedback from the readers, I decided to show some more Laravel tips that are used at Weap.

The get() method can accept an array of columns to return

Did you know that the get() method can accept an array with the columns which should be returned? The same thing also works with the method all().

image


Allow access to specific IP addresses when your application is in maintenance mode

Laravel allows you to put your application in maintenance mode using the command artisan down. While in maintenance, the application will not be accessible by the users. But did you know that you can allow access to specific IP addresses?

image


Combined where conditions

Using combined where conditions is a common case for almost all applications. Did you know there is a different way to write them?

image


Getting the ID of the authenticated user

Very often I see developers using Auth::user()->id to retrieve the id of the authenticated user. There is a better way.

image

Faker optional()

Sometimes, in Weap's automated tests a backup record should be not completed. For such cases, Faker has the optional() method.

image

Unsigned columns in the migrations

When you have a relation between two tables, the column must be unsigned. To make the column unsigned, the unsigned() method is used. But there is a second way to achieve the same result.

image

Easier dd()

If you need to dd() the results of a query, there are two ways.

image

Stay Tuned!

Previously published at https://weap.io/blog/7-laravel-tips-you-should-know

L O A D I N G
. . . comments & more!

About Author

Adrian HackerNoon profile picture
Adrian@adidragocea
DigitalOcean Backups - Weap.io

TOPICS

THIS ARTICLE WAS FEATURED IN...

Permanent on Arweave
Read on Terminal Reader
Read this story in a terminal
 Terminal
Read this story w/o Javascript
Read this story w/o Javascript
 Lite
Senior
Roocket
Unni
Coffee-web
Hashnode
Learnrepo
X REMOVE AD