Laravel-Backpack / CRUD

Build custom admin panels. Fast!
https://backpackforlaravel.com
MIT License
3.15k stars 891 forks source link

How to Create a CRUD Master Detail #451

Closed fabriciolangermt closed 7 years ago

fabriciolangermt commented 7 years ago

Is there any way to create a CRUD where items / details get together with the master fields

tabacitu commented 7 years ago

Hi, @fabriciolangermt . Sorry, I don't understand.

fabriciolangermt commented 7 years ago

I'm from Brazil, and I do not know English very well, so I'm using Google Translate. Rss But my doubt is how to make a registration form master / details. A simple case would be sale / items Where I have the fields of sale (customer, form of payment, etc.) and a list of items (product, quantity, price, total) But all this in one form

tabacitu commented 7 years ago

Hmm. I guess you could create a custom field type starting from the existing table field. But if sounds complicated, I think it's best to create that form from scratch and not use Backpack for it.

Unfortunately, we don't have backpack documentation in anything other than English.

PS. For non-bugs, please post on Stack Overflow (using the backpack-for-laravel and laravel tags). Keeping Github Issues only for bugs & features will allow us to push fixes and features way faster. Thank you for understanding!

borutjures commented 7 years ago

Keeping Github Issues only for bugs & features

This is a feature and it is an important one for all business facing apps. Like those that would require a commercial license ;-)

Think about business documents like invoices. There is a invoice header (1 record) and invoice lines (many lines for each invoice header). It is custom to show records from these two tables on the same form. Some examples: https://www.google.si/search?q=master+detail+form

OwenMelbz commented 7 years ago

@properius I think you need to remember, backpack is a package to be used to help build an admin, its not a CMS. If you need a CMS, use a CMS.

Its primary package is "Base" which provides a routing/authentication/templating system for you to build your admin panels in.

Its secondary package is "Crud" which is a mini framework that helps you build create/update forms for the native laravel eloquent models.

You do not download laravel, and expect it to have a shopping cart system built already.

You use the framework as a starting point to build upon.

The same is for Backpack, its a starting point to build upon that covers many users requirements.

When you need custom functionality you build it! Thats what developers are for, to develop... otherwise you'd just hire an IT assistant to read through documentation filling out fields (otherwise known as wordpress developers).

People seem to forget that they will have to still build stuff, Backpack is simply another helper item in your toolkit to make your lives easier. If it doesn't have a feature, create it!! Then if you want to give back to the community release it and then support it! I'm nothing todo with Backpack, I just like to help, so I submit PRs for potential features, and try submit bug fixes, because people need help, would be nice if the rest of the development community would stop criticizing and instead provide solutions and help. Makes the world a better place when people offer help rather than just moan.

borutjures commented 7 years ago

Sorry @OwenMelbz. I didn't write it as a critique. I've seen questions about master/detail forms in other issues and was surprised that there was lack of familiarity with them. My post and the link was meant as help to @fabriciolangermt 's explanation.

Master/detail forms are real requirement for business apps. Just like a grid. I didn't mean CMS or WordPress.

I just wanted to give some feedback to @tabacitu how he could sell more licenses. And yes, I paid for a license as a thank you to all who work on this project.

sanchezpablo commented 7 years ago

@fabriciolangermt You could override the edit method in Crud controller and add secondary Crud controllers in order to implement the master-detail, using also a custom view for rendering the detail table.

public function edit($id)
{
        $this->crud->hasAccessOrFail('update');

        $this->data['entry'] = $this->crud->getEntry($id);
        $this->data['crud'] = $this->crud;
        $this->data['fields'] = $this->crud->getUpdateFields($id);
        $this->data['title'] = trans('backpack::crud.edit') . ' ' . $this->crud->entity_name;

        $this->data['id'] = $id;

        $operationsCrud = new ItemOperationCrudController();
        $operationsCrud->setUp();

        // conditions
        $operationsCrud->crud->addClause('where', 'itm_id', $this->data['entry']['attributes']['id']);

        $this->data['operations_crud'] = $operationsCrud->crud;
        if (! $this->data['operations_crud']->ajaxTable()) {
            $this->data['operations_crud_entries'] = $this->data['operations_crud']->getEntries();

        return view('crud::item.edit', $this->data);
}