Search code examples
phplaravelvoyager

Laravel Voyager customize browse.blade.php


New to Laravel/Voyager. I have overridden the Voyager Controller and View as mentioned in the documentation. Need to customize the browse.blade.php to show data from the joined table also. The first part was easy, added

$query->join('table_b', 'table_a.id', '=', 'table_b.table_a_id');

in the overridden VoyagerBaseController controller index(..) method, and can see the altered query by running

$query->toSql();

However, can't find the table_b data in $dataType->browseRows in the browse.blade.php.

It seems that I'm missing a step in this process.

Any ideas?

Thanks.


Solution

  • Actually the table_b data stored in the $dataTypeContent variable. The $dataType variable gets data from the DataType model:

    $slug = $this->getSlug($request);
    $dataType = Voyager::model('DataType')->where('slug', '=', $slug)->first();
    

    So, to solve my problem I'm getting the "dataType" for my table_b also:

    $additionalSlug = 'table_b'; // for example
    $additionalDataType = Voyager::model('DataType')->where('slug', '=', $additionalSlug)->first();
    

    Then merging the two "dataTypes" "browseRows" using the merge() method:

    $dataTypeBrowseRows = $dataType->browseRows->merge($additionalDataType->browseRows);
    

    After that replacing @foreach($dataType->browseRows as $row) with @foreach($dataTypeBrowseRows as $row) in the overridden browse.blade.php file.

    Hope this will help someone.