Last updated
Last updated
Masonite 2 brings an incredible new release to the Masonite family. This release brings a lot of new features to Masonite to include new status codes, database seeding, built in cron scheduling, controller constructor resolving, auto-reloading server, a few new internal ways that Masonite handles things, speed improvements to some code elements and so much more. We think developers will be extremely happy with this release.
Upgrading from Masonite 1.6 to Masonite 2.0 shouldn't take very long. On an average sized project, this upgrade should take around 30 minutes. We'll walk you through the changes you have to make to your current project and explain the reasoning behind it.
Checkout the
Controller constructors are now resolved by the container so this removed some redundancy within your code and any duplicated auto resolving can now be directly in your constructor:
Read more in the documentation.
There is a new command that starts a Python shell and imports the container for you already. Test it out to verify that objects are loaded into your container correctly. It's a great debugging tool.
Masonite 2 ships with an awesome little helper command that allows you to see all the routes in your application
A huge update to Masonite is the new --reload
flag on the serve command. Now the server will automatically restart when it detects a file change. You can use the -r
flag as a shorthand:
An incredible new feature is autoloading support. You can now list directories in the new AUTOLOAD
constant in your config/application.py
file and it will automatically load all classes into the container. This is great for loading command and models into the container when the server starts up.
You can also use this class as a standalone class in your own service providers.
Updated all libraries to the latest version with the exception of the Pendulum library which latest version is a breaking change and therefore was left out. The breaking change would not be worth it to add the complexity of upgrading so you may upgrade on a per project basis.
Previously you had to import classes like:
Now you can simply specify:
Because of this change we no longer need the same duplicated class names in the PROVIDERS list either.
Removed the need for the redirection provider completely. You need to remove this from your PROVIDERS
list.
Renamed Request.redirectTo
to Request.redirect_to
Also removed the .send() method and moved the dictionary into a parameter:
Added a new Request.only method to fetch only specific inputs needed.
Added a new Request.get_request_method()
method to the Request
class.
You can now completely remove fetching of any inputs that Masonite handles internally such as __token and __method when fetching any inputs. This is also great for building third party libraries:
Because of the changes to internal framework variables, there are several changes to the CSRF middleware that comes in every application of Masonite.
Added a new default package to Masonite that allows scheduling recurring tasks:
It's important during development that you have the ability to seed your database with dummy data. This will improve team development with Masonite to get everyones database setup accordingly.
Now all templates have a new static function in them to improve rendering of static assets
You can use the password helper to hash passwords more simply than using straight bcrypt:
You can now specify which location in your drivers you want to upload to using a new dot notation:
This will use the directory stored in:
Masonite 2 removes the bland error codes such as 404 and 500 errors and replaces them with a cleaner view. This also allows you to add custom error pages.
Providers are now explicitly imported at the top of the file and added to your PROVIDERS list which is now located in config/providers.py
. This completely removes the need for string providers and boosts the performance of the application sustantially
Read more in documentation.
Read more in documentation.
Read more in Introduction documentation.
Read more in documentation.
Read more about changing duplicated class names under the documentation.
Read more in the documentation.
Read more in documentation.
Read more in documentation.
Read more in documentation.
Be sure to read the changes in the .
Read about Masonite Scheduler under the documentation.
Read more in the documentation.
Read more in the documentation.
Read more in the documentation.
Read more in the documentation.
Read more in the documentation.