-
Notifications
You must be signed in to change notification settings - Fork 2
Models
The Model layer represents the domain modal (such as User, Category, Product, etc...) and encapsulates the business logic specific to your application. Alpha uses the Illuminate Database. For more information on how to use the Illuminate Database, visit Eloquent for an in-depth understanding of the framework.
Creating a model creates a corresponding migration. To create a model, run the command in your project root directory
php alpha g:model ModelName
This creates the model in your app/models
directory and a migration in your app\migrations
directory. Everything from there is just like Eloquent.
After adding all your DB tables you can then run php alpha db:migrate
to push to the database
Modifying database tables can be tiring if you are doing it directly from the database. This can cause problems when your local database and your production database are not in sync. Migrations can in handle for this very purpose. You can run
php alpha g:migration name_of_migration
This will generate a migration file with the name provided to it. In the migration file, you can then do all the modifications to your database and run php alpha db:migrate
to run the migration.
There are occasions where you might want to correct some errors in the migration file. You can run a rollback to undo the changes that were done with php alpha db:rollback STEP
where STEP
is the migration file number from the bottom of the migration directory. So your last migration will have a STEP
of 1 making your migration php alpha db:rollback 1
. To run a complete rollback for all migrations, you can run php alpha db:rollback all
.