PHP code example of teguh02 / filament-db-sync

1. Go to this page and download the library: Download teguh02/filament-db-sync 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/ */

    

teguh02 / filament-db-sync example snippets



use Teguh02\FilamentDbSync\FilamentDbSync;

public function panel(Panel $panel): Panel
{
    return $panel
    // ... another filament configuration
        ->plugins([
            FilamentDbSync::make(),
        ]);
}



namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Items extends Model
{
    use HasFactory;

    // Define the fillable property to 
    // allow mass assignment on the model
    // and the database sync process
    protected $fillable = [
        'name',
        'description',
        'price',
        'stock',
        'expired_at',
    ];

    // Define the casts property to
    // automatically cast the data type
    // of the model attributes
    protected $casts = [
        'stock' => 'integer',
        'price' => 'integer',
        'expired_at' => 'date',
    ];
}



// config for Teguh02/FilamentDbSync
return [

    /**
     * The host where the data will be synced
     */
    'sync_host' => env('SYNC_HOST', 'http://localhost'),

    /**
     * The token to be used for authentication
     */
    'auth_token' => env('SYNC_TOKEN', 'default_token'),

    /**
     * Models configuration
     */
    'models' => [
        /**
         * If set to true, the package will
         * automatically scan all models in the app/Models directory
         */
        'auto_scan' => env('AUTO_SCAN_MODELS', true),

        /**
         * If auto_scan is set to true,
         * this configuration will be used to exclude models
         * which will not be synced
         */
        'excluded' => [
            // App\Models\User::class,
        ],

        /**
         * When auto_scan is set to false,
         * this configuration will be used to 
bash
php artisan vendor:publish --provider="Teguh02\FilamentDbSync\FilamentDbSyncServiceProvider"
php artisan migrate