How to flatten an array in PHP
Try to use this code:
Coursecomp is your starting point for developing and maintaining your web application.
Try to use this code:
You should avoid using SQL functions in your Laravel Eloquent queries because they inflict full table scans. This happens due to database mechanisms – the condition is not applied until the date function has been run. It will produce a query like this: The better way: So we get this exact query, without the date() […]
To remove a column from a database table in Laravel, you need to create a migration, edit, and then run it in the command line interface. Create the migration You need to open your Laravel application folder in Terminal. Then run one of the following commands. Remember that you can skip typing underscore symbols, see […]
You can see if the column in your Laravel application DB is unique or not. For example, the article table has slug and author_id with the unique slug for each author. See the code below, it’s useful for multi-tenancy:
When you try to parse a date with Carbon, by default it will throw an exception when parsing an invalid date format. So you need to manually try/catch the exception in your code. But sometimes, you might need a false value rather than dealing with the exception. So here is the macro that will help […]
You can use conditions in Eloquent with relationships. For example, we’ve got a Team and its Users. We can define the relationship with the name “admins” which extends the user relation with a condition.
There are basically two options to manage Nginx configuration with Laravel Fore. 1. Create custom Nginx template before adding a site In the Servers section of the Forge panel, you should select Nginx Templates menu option, then add your custom name to the configuration file. Then, change the template file according to your needs and […]
This code snippet can be useful in authorizing form requests. For example, you get the post instance from the request and then check the user rights.
You can make some improvement to your code, if you want to reset the cache on creating or updating a Model in Laravel. See the code below:
Hello friends! As you may know now, since the version 9 of Laravel you can use the new way to define Eloquent accessors and mutators