Download the PHP package oza/laravel-database-jsonable without Composer
On this page you can find all versions of the php package oza/laravel-database-jsonable. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download oza/laravel-database-jsonable
More information about oza/laravel-database-jsonable
Files in oza/laravel-database-jsonable
Package laravel-database-jsonable
Short Description Laravel package to fill and retrieve your database fields in JSON formats
License MIT
Informations about the package laravel-database-jsonable
Laravel package to fill and retrieve your database fields in JSON formats
this package allows you to fill some fields of your model in json format. For example, if you have a posts table, which has a field of action where you can put the actions as the number of comments likes etc ... you can easily do it with this package
Installation
Usage
-
Just add
DatabaseJsonable
trait and$jsonable
property that contains jsonable fields to your model.Api
-
Now your
actions
field will be a Jsonable class that contains lots of methods that you can use to add, edit, remove items in your field - You can also add data like this
If you do this, all the fields contained in the jsonable property of your model will be directly encoded in json and saved
-
Define Schema for jsonable field
Always typing an array to be transmitted can be a bit tiring. To allow you to save your energy and continue coding pretty Laravel application, the jsonable fields can take a schema to follow. To add it, just modify your jsonable property like that:
Then you can easily add data like this:
You can also use strict mode by adding
strictJsonableSchema
property- Retrieve data
All items saved are Laravel Collection, which gives you access to many methods that you can use to make your life easier.
-
-
You can also retrieve data like this
-
Get First item
-
Get last Item
- Get with id
Get an item with its id
- Change value or add new entry
change the value of an entry in your jsonable field
- Update an Item
Totally change an entry
-
Remove an item
- Add timestamps to entries
just set jsonableTimestamps
to your model
Then when you add some items the timestamps will be set
- Each item is a Laravel Collection
As I mentioned above all items are Laravel collections, which opens the door to many methods on array. For all available methods, see here Laravel Collection