Is it possible to create a model from mysql database table in laravel
I know that in Laravel we can create a model and migrate them into database.
model > migrate > table to SQL server.
But my question is there any way to inverse this operation.
i.e
SQL server > table_name :
class table_name extends Model
{
//
}
Whatever the table you have created in your mysql, you just have to create a Model like this
<?php
namespace App;
use Illuminate\Database\Eloquent\Model;
class TableName extends Model
{
/**
* The database table used by the model.
*
* @var string
*/
protected $table = 'table_name';
}
And it will start functioning as you want.
Migrations has nothing to do with it and are optional but very useful if you are working on different dev environments, better use that.
I hope it helps