Skip to content
Discussion options

You must be logged in to vote

To add a "second order" relationship in the setupListOperation() method of your CRUD controller, you can use dot notation to access nested relationships. Here's how you can modify your code to display the spouse's name:

CRUD::column([
    'label' => 'Spouse',
    'name' => 'payer.spouse.name',
    'type' => 'relationship',
    'entity' => 'payer.spouse',
    'attribute' => 'name',
    'model' => 'App\Models\User',
    'searchLogic' => function ($query, $column, $searchTerm) {
        $query->orWhereHas('payer.spouse', function ($q) use ($searchTerm) {
            $q->where('name', 'like', '%'.$searchTerm.'%');
        });
    }
]);

This approach uses the dot notation to access the spouse …

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by prescriptionlifeline
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
1 participant