iambegineer
iambegineer

Reputation: 413

What is the use of strict in Laravel config/database?

I have to turn off the strict in config/database file as I need to use group by in my SQL query.

What is the use of strict in Laravel config/database and by turning it off or strict = false will it affect the website? Will it make our website security weak?

What is the disadvantage of turning strict off in Laravel config/database?

Upvotes: 34

Views: 26389

Answers (2)

Hashan
Hashan

Reputation: 180

Since the raw query in MySQL is running and shows you the desired result, you can replicate this behavior in your Laravel application by turning off strict mode.

Upvotes: 0

EddyTheDove
EddyTheDove

Reputation: 13259

According to the doc:

Strict mode controls how MySQL handles invalid or missing values in data-change statements such as INSERT or UPDATE. A value can be invalid for several reasons. For example, it might have the wrong data type for the column, or it might be out of range. A value is missing when a new row to be inserted does not contain a value for a non-NULL column that has no explicit DEFAULT clause in its definition. (For a NULL column, NULL is inserted if the value is missing.) Strict mode also affects DDL statements such as CREATE TABLE.

Read more here: https://dev.mysql.com/doc/refman/5.7/en/sql-mode.html#sql-mode-strict

Disabling it wouldn't make your website unsecured if you handle all validations in your controllers and follow best practices like Laravel already does out of the box.

Upvotes: 53

Related Questions