Filtering owner of particular records in show index

Laraship QuestionsCategory: TechnicalFiltering owner of particular records in show index
jedjie asked 5 years 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 5 years 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();

}

}