Search code examples
phplaravellaravel-5eloquentlaravel-5.3

Laravel Models Defining Columns Possible?


I just started playing with Laravel, and was wondering the following:

Can you define your table structure in the model, then create a migration based off it? (The way Django works).

 namespace App;

 use Illuminate\Database\Eloquent\Model;


 class SomeListing extends Model
 {
     // Below V V V V Define Columns

     public $title = ''; // somehow make a string(255)?
     public $description = ''; // somehow make a text?

     // etc
     // etc
 }

Or must you always adjust the migration files? I could not find this here.


Solution

  • I think it does not exist, but you can create migrations for your database with migrations

    Create migration

    php artisan make:migration create_table_name
    

    and

    php artisan migrate
    

    More info could be found at Laravel's Migration Document