Home Arrow Icon Knowledge base Arrow Icon Global Arrow Icon How do I integrate Twill's admin UI into an existing Laravel controller
    Twill integration Laravel controller Twill admin UI Laravel development Twill module PHP Laravel


How do I integrate Twill's admin UI into an existing Laravel controller


To integrate Twill's admin UI into an existing Laravel controller, you can follow these steps:

1. Install and Set Up Twill: First, make sure you have Twill installed and configured in your Laravel application. Follow the Twill installation guide to set up Twill properly.

2. Create a Twill Module: Use the Twill Artisan command to create a new module that you want to integrate into your existing controller:


   php artisan twill:module my-module
   

This will create the necessary files and database migrations for your new module.

3. Customize the Twill Module: Modify the generated module files to match your existing application's data models and requirements. This includes updating the `Form`, `Browser`, and `Controller` classes.

4. Integrate the Twill Admin UI: In your existing Laravel controller, you can now integrate the Twill admin UI by using the `TwillController` class as a base class and leveraging Twill's built-in functionality.

Here's an example of how you can do this:

php
   namespace App\Http\Controllers;

   use A17\Twill\Http\Controllers\Admin\ModuleController as TwillController;
   use App\Http\Requests\MyModuleRequest;
   use App\Models\MyModule;

   class MyModuleController extends TwillController
   {
       protected $moduleName = 'my-module';
       protected $modelName = 'MyModule';

       public function __construct()
       {
           parent::__construct();
           $this->setUpController();
       }

       protected function setUpController(): void
       {
           $this->setPermalinkBase('my-module');
           $this->enableReorder();
       }

       public function index()
       {
           return $this->listing();
       }

       public function create()
       {
           return $this->formView();
       }

       public function store(MyModuleRequest $request)
       {
           return $this->handleForm($request);
       }

       // Add more CRUD methods as needed
   }
   

In this example, we're extending the `TwillController` class and overriding the necessary methods to integrate the Twill admin UI into our existing controller.

5. Update Routes and Navigation: Ensure that your routes and navigation are set up correctly to access the Twill admin UI. You can either add the Twill routes to your existing routes file or create a separate routes file for the Twill admin console.

Additionally, you can customize the Twill navigation to include your new module by modifying the `config/twill.php` file.

By following these steps, you can seamlessly integrate Twill's admin UI into your existing Laravel application, allowing you to leverage Twill's powerful features and functionality within your custom controllers and models.

Citations:
[1] https://github.com/area17/twill/issues/192
[2] https://tech.codivores.com/ltivt-5-laravel-twill-first-module
[3] https://twillcms.com/docs/getting-started/installation.html
[4] https://github.com/area17/twill/releases
[5] https://dev.to/themeselection/the-ultimate-laravel-resourcesfor-developers2022-2nae