The Journey to migrate to Laravel
Introduction
Recently, during my research on the integrations we are working on, I was able to recreate the file structure, routing, service providers, and blade of the Laravel framework. This led me to a realization - October CMS uses the Laravel framework core behind the scenes, so all Laravel features should be available out of the box. With this in mind, I started an experiment to see if this could be applicable. First, I created the routes directory with the same files that come with Laravel by default and tried to register some routes. However, the routes were never registered. To fix this, I created a service provider like the RoutesServiceProvider which comes with Laravel to register the routes, and it worked! Unfortunately, all of the October CMS routes we had got broken. I searched for where October CMS is doing its thing (routing) and adjusted the web.php a little. This single line is responsible for delegating all requests coming to October to the right page. This made everything seem fine, and I was able to navigate through the system normally. But after a few tests, I realized that the backbone was no longer working. After tinkering, I found the issue with the RoutesProvider I created - it was blocking the rest of the October CMS routes from getting registered. With a few adjustments, it worked fine. I tested the controllers and blade views, and all worked just fine.
Controller:
<?phpnamespace App\Http\Controllers; class WelcomeController{ public function index() { return view('welcome',[ 'foo' => 'bar' ]); }}
View:
<!DOCTYPE html><html lang="en"> <head> <meta charset="UTF-8"> <meta http-equiv="X-UA-Compatible" content="IE=edge"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <title>From blade</title></head> <body> <ul> <li>{{ user() }}</li> </ul></body> </html>
Summary
This draft demonstrates the concept and the ability to migrate to Laravel while working with October CMS, avoiding the cost of rebuilding and starting from scratch. The process may take longer, but the final result will be worth it. The changes are available on GitLab on the Migrate-to-laravel-draft branch.
In conclusion, the experiment to migrate to Laravel while working with October CMS was successful. By creating a service provider to register Laravel routes and making adjustments to the October CMS routing mechanism, the backbone of the system was not affected and Controllers and Blade views continued to work properly. While the process may take longer, this approach allows us to avoid the cost of rebuilding and starting from scratch. The changes are available on GitLab on the Migrate-to-laravel-draft branch.