Filtering owner of particular records in show index

Filtering owner of particular records in show index

Laraship QuestionsCategory: TechnicalFiltering owner of particular records in show index
jedjie asked 4 months ago

Hello,

Filtering owner of particular records during show in index, what in particular class can I filter the User ID owner of a particular records to show before arriving in the Index portion of a controller that is based on your module template, because it shows all of the records that does not belong to the user, for an admin user its ok.

1 Answers
laraship Staff answered 4 months ago

Hello,

This can be done in the DataTable class for that object

for example

/**

* Get query source of dataTable.

* @param Product $model

* @return \Illuminate\Database\Eloquent\Builder|static

*/

public function query(Product $model)

{

if (isSuperUser()) {

return $model->newQuery();

} else {

return user()->[User relation with the objects you need]->newQuery();

}

}

UP TO 60% OFF

LIMITED TIME OFFER
SHOP NOW
Offer Expires Oct 30
close-link