Skip to main content

Models, Migrations, Artisan Commands

Premium
4 min read

In our specific package case, we didn't need some features, but I do want to mention them and show you how to use them, in case your packages need them.


Eloquent Models

This one is pretty easy, you just create a Model class in the /src/Models of the package and namespace it correctly.

Then, your Controllers (or the Controllers outside the package) may just use the Model by loading it from the correct namespace....

The Full Lesson is Only for Premium Members

Want to access all of our courses? (29 h 46 min)

You also get:

55 courses
Premium tutorials
Access to repositories
Private Discord
Get Premium for $129/year or $29/month

Already a member? Login here

Comments & Discussion

N
Nour ✓ Link copied!

It's very useful thank you very much

W
WAME ✓ Link copied!

For migrations, I would not overwrite the migration creation date What if someone runs the publish of your package, it creates a new migration file for them, and after running `php artisan migrate' it displays an error that such a table already exists

M
Modestas ✓ Link copied!

We are not talking about constant update on the timestamp. It is more of a:

You can change the timestamp as much as you want BEFORE the first commit

Changing it after a commit - is a bad thing indeed!

W
WAME ✓ Link copied!

I use php artisan vendor:publish --all in composer.json to update my packages after composer update, I often forgot about vendor:publish

{
...
"scripts": {
"post-update-cmd": [
"@php artisan vendor:publish --all"
]
}
}

A similar problem with creating a new migration again and again was e.g. in spatie/laravel-medialibrary I created a PR that search a file by name without a date and they approved it https://github.com/spatie/laravel-medialibrary/pull/3299/commits/96fd55782f8d0ada7360e139bf2e385f4750f925

We'd Love Your Feedback

Tell us what you like or what we can improve

Feel free to share anything you like or dislike about this page or the platform in general.