PHP code example of peltonsolutions / laravel-pivot-table-helper

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

    

peltonsolutions / laravel-pivot-table-helper example snippets




use App\Models\User;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\Schema;
use PeltonSolutions\LaravelPivotTableHelper\Models\GenerateBelongsToManyMigration;

return new class extends Migration {
	/**
	 * Run the migrations.
	 */
	public function up(): void
	{
		GenerateBelongsToManyMigration::createMigration(
			(new User())->roles()
		);
	}

	/**
	 * Reverse the migrations.
	 */
	public function down(): void
	{
		Schema::dropIfExists((new User())->roles()->getTable());
	}
};





use App\Models\User;
use Illuminate\Database\Migrations\Migration;
use Illuminate\Support\Facades\Schema;
use PeltonSolutions\LaravelPivotTableHelper\Models\GenerateBelongsToManyMigration;

return new class extends Migration {
	/**
	 * Run the migrations.
	 */
	public function up(): void
	{
	    $instance = new User();
		GenerateBelongsToManyMigration::createMigration([
			$instance->relationship1(),
			$instance->relationship2(),
		]);
	}

	/**
	 * Reverse the migrations.
	 */
	public function down(): void
	{
		Schema::dropIfExists((new User())->roles()->getTable());
	}
};