✔ Contribute to improve the package! Thanks in advance.
Run complex SQL queries from API requests such as update different conditional records in a single query.
Install the package through Composer. On the command line:
composer require rakibdevs/laravel-query-extra
If Laravel > 7, no need to add provider
Add the following to your providers
array in config/app.php
:
'providers' => [
// ...
RakibDevs\QueryExtra\QueryExtraServiceProvider::class,
];
Suppose we need to update categories
table when cat_id 3 then cat_name will be 'Category 3' and cat_id 4 then cat_name will be 'Category 4' and so on...
To update multiple records in a single query,
$arrr = array(
array(
'data' => array(
'cat_name' => 'Category 3', // column name
'status' => 1 // column name
),
'keyval' => 3 // column value for whereKey() condition
),
array(
'data' => array(
'cat_name' => 'Category 2', // column name
'status' => 1 // column name
),
'keyval' => 2 // column value for whereKey() condition
),
array(
.......................
.......................
);
use RakibDevs\QueryExtra\QueryExtra;
(new QueryExtra)
->table('categories') // add table name
->whereKey('cat_id') // key which apply the condition
->bulkup($arrr); // updated array
Note: 'data' of all items must have same columns.
Laravel Open Weather API is licensed under The MIT License (MIT).