Skip to content

Commit

Permalink
Fix blade to php generation.
Browse files Browse the repository at this point in the history
  • Loading branch information
vaibhavpandeyvpz committed Jun 21, 2022
1 parent c00dd70 commit 3d70263
Showing 1 changed file with 6 additions and 12 deletions.
18 changes: 6 additions & 12 deletions src/LockingServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -35,18 +35,12 @@ public function register()
*/
public function boot()
{
Blade::directive('lockInput', function (Model $model) {
$valid = in_array(LocksVersion::class, class_uses_recursive($model), true);
if (!$valid) {
throw new \RuntimeException(
sprintf('%s does not use %s trait.', get_class($model), LocksVersion::class)
);
}

/** @var LocksVersion $model */
$fieldName = call_user_func(get_class($model), 'lockVersionColumnName');
$fieldValue = $model->currentLockVersion();
return sprintf('<input type="hidden" name="%s" value="%s">', $fieldName, $fieldValue);
Blade::directive('lockInput', function ($model) {
return sprintf(
'<input type="hidden" name="<?= %s ?>" value="<?= %s ?>">',
"call_user_func([get_class($model), 'lockVersionColumnName'])",
"{$model}->currentLockVersion()"
);
});
}
}

0 comments on commit 3d70263

Please sign in to comment.