Download the PHP package ceddyg/query-builder-repository without Composer
On this page you can find all versions of the php package ceddyg/query-builder-repository. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download ceddyg/query-builder-repository
More information about ceddyg/query-builder-repository
Files in ceddyg/query-builder-repository
Package query-builder-repository
Short Description Repository using query builder. To return a Collection of stdClass or a simple stdClass. It's faster and use less memory than Eloquent if you just want data from database.
License MIT
Informations about the package query-builder-repository
Query Builder Repository
Laravel Repository using Query Builder (Fluent) instead of Eloquent. It returns a Collection of StdClass or a simple StdClass. It can receive arrays to create or update a record in the database and also delete a record or multiple record.
Installation
Usage
Create a repository
Firstly you have to create a repository and define the table, primary key and fillable.
By default the table will take the snake case in the plural of the repository's name without "Repository" and primary key is "id" by default.
Avaible methods
- all(array $aColumns)
- find(int $id, array $aColumns)
- findByField(string $sField, mixed $mValue, array $aColumns)
- findWhere(array $aWhere, array $aColumns)
- findWhereIn(string $sField, array $aWhere, array $aColumns)
- findWhereNotIn(string $sField, array $aWhere, array $aColumns)
- first(array $aColumns)
- last(array $aColumns)
- paginate(int $iLimit, array $aColumns, string $sPageName, int $iPage)
- create(array $aAttributes)
- update(int $id, array $aAttributes)
- updateOrCreate(array $aAttributes)
- delete(array|int $id)
Additional methods
- getTable
- getPrimaryKey
- getFillFromView
- orderBy
- limit
- datatable
all
Get all record in the database.
find
Find a record with his ID.
findByField
Find records with a given field.
findWhere
Find records with a given where clause.
findWhereIn
Find records with a given where in clause.
findWhereNotIn
Find records with a given where not in clause.
first
Return the first record.
php $oRepository = new ProductRepository();
$oRepository->last(); //StdClass //or $oRepository->last(['name']); //StdClass html
ID | Name | Price | Category | Tag | Tag Category |
---|
javascript
$(document).ready(function() {
$('#tab-admin').DataTable({
serverSide: true,
ajax: {
url: '../ajax-url'
},
columns: [
{ data: "id" },
{ data: "name" },
{ data: "price" },
{
data: "category_name",
name: "category.name"
},
{
data: "tag_name",
name: "tag.name",
//If you have many tag and want to replace ' / '
render: function ( data, type, row, meta ) {
return data.replace(" / ", ""); ;
}
},
{
data: "category_tag_name",
name: "tag.category_tag.name"
},
//Add a button to edit
{
data: "id",
render: function ( data, type, row, meta ) {
var render = "{!! Button::warning('Edit')->asLinkTo(route('admin.admin.edit', 'dummyId'))->extraSmall()->block()->render() !!}";
render = render.replace("dummyId", data);
return render;
}
},
//Add a button to delete
{
data: "id",
render: function ( data, type, row, meta ) {
var render = '{!! BootForm::open()->action( route("admin.admin.destroy", "dummyId") )->attribute("onsubmit", "return confirm(\'Are you sure to delete ?\')")->delete() !!}'
+'{!! BootForm::submit("Delete", "btn-danger")->addClass("btn-block btn-xs") !!}'
+'{!! BootForm::close() !!}';
render = render.replace("dummyId", data);
return render;
}
}
],
//Don't sort edit and delete column
aoColumnDefs: [
{
bSortable: false,
aTargets: [ -1, -2 ]
}
]
});
} );
#### orderBy
Order by a given field and direction. By defalut, the direction is 'asc'.
#### limit
Limit the query.
## Timestamp
You can automatically set a timestamp to a record.
## Date
You can specify the default date format from the database and the default date format to store in the database.
Then if you have 2017-05-24 in your database you will have :
## Custom attribute
You can get specific attribute.
And you can use it simply.
You can specify what column you need for your custom attribute in the class.
And then.
## Relationship
To configure relationship, it's like Eloquent, you have to define a belongsTo, belongsToMany or hasMany with other repositories.
Relations are considered like columns, so to add it :
To use it with [getFillFromView](#getfillfromview) you have to define what relations you allow :
You can specify if the relations are returned as array or collection.
## Connection
You can specify a database (set in config/database.php).
Or
## ToDo List
- Add specific setter
- Select only the fillable's relation in the getFillFromView method (if we have $oItem->tag->tag_name in the view, the system have to select tag_name only)
- Add through relation
- Mix paginate and avaible methods
- Add a command to generate repository