PHP code example of socoladaica / laravel-table-prefix

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

    

socoladaica / laravel-table-prefix example snippets




namespace App;

use Illuminate\Database\Eloquent\Model;
use Socoladaica\LaravelTablePrefix\HasTablePrefix;

class Post extends Model
{
    use HasTablePrefix;

    protected $prefix = 'blog_';

}



namespace App;

use Illuminate\Database\Eloquent\Relations\Pivot;
use Socoladaica\LaravelTablePrefix\HasTablePrefix;

class CategoryPost extends Pivot
{
    use HasTablePrefix;

    protected $prefix = 'blog_';

}



namespace App;

use Socoladaica\LaravelTablePrefix\HasTablePrefix;

trait BlogPrefix
{
    use HasTablePrefix;

    /**
     * The table prefix associated with the model.
     * 
     * @var string
     */
    protected $prefix = 'blog_';

}



namespace App;

use Illuminate\Database\Eloquent\Model;

class Post extends Model
{
    use BlogPrefix;

}



namespace App;

use Illuminate\Database\Eloquent\Relations\Pivot;
use Socoladaica\LaravelTablePrefix\HasTablePrefix;

class CategoryPost extends Pivot
{
    use BlogPrefix;

}


class CreateSocolaCmsBlogDatabase extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {

        Schema::create(Post::getTableName(), function (Blueprint $table) {
            $table->id();
            $table->timestamps();
        });

        Schema::create(Category::getTableName(), function (Blueprint $table) {
            $table->id();
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists(Post::getTableName());
        Schema::dropIfExists(Category::getTableName());
    }
}