jhorngacher was awarded Best Answer+1000 XP
5mos ago
jhorngacher wrote a reply+100 XP
5mos ago
jhorngacher wrote a reply+100 XP
5mos ago
I had this solution already implemented, but somehow the property value is still getting changed.
public function exceptionHandlesFormPermission($e, $stopPropagation){
if($e instanceof Exception){
$this->dispatch('notification.add', [
'type' => 'error',
'message' => $e->getMessage(),
]);
$stopPropagation();
}
}
jhorngacher wrote a reply+100 XP
5mos ago
Alright, thanks for the helpful tips on the best practices.
Further the issue still persists since your provided solution also throws an exception. The exception was thrown already before and I even get the error message on the client side. Still my variable gets changed. And I don't know why since Livewire docs also state that throwing an exception in updating is enough ..
jhorngacher started a new conversation+100 XP
5mos ago
I am pretty new to the Livewire ecosystem and trying to figure out the following thing.
So I have a component which uses a Trait to determine if a user can perform the updating method on a specific variable. So far so good, the check is working fine by using the updating{Trait} hook. The method throws an exception as I expect it. So I am going to use another hook exception{Trait}. The exception method gets called, a unique message gets dispatched. Now my issue, how am I able to prevent the property from being updated? When i check the request debug it updates the property inside my component. Here's my current used code
class CustomComponent {
use CheckFormPropertyPermissions;
// shouldnt get updated with the updating hook?
#[HasPermission('someperm')]
public int|null $someId = null;
}
public function updatingCheckFormPropertyPermissions($name): bool{
$nameParts = explode('.', $name);
$permission = $nameParts[0];
$app = config('app.name', env('APP_NAME', ''));
$name = implode('.', [
$app,
$permission
]);
if(array_key_exists($name, $this->propertyPermissionIsAllowed)){
return true;
}
if(!auth()->user()->can($name)){
throw new Exception('Not allowed!');
}
$this->propertyPermissionIsAllowed[$name] = true;
return true;
}
public function exceptionCheckFormPropertyPermissions($e, $stopPropagation){
if($e instanceof Exception){
$this->dispatch('notification.add', [
'type' => 'error',
'message' => $e->getMessage(),
]);
$stopPropagation();
}
}
Maybe someone is able to give me a hint?
Thanks in advance