Show only posts from owner

Show only posts from owner

Laraship QuestionsCategory: TechnicalShow only posts from owner
Helinho asked 1 month 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 1 month 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);
}
Helinho
replied 1 month ago

Thanks! It works, but now my Admin and SuperUser can not view all records. I made this:

1) On DataTables/QuestionsDataTable.php

(…)
use Corals\User\Models\User;
use Corals\User\Models\Role;

/**
* Get query source of dataTable.
* @param Question $model
* @return \Illuminate\Database\Eloquent\Builder|static
*/
public function query(Question $model) {
return $model->Questions()->newQuery();
}
(…)

2) On Models/Question.php

(…)
use Corals\User\Models\User;
use Corals\User\Models\Role;

public function scopeQuestions($query) {
return $query->where(‘created_by’, user()->id);
}
(…)

My Admin and SuperUser can not view all records! What can I do?

Helinho
replied 7 days ago

For conditional role I use this inside my Model:

[code]
public function scopeQuestions($query) {
if (user()->hasRole(‘member’)) {
$permission = $query->where(‘created_by’, user()->id);
} else {
$permission = $query;
}
return $permission;
}
[/code]

laraship
Staff replied 6 days ago

Hello,

You need to get an extended license for questions related to the custom development, we have already answered many of your questions, but we cannot get go any further 

Helinho
replied 6 days ago

I’m sorry. Am I not entitled to use this forum to ask questions? As I understand it, I have the right to technical support here about plataform system in this communication channel. If I got it wrong, beforehand, I apologize.

laraship
Staff replied 6 days ago

Hello,

Customization Consultation is not part of standard license support, it clearly mentioned in the license types
of course, you can ask questions about existing features on this forum

Helinho
replied 6 days ago

Ok, I got it. Sorry about that! So, how many cost this Customization Consultation and where I find it?

laraship
Staff replied 6 days ago

You need to have extended or multitenant license to be able to ask customization questions

Helinho
replied 6 days ago

Please, can you at least answer the questions I asked today? This one here has already been resolved, but I have two more that I sent. Can you help me with this, please !?

Happy New Year!

40% DISCOUNT ON OUR ENTIRE STORE
COUPON CODE : Hello2021
GO TO STORE
LIMITED TIME OFFER
close-link
40% Off on all of LARASHIP platforms, plugins, and themes NO EXCLUSIONS
CODE: Hello2021
close-image