Menu Crud with Items #1310
Replies: 3 comments
-
I understand you're trying to create a menu system with Backpack where you can view all items belonging to a specific menu. This is a common pattern in admin panels. Based on the knowledge sources, there are a few approaches you could take: Option 1: Create a Custom OperationYou can create a custom operation in your MenuCrudController that displays the menu items for a specific menu. This would involve:
Here's how you might approach this: <?php
namespace App\Http\Controllers\Admin;
use Backpack\CRUD\app\Http\Controllers\CrudController;
class MenuCrudController extends CrudController
{
use \Backpack\CRUD\app\Http\Controllers\Operations\ListOperation;
use \Backpack\CRUD\app\Http\Controllers\Operations\CreateOperation;
use \Backpack\CRUD\app\Http\Controllers\Operations\UpdateOperation;
use \Backpack\CRUD\app\Http\Controllers\Operations\DeleteOperation;
use \Backpack\CRUD\app\Http\Controllers\Operations\ShowOperation;
// Your custom operation for viewing menu items
use \App\Http\Controllers\Admin\Operations\ViewMenuItemsOperation;
// Rest of your controller code...
} Option 2: Use MenuCRUD PackageBackpack actually has a MenuCRUD package that might help with what you're trying to accomplish. This package allows you to "Add, edit, reorder, nest, rename menu items and link them to Backpack\PageManager pages, external link or custom internal link." MenuCrud Option 3: Custom Route and MethodAnother approach is to add a custom route and method to your controller: // In routes/backpack/custom.php
Route::crud('menu', 'MenuCrudController');
Route::get('menu/{id}/items', 'MenuCrudController@items');
// In your MenuCrudController
public function items($id)
{
// Set up the CRUD panel for menu items
$this->setupListOperation();
$this->crud->addClause('where', 'menu_id', $id);
// Return a view with the items
return view('your-view-for-items', [
'crud' => $this->crud,
'menu' => Menu::find($id)
]);
} This is similar to the approach shown in the community forum where someone was trying to show only draft items with a custom route Help Needed with Controller and Route Setup. For the best implementation, I'd recommend creating a proper custom operation as it will integrate better with Backpack's architecture. The documentation doesn't provide a complete example of this specific use case, but it does explain how operations work in general. Would you like more specific guidance on implementing any of these approaches? ℹ️ Please note our AI Bot does not reply to follow-ups, this will be the only AI answer in this thread. If the AI helped you find the answer, please mark it as answered or write details below so it can learn. Then close the conversation. If not, please give more information for when a human reads this. ℹ️ Relevant sources: 4. Add-ons, License, and Support|Support Part 2 |
Beta Was this translation helpful? Give feedback.
-
It would be nice if I could also display the items in each menu in a table. I've already added an operation for this, but it gives me this error: Trying to access array offset on null |
Beta Was this translation helpful? Give feedback.
-
Hey @pixelpatron90 In the screenshot, I see that each menu has subitems. What kind of items are these? Are these relationship models?
|
Beta Was this translation helpful? Give feedback.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hello, I'm contacting you with a difficult problem.
I have a MenuCrudController in which I can create menus. In parallel, I need an operation in the actions that displays all the items in the respective menu in a new table.
I've already tried creating an operation, but it only worked moderately well.
What exactly would be the correct approach?
Beta Was this translation helpful? Give feedback.
All reactions