https://github.com/jeidison/native-query
Laravel package for save native query in external file.
https://github.com/jeidison/native-query
laravel php sql
Last synced: about 1 year ago
JSON representation
Laravel package for save native query in external file.
- Host: GitHub
- URL: https://github.com/jeidison/native-query
- Owner: jeidison
- Created: 2019-08-26T01:04:43.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2023-03-03T15:51:19.000Z (about 3 years ago)
- Last Synced: 2025-02-22T15:03:22.409Z (about 1 year ago)
- Topics: laravel, php, sql
- Language: PHP
- Homepage:
- Size: 25.4 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Installation
```bash
$ composer require jeidison/native-query
```
# Publish Settings
```bash
$ php artisan vendor:publish --provider="Jeidison\NativeQuery\Provider\NativeQueryServiceProvider"
```
This will add the nativequery.php file in your config directory with the following contents:
```php
return [
'path-sql' => database_path('native-query'),
'type' => Jeidison\NativeQuery\Enums\FileType::PHP,
];
```
And this will add the native-query.xml file in your database directory with the following contents:
# SQL in file XML
```xml
SELECT * FROM TAB1 WHERE PAR1 = ?
```
And this will add the native-query.php file in your database directory with the following contents:
# SQL in file PHP
```php
CONST findTab1 = "
SELECT * FROM TAB1 WHERE PAR1 = :par1
";
```
# Add Trait in model
```php
...
class ModelX extends Model
{
use HasNativeQuery;
protected $queryFile = '/path/file-with-queries';
...
}
```
# Executing SQL
```php
ModelX::nativeQuery('findTab1')->param('par1', 'value1')->param('par2', 'value2')->exec();
ModelX::nativeQuery('findTab1')->param(['par1' => 'value1'])->exec();
ModelX::nativeQuery('findTab1')->param(['par1' => 'value1'])->->debug();
NativeQuery::query('findTab1')
->queryFile('/path/file-with-queries')
->param('par1', 'value1')
->exec();
```