If you would like to generate / build model files for our existing database tables, Open the terminal or command prompt and install the following package,
composer require "laracademy/generators" --dev
Once you have completed the above step, just run below PHP command inside your project root directory:
php artisan generate:modelfromtable --schema="ENTER_YOUR_DATABASE_NAME"
Another option is,
Open the generated model file located in the app directory and specify the table name and fillable fields of the database table. For example
namespace App;
use Illuminate\Database\Eloquent\Model;
class ModelName extends Model
{
protected $table = 'db_table_name';
protected $fillable = [
'field_name1',
'field_name1',
// add more fillable fields here
];
}
Comments (0)