Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/yazeedobaid/laravel-jsonable
Eloquent like style for quering a JSON field in a MYSQL database
https://github.com/yazeedobaid/laravel-jsonable
Last synced: 7 days ago
JSON representation
Eloquent like style for quering a JSON field in a MYSQL database
- Host: GitHub
- URL: https://github.com/yazeedobaid/laravel-jsonable
- Owner: yazeedobaid
- License: mit
- Created: 2018-03-10T11:20:46.000Z (over 6 years ago)
- Default Branch: master
- Last Pushed: 2019-04-26T12:19:25.000Z (over 5 years ago)
- Last Synced: 2024-04-21T06:20:52.031Z (7 months ago)
- Language: PHP
- Homepage:
- Size: 6.84 KB
- Stars: 1
- Watchers: 0
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# Laravel-Jsonable
Eloquent like style for quering a JSON field in a MYSQL database.## Installation
Require this package, with [Composer](https://getcomposer.org/), in the root directory of your project.
``` bash
$ composer require yazeedobaid/jsonable
```## Usage
### Setup a Model
``` php
first();```
### OR JSON Contains
Add an ORed where clause to the query to checks if the JSON field contains text.
The first argument specify the JSON column name in DB, second argument is
the path in the JSON field and the third argument is the text to check if
JSON field contains.``` php
$post = Post::orJsonContains('body', 'title', 'Laravel')->first();
```
### JSON Extract
Add a select field to the query to select a value from the JSON field.
The first argument specify the JSON column name in DB and second argument is
the path in the JSON field.``` php
$post = Post::jsonExtract('body', 'title')->first();
```
### JSON Keys
Add a select field to the query to return all the keys in a JSON field.
The first argument specify the JSON column name in DB.``` php
$post = Post::jsonKeys('body')->first();
```
If JSON field is nested with obther JSON objects in it, you can add a second argument
for the nestd JSON object to return its keys``` php
$post = Post::jsonKeys('body', 'title')->first();
```
### JSON Search
Search for a value in a JSON field and returns the JSON path to that value. The first
argument specify the JSON column name in DB, the second argument specify to return all
the found results or the first one and the third argument is the text to search for.``` php
$post = Post::jsonSearch('body', 'one', 'Laravel')->first();
```
``` php
$post = Post::jsonSearch('body', 'all', 'Laravel')->first();
```