PHP code example of jumilla / laravel-versionia

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

    

jumilla / laravel-versionia example snippets


$app->register(Jumilla\Versionia\Laravel\ServiceProvider::class);



namespace App\Providers;

use Jumilla\Versionia\Laravel\Support\DatabaseServiceProvider as ServiceProvider;
use App\Database\Migrations;
use App\Database\Seeds;

class DatabaseServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
        $this->migrations('framework', [
            '1.0' => Migrations\Framework_1_0::class,
        ]);

        $this->migrations('app', [
            '1.0' => Migrations\App_1_0::class,
        ]);

        // ... seed definition ...
    }
}

    'providers' => [
        ...
        App\Providers\ConfigServiceProvider::class,
        App\Providers\DatabaseServiceProvider::class,
        App\Providers\EventServiceProvider::class,
        ...
    ],

$app->register(App\Providers\DatabaseServiceProvider::class);



namespace App\Database\Migrations;

use Jumilla\Versionia\Laravel\Support\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class App_1_0 extends Migration
{
    /**
     * Migrate the database to forward.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('posts', function (Blueprint $table) {
            $table->increments('id');
            $table->string('title');
            $table->text('content');
            $table->json('properties');
            $table->timestamps();
        });
    }

    /**
     * Migrate the database to backword.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('posts');
    }
}



namespace App\Providers;

use Jumilla\Versionia\Laravel\Support\DatabaseServiceProvider as ServiceProvider;
use App\Database\Migrations;
use App\Database\Seeds;

class DatabaseServiceProvider extends ServiceProvider
{
    /**
     * Bootstrap any application services.
     *
     * @return void
     */
    public function boot()
    {
    	//... migration definition ...

        $this->seeds([
            'test' => Seeds\Test::class,
            'staging' => Seeds\Staging::class,
            'production' => Seeds\Production::class,
        ], 'test');
    }
}



namespace App\Database\Seeds;

use Jumilla\Versionia\Laravel\Support\Seeder;
use Carbon\Carbon;

class Staging extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        $now = Carbon::now();

        app('db')->table('posts')->truncate();

        app('db')->table('posts')->insert([
            'title' => 'Sample post',
            'content' => 'Hello laravel world.',
            'properties' => json_encode([
                'author' => 'Seeder',
            ], JSON_PRETTY_PRINT),
            'created_at' => $now,
            'updated_at' => $now,
        ]);
    }
}
sh
php artisan database:status
sh
php artisan database:upgrade
sh
php artisan database:upgrade --seed <seed>
sh
php artisan database:clean
sh
php artisan database:refresh
sh
php artisan database:refresh --seed <seed>
sh
php artisan database:rollback <group>
sh
php artisan database:again <group>
sh
php artisan database:again <group> --seed <seed>
sh
php artisan database:seed <seed>
sh
php artisan database:seed