samedi 30 juin 2018

Using callable params to modify a query

I am using https://github.com/BRACKETS-by-TRIAD/craftable to generate an admin panel for my app.

I have an Organisation model that belongs to an Organisation Type model.

In the index listing, I want to be able to display the Organisation Type name rather than the _id. To do this, I have to modify this query, to eager load the relationship using the 'with' method.

The method signature for the listing is:

public static function processRequestAndGet($request, $columns = array(), $searchIn = null, $modifyQuery = null, $locale = null)

and the index method is:

$data = AdminListing::create(Organisation::class)->processRequestAndGet(
        // pass the request with params
            $request,

            // set columns to query
            ['id', 'organisation_type_id', 'name', 'active'],

            // set columns to searchIn
            ['id', 'name']
        );

        if ($request->ajax()) {
            return ['data' => $data];
        }

        return view('admin.organisation.index', ['data' => $data]);

Can someone help with this, please?



via Chebli Mohamed

Aucun commentaire:

Enregistrer un commentaire