In this post, we gonna look at using Laravel’s Eloquent ORM and Query Builder methods to query data from the database where the field is null and where the field is not the null scenario. Check if null: whereNull […]
How to Connect to MySQL database in Slim framework 4
Defining MySQL database connection in the Slim 4 framework is pretty simple. In this slim framework 4 tutorial, we gonna create a project with Slim-Skeleton. If you are looking for Slim Framework 3, follow the link How […]
How to fix XAMPP server error xampp-control.ini Access is denied
We gonna fix the XAMPP access denied error in windows by running the application as an administrator. You can just right-click xampp-control.exe and you can run as administrator each time whenever you start XAMPP or you […]
How to Import and Export MySQL Databases
Export Database To export a database, open up the terminal, making sure that you are not logged into MySQL, and execute the below command with database details.
1 |
mysqldump -u [username] -p [database_name] > [database_name].sql |
PHP 8 – Nullsafe operator
The operator nullsafe allows a developer to eliminate the null check for each property before going onto the next chain of the property or method. It is very common to only want to call a method or fetch a property on […]
Custom Helper functions in Laravel
In this post, we gonna create custom functions and load it in the Laravel project. These functions can be accessible all over the project. Loading custom helper functions in Laravel is pretty straightforward. Let’s […]
Remove Empty Array Elements and reindex in PHP
The built-in array_filter() the function removes all the empty elements, zeros, false and null values from an array. This function uses a callback function to filter the array values. If no callback function is specified, […]
PHP 7.4 – Null coalescing assignment operator
The null coalescing assignment operator is a shorthand for null coalescing operations. Let’s take a example code
1 |
$data['date'] = $data['date'] ?? new DateTime(); |
PHP 7.4 – Arrow functions
Arrow functions also called “short closures”. We can always access the parent scope, there’s no need for the use keyword. Here is a simple example with an arrow function.
1 2 3 |
$items = [1,2,3,4,5]; $factor = 10; array_map(fn ($item) => $item * $factor, $items) |
Eloquent – A better way to increment or decrements an int
Laravel has in-built increment() and decrement() functions to increase or decrease a value of the column, by 1 or with the given number. Below are the examples:
1 |
User::find($user_id)->increment('post_count'); |