rakibdevs / laravel-query-extra
Run complex SQL queries from API requests such as update different conditional records in a single query
Requires
- php: ^7.3|^8.0
- illuminate/database: ^6.0|^7.0|^8.0
- illuminate/support: ^6.0|^7.0|^8.0
Requires (Dev)
- orchestra/testbench: ^4.9|^5.8|^6.3
- phpunit/phpunit: ^9.0
This package is auto-updated.
Last update: 2022-08-25 04:49:40 UTC
README
✔ Contribute to improve the package! Thanks in advance.
Laravel Query Extra
Run complex SQL queries from API requests such as update different conditional records in a single query.
Installation
Install the package through Composer. On the command line:
composer require rakibdevs/laravel-query-extra
Configuration
If Laravel > 7, no need to add provider
Add the following to your providers
array in config/app.php
:
'providers' => [ // ... RakibDevs\QueryExtra\QueryExtraServiceProvider::class, ];
Usage
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.
License
Laravel Open Weather API is licensed under The MIT License (MIT).