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