Crud: Crud entry id in list view replaced by joined id after addClause

Created on 23 Jan 2018  路  2Comments  路  Source: Laravel-Backpack/CRUD

Hello,
I use this code in the setup() method of my DocumentCrudController:

            if (\Auth::user()->hasRole('CompanyManager')) {
                $this->crud->addClause(
                    'join',
                    'users',
                    function ($query) {
                        $companyId =  \Auth::user()->company->id;
                        $query->on('documents.user_id', '=', 'users.id')
                        ->where('users.company_id', '=', $companyId);
                    }
                );
            }

I just need a company manager being able to view download documents owned by any company user, so I use a button from a view which call $entry->getKey() as parameter for a download route: it works perfectly well If I don't add any join clause.
When the "users" table comes into play via the join clause, the document id just gets replaced by the user id, so that I cannot access the document anymore.
I can I get rid of this behaviour?

Backpack, Laravel, PHP, DB version:

Backpack bae 0.8.6, CRUD 3.3.5, Laravel 5.5.29, PHP 7.1.8, MySQL 5.7.19.

Most helpful comment

Sorry, found solution by myself: appending
$this->crud->addClause('select', 'documents.*');
it solved.

All 2 comments

Sorry, found solution by myself: appending
$this->crud->addClause('select', 'documents.*');
it solved.

Thanks for sharing your solution too, @captainkirkoff . You'll definitely help someone who searches for the same thing. Cheers!

Was this page helpful?
0 / 5 - 0 ratings