Download the PHP package corephp/slim-eloquent without Composer
On this page you can find all versions of the php package corephp/slim-eloquent. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download corephp/slim-eloquent
More information about corephp/slim-eloquent
Files in corephp/slim-eloquent
Package slim-eloquent
Short Description Wrapper dependency for eloquent database
License Apache-2.0
Informations about the package slim-eloquent
Eloquent dependency wrapper for Slim 3
This is a simple wrapper of Eloquent ORM for Slim 3. It provides a Parser class to generate connections option from a standard database URL of PostgresSQL, MySQL or SQLite databases.
Dependencies
Installation
You can use the slimcmd tool to install this dependency:
Or you can setup manually:
Allowed Database URLs
Te allowed formats of database connections are:
MySQL
PostgreSQL
SQLite
Using Parser class
The Parser class has 3 available methods to generate conection opctions for Eloquent:
- parseConnection: Parse connection strings for MySQL, PostgreSQL and SQLite connections.
- parseGeneral: Parse connections for MySQL and PostgreSQL only.
- parseSqlite: Parse connections for SQLite only.
The parseConnection
and the parseGeneral
function generates a configuration array as it shown below when pass a PostgreSQL or MySQL connection:
The parseConnection
and the parseSqlite
function generates a configuration array as shown below when pass a SQLite connection.
Examples
Eloquent Wrapper
This class allows you to create the main connection to embed as dependency on Slim.
You can generate a database.php
file your dependencies section with the code below:
This generates the main connection and boot Eloquent to use the models. Also you can setup a read and write configuration with diferent databases.
Base Model class
This packages provides a predefined base model class that brings you the most basic configuration of Models that you need and you can use it as shown below:
The Model class has 2 preconfigured functions:
- getDateFormat: Has the date format definition as 'Y-m-d H:i:s'
- scopePagination: Scope that can be aded at the end of a chain of query
filters to generate paginated sections of a single query. This scope has 3
parameters: $limit, $page and $links in that order.
$limit
: Is the number of elements by page that will be retrived by the query.$page
: Page that will be retrived. I you set a number lower than 1, you will always have the page 1, and if you set a number greater than the total of pages, you will always have the last page posible.$links
: this is a boolean parameter, if you set as true, this generates an extra key on the resultant array named links that will have the pagination sections in an array like this:[1, 2, 3, 4, 5, 6, '...', 100]
. this can Helpyou to generate a custom pagination for your datatables.