Laravel is a really cool framework. But there is always some improvements that can be made. This repository is like beta sandbox for it, before a potential pull requests on the official laravel git.
This library comes with some useful standalone classes:
-
Pagination\ByOffsetLengthAwarePaginator
(todo...) -
GPS\GPSCoordinates
(todo...) -
Selectors\Selector
(todo...) -
Services\Service
(todo...) -
Validation\Validator
(todo...)
(todo...)
(todo...)
(todo...)
(todo...)
(todo...)
(todo...)
(todo...)
(todo...)
This class inherits directly from Illuminate\Database\Eloquent\Model
but add some features, specifically about relations management.
Implements the CollectionOrModel
interface.
Allows the usage of getTable()
statically.
Allows the usage of getTableColumn()
statically.
Alias for qualifyColumn($column)
which has been added since.
This method has been overwritten to return a Jchedev\Laravel\Eloquent\Builders\Builder
instead.
If you decide to use your own Builder class, you should make it inherits from Jchedev\Laravel\Eloquent\Builders\Builder
first.
This method has been overwritten to return a Jchedev\Laravel\Eloquent\Collections\Collection
instead.
If you decide to return your own Collection class, you should make it inherits from Jchedev\Laravel\Eloquent\Collections\Collection
first.
This class inherits directly from Illuminate\Database\Eloquent\Collection
but add new methods.
Implements the CollectionOrModel
interface.
Returns a builder targeting only the items of the collection (using whereIn(primary_key, [...])
). This method expects all the items of the collection to be from the same Model (Mixing some "Users" to some "Comments" will create unwanted behavior).
Run an update query on the builder returned by builder()
.
Run an delete query on the builder returned by builder()
.
This class inherits directly from Illuminate\Database\Eloquent\Builder
but add new methods.
(todo...)
(todo...)
With the existing implementation of the count()
method, the limit
parameters is ignored. This method changes that.
Example with a total of 200 users:
User::take(10)->count() = 200
User::take(10)->countWithLimit() = 10
(todo...)
The default select()
method is not qualifying the column name. This one is.
The default where()
method is not qualifying the column name. This one is.
The default whereNull()
method is not qualifying the column name. This one is.
The default whereIn()
method is not qualifying the column name. This one is.
(todo...)
The default whereBetween()
method is not qualifying the column name. This one is.
This library comes with some extra exceptions:
UnexpectedClassException
(todo...)
This library comes with some extra middleware:
-
AuthNotRequired
(todo...) -
LogQueries
(todo...) -
MinifiedResponse
(todo...)
Calling a method that doesnt exist on the object will automatically forward the call to each Resource element.
Calling ::collection()
will return a Jchedev\Laravel\Http\Resources\Collection
object.
This library comes with some extra rules:
-
HandlesExceptions
-
HasCompositePrimaryKey
-
HasGPSCoordinates
-
HasReference
This library comes with some useful helpers:
array_get_any(array $array, array $keys, $default = null)
(todo...)
-
get_variable_type($variable)
The default gettype() method doesnt work if a Closure. This method does. -
get_class_basename($object)
: Accept a string or an object and return only the basename part of aget_class()
return on it. (Example:get_class_basename('Jchedev\Laravel\Console\Commands')
will return "Commands"). -
get_class_namespace($object)
: Accept a string or an object and return only the namespace part of aget_class()
return on it. (Example:get_class_basename('Jchedev\Laravel\Console\Commands')
will return "Jchedev\Laravel\Console").
-
sanitize_string($value)
Trim the string, except if value is NULL. -
boolean_to_string($value, $true = 'true', $false = 'false')
: Converts a boolean true/false into a string (Default values: "true" or "false"). -
null_if_empty($value)
: Check if a string is empty and return NULL if so. -
time_duration($string, $convert_in = 'second')
: Converts a readable string ("2 weeks", "1 month") into a number (based on $convert_in which accepts: "second", "minute", "hour", "day", "month", "year"). -
time_multiplier($from, $to)
: Return the time ratio between $from and $to. (Example:time_multiplier('minute', 'second')
will returns 60 since there is 60 seconds in 1 minute. -
table_column($table, $column)
: Appends a $table name to a $column. This helper is mainly used by the query builder. -
minify_html($html)
: Minify as much as possible some html content by removing unecessary tabs, comments and such and return the optimized string.