PHP code example of tobymaxham / laravel-properties

1. Go to this page and download the library: Download tobymaxham/laravel-properties 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/ */

    

tobymaxham / laravel-properties example snippets




namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use TobyMaxham\LaravelProperties\Traits\UseProperties;

class YourEloquentModel extends Model
{
    use UseProperties;
}



use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

return new class extends Migration
{
    public function up(): void
    {
        Schema::create('your_eloquent_models', function (Blueprint $table) {
            $table->id();
            
            $table->json('properties');
            
            // ...
            
            $table->timestamps();
        });
    }

    public function down(): void
    {
        Schema::dropIfExists('your_eloquent_models');
    }
};


$model = new EloquentModel();
$model->setProperty('key', 'value');
$model->save();


$model->setProperty('foo.bar', 'value');

$model->getProperty('foo.bar'); // 'value'

$model->getProperty('foo.baz', 'another Value'); // 'another Value'