check widget permission

This commit is contained in:
Denis Duliçi 2021-01-29 23:56:54 +03:00
parent 42af602477
commit 36d7d6aae4

View File

@ -4,6 +4,7 @@ namespace App\Transformers\Common;
use App\Models\Common\Dashboard as Model;
use League\Fractal\TransformerAbstract;
use App\Utilities\Widgets;
class Dashboard extends TransformerAbstract
{
@ -34,10 +35,14 @@ class Dashboard extends TransformerAbstract
*/
public function includeWidgets(Model $model)
{
if (!$model->widgets) {
if (!$widgets = $model->widgets) {
return $this->null();
}
return $this->collection($model->widgets, new Widget());
$widgets = $widgets->filter(function ($widget) {
return Widgets::canShow($widget->class);
});
return $this->collection($widgets, new Widget());
}
}