PHP code example of denismitr / laravel-json-attributes
1. Go to this page and download the library: Download denismitr/laravel-json-attributes library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
denismitr / laravel-json-attributes example snippets
Schema::create('orders', function (Blueprint $table) {
$table->increments('id');
$table->string('description');
$table->jsonData('json_data');
});
use Denismitr\JsonAttributes\JsonAttributes;
use Illuminate\Database\Eloquent\Builder;
use Illuminate\Database\Eloquent\Model;
class Record extends Model
{
protected $casts = ['json_data' => 'array'];
/**
* @return JsonAttributes
*/
public function getJsonDataAttribute(): JsonAttributes
{
return JsonAttributes::create($this, 'json_data');
}
/**
* @return Builder
*/
public function scopeWithJsonData(): Builder
{
return JsonAttributes::scopeWithJsonAttributes('json_data');
}
}