Skip to content

Commit

Permalink
Merge pull request #10 from tomatophp/develop
Browse files Browse the repository at this point in the history
fix button permission with method
  • Loading branch information
3x1io authored Feb 7, 2024
2 parents 6cad2c9 + c044024 commit e38587f
Showing 1 changed file with 11 additions and 6 deletions.
17 changes: 11 additions & 6 deletions src/Views/Button.php
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public function __construct(
*/
public function render()
{
return function (array $data) {
$checkPermission = function (array $data) {
if(isset($data['attributes']) && isset($data['attributes']['href'])){
$route = \Route::getRoutes()->match(Request::create($this->attributes->getAttributes()['href']))->getName();
if(class_exists(\Spatie\Permission\Models\Role::class)){
Expand All @@ -41,20 +41,25 @@ public function render()
}

if($permission && auth('web')->user() && auth('web')->user()->can($permission->name)){
return 'tomato-admin::components.button';
return true;
}
else if(!$permission){
return 'tomato-admin::components.button';
return true;
}
else {
return '';
return false;
}
}
else {
return 'tomato-admin::components.button';
return true;
}
};


if($checkPermission){
return view('tomato-admin::components.button');
}
else {
return '';
}
}
}

0 comments on commit e38587f

Please sign in to comment.