Download the PHP package schrosis/blade-sql without Composer
On this page you can find all versions of the php package schrosis/blade-sql. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Informations about the package blade-sql
blade-sql
Introduction
blade-sql provides the generation and execution of SQL using Blade, Laravel's template engine
When you want to write a complex SQL with more than 100 rows, isn't it hard to write it in the query builder?
Sometimes you want to write raw SQL for tuning purposes
In such cases, blade-sql is useful!
Requirements
- PHP(^7.3|^8.0)
- PDO
- Laravel:(^6.0|^7.0|^8.0)
Installation
Laravel uses Package Auto-Discovery, so doesn't require you to manually add the ServiceProvider
If you don't use auto-discovery, add the BladeSQLServiceProvider to the providers array in config/app.php
And if you use facade aliases, add BladeSQL to the aliases array
Copy the package config to your local config with the publish command
Usage
Create .blade.php file for blade-sql in resources/sql/ dir
Execute SELECT Query
Execute a query using the BladeSQL facade
The result of a select query is a Collection object of stdClass
You can also turn it into a Collection object of Models or your Entity
The entity method argument expects a class with a method named fromArray
Otherwise, you can use the Collection::map()
Execute INSERT UPDATE DELETE Query
You can also use the BladeSQL facade to perform an insert update delete query
The way to call these methods is the same as the select
The difference is that these methods return the number of rows that have been updated
Run on a specific connection
If you want to use a connection other than the default one, call the setConnection method
Also use it when doing a transaction
Blade Directives and Components
In addition to the basic features of blade, provides directives and components similar to Java's mybatis
@where
Erase the leading AND or OR and prefix it with WHERE
@where component is useful when using @if to create WHERE clauses
It will compile like this
If the $slot of @where is empty, the first WHERE is not attached
@set
Works just like @where
Remove the , at the end and prefix it with SET
@set component is useful when using @if to create a SET clause for an update query.
It will compile like this
@IN
@IN directive Create an IN clause from an array
If $id_list is [1, 2, 3], it will be compiled like this
@LIKE
@LIKE directive escapes values that are bound to the LIKE clause
If $name is 'strawberry 100%', then it will compile like this
And 'strawberry 100%' will be escaped to 'strawberry 100\%'
You can also easily add _ and %