Show only posts from owner

Laraship QuestionsCategory: TechnicalShow only posts from owner
ATMA asked 3 years ago
I have a custom module (Quiz) where all the records of all users appear in the index module page, but I want to show only the respective records per user who created them (created_by).
1 Answers
laraship Staff answered 3 years ago
Hello You can check MyInvoicesTransformer as an example for your requests, basically, the query function should be changed to add the scope filter you need  
/**
* Get query source of dataTable.
* @param Invoice $model
* @return \Illuminate\Database\Eloquent\Builder|static
*/
public function query(Invoice $model)
{
return $model->myInvoices()->newQuery();
}

and in the model you add


public function scopeMyInvoices($query)
{
return $query->where('user_id', user()->id);
}