rakibdevs/laravel-query-extra

This package is abandoned and no longer maintained. No replacement package was suggested.

Run complex SQL queries from API requests such as update different conditional records in a single query

dev-master 2021-05-21 05:45 UTC

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

GitHub stars GitHub forks GitHub issues GitHub license

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).