Crud: Detail row e custom fields

Created on 4 Feb 2017  路  5Comments  路  Source: Laravel-Backpack/CRUD

Hi,
I can't find in documentation (V3.0) how make detail_row e custom field template.
Maybe the documentation it's not updated because the template path (views/backpack/crud/details_row.blade.php and /resources/views/vendor/backpack/crud/fields) doesn't works.
The showDetailsRow method's works fine but with template i can make a detail more complex
Thx

Most helpful comment

Hi there!

@pushamaku , it's actually a very bad practice to edit vendor files if you use composer (Laravel does). When you run composer update those files will most likely be overwritten, and you'll lose all changes you made.

But Backpack has a good workaround for this: all view files in the package can be easily overwritten, just by having a file with the same name in your project's resources/views/vendor/backpack folder.

So for example, if you want a custom details_row.blade.php, you can overwrite:
vendor/backpack/crud/src/resources/views/details_row.blade.php by creating a file with the same name in your project, in resources/views/vendor/backpack/crud/details_row.blade.php.

@num3r06 , if you want to use a different blade file, you can just create a method in your EntityCrudController like in the example below. Edit anything you want:

/**
     * Used with AJAX in the list view (datatables) to show extra information about that row that didn't fit in the table.
     * It defaults to showing some dummy text.
     *
     * It's enabled by:
     * - setting: $crud->details_row = true;
     * - adding the details route for the entity; ex: Route::get('page/{id}/details', 'PageCrudController@showDetailsRow');
     * - adding a view with the following name to change what the row actually contains: app/resources/views/vendor/backpack/crud/details_row.blade.php
     */
    public function showDetailsRow($id)
    {
        $this->crud->hasAccessOrFail('details_row');

        $this->data['entry'] = $this->crud->getEntry($id);
        $this->data['crud'] = $this->crud;

        // load the view from /resources/views/vendor/backpack/crud/ if it exists, otherwise load the one in the package
        return view('crud::details_row', $this->data);
    }

Hope it helps.

Cheers!

All 5 comments

Just edit details_row_blade.php in vendor/backpack/crud/src/resources/views

But how set detail_row template for each model?
If i want different detail for each model, how i call the specific detail?

Thx

Hi there!

@pushamaku , it's actually a very bad practice to edit vendor files if you use composer (Laravel does). When you run composer update those files will most likely be overwritten, and you'll lose all changes you made.

But Backpack has a good workaround for this: all view files in the package can be easily overwritten, just by having a file with the same name in your project's resources/views/vendor/backpack folder.

So for example, if you want a custom details_row.blade.php, you can overwrite:
vendor/backpack/crud/src/resources/views/details_row.blade.php by creating a file with the same name in your project, in resources/views/vendor/backpack/crud/details_row.blade.php.

@num3r06 , if you want to use a different blade file, you can just create a method in your EntityCrudController like in the example below. Edit anything you want:

/**
     * Used with AJAX in the list view (datatables) to show extra information about that row that didn't fit in the table.
     * It defaults to showing some dummy text.
     *
     * It's enabled by:
     * - setting: $crud->details_row = true;
     * - adding the details route for the entity; ex: Route::get('page/{id}/details', 'PageCrudController@showDetailsRow');
     * - adding a view with the following name to change what the row actually contains: app/resources/views/vendor/backpack/crud/details_row.blade.php
     */
    public function showDetailsRow($id)
    {
        $this->crud->hasAccessOrFail('details_row');

        $this->data['entry'] = $this->crud->getEntry($id);
        $this->data['crud'] = $this->crud;

        // load the view from /resources/views/vendor/backpack/crud/ if it exists, otherwise load the one in the package
        return view('crud::details_row', $this->data);
    }

Hope it helps.

Cheers!

Hi @num3r06

You can also copy the logic from this PR https://github.com/Laravel-Backpack/CRUD/pull/334 or wait for it to get merged :)

Whoa.. Good thing I didn't run update yet :) Thank you!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

M0H3N picture M0H3N  路  3Comments

sokvebolkol picture sokvebolkol  路  3Comments

abewartech picture abewartech  路  3Comments

GenericHero01 picture GenericHero01  路  3Comments

sseggio picture sseggio  路  3Comments