1. Go to this page and download the library: Download noouh/migration-to-model 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/ */
noouh / migration-to-model example snippets
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateUsersTable extends Migration
{
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('email')->unique();
$table->foreignId('profile_id')->constrained();
$table->timestamps();
});
}
public function down()
{
Schema::dropIfExists('users');
}
}
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class User extends Model
{
use HasFactory;
protected $table = 'users';
protected $fillable = ['name', 'email', 'profile_id'];
public function profile()
{
return $this->belongsTo(Profile::class, 'profile_id', 'id');
}
}