Back to blog

P5 | Creating Your First CRUD with Craftable PRO for Laravel

Aug 16, 2024
.
Samuel Trstenský

Hello everyone! I’m Samuel from the Craftable PRO team. In this part, we’re diving into CRUD generation—creating, reading, updating, and deleting records—for our 'trainings' table. We’ll generate a complete admin module that includes listing, create, edit, and delete functionalities. Let’s get started!

Setting Up the CRUD Generator

With Craftable PRO, there are two main ways to generate CRUD: the interactive wizard mode or by typing parameters directly. Today, I’ll show you how to use the interactive wizard, which is especially useful for first-time users.

In your terminal, enter the following command to launch the CRUD wizard for the 'trainings' table:

sail art craftable-pro:generate-crud trainings -w

Step-by-Step Guide Through the Wizard

  1. Listing Page Columns: The first step is deciding what to display on the listing page. We’ll keep it simple by displaying only the title column. The id column will be automatically included.
  2. Sorting Options: For sorting, we’ll select both id and title, making it easy to sort trainings by either field. Since these are default options, simply pressing enter will select them.
  3. Form Page Columns: Next, we’ll choose columns for the create/edit form. Here, we want all columns editable, so we press enter to include them.
  4. Translatable Columns: Craftable PRO supports Localization, and since title and text are jsonb types, they’re translatable by default. We confirm both as translatable by pressing enter.
  5. Media Upload: Craftable PRO includes a media management feature, which was set up during installation. For our trainings table, we’ll add a media collection called cover for images associated with each training session.
  6. Relationships: While Craftable PRO supports relationships, we’ll skip this step for now, as trainings doesn’t yet link to other tables. Stay tuned for our next video, where we’ll explore this further with the exercises table.
  7. Export Feature: Craftable PRO allows exporting data to Excel. To demonstrate this feature, we’ll enable it by selecting “yes.”

Completing the CRUD Generation

Once the wizard completes, Craftable PRO generates the necessary controllers, models, views, requests, and permissions, allowing us to assign CRUD-specific permissions to roles. Let’s switch over to the admin panel to see the new module in action.

Testing the 'Trainings' Module

<br>

In our admin panel, we can now see a fully functional trainings module. Let’s add a new training session to see it in action. Notice how we can input data in multiple languages, thanks to Craftable PRO’s built-in localization support. After saving, the new training appears in the listing, where we can view, edit, or delete it as needed.


With this setup, our admin panel is beginning to take shape! In the next video, we’ll generate CRUD for 'exercises' and introduce our first relational setup in Craftable PRO. See you next time!