<?php
namespace Livewire\ComponentConcerns;
use Livewire\Livewire;
use Livewire\ImplicitlyBoundMethod;
use Illuminate\Database\Eloquent\Model;
use Livewire\Exceptions\MethodNotFoundException;
use Livewire\Exceptions\NonPublicComponentMethodCall;
use Livewire\Exceptions\PublicPropertyNotFoundException;
use Livewire\Exceptions\MissingFileUploadsTraitException;
use Illuminate\Database\Eloquent\Collection as EloquentCollection;
use Livewire\HydrationMiddleware\HashDataPropertiesForDirtyDetection;
use Livewire\Exceptions\CannotBindToModelDataWithoutValidationRuleException;
use function Livewire\str;
trait HandlesActions
{
public function syncInput($name, $value, $rehash = true)
{
$propertyName = $this->beforeFirstDot($name);
throw_if(
isset($this->{$propertyName}) && ($this->{$propertyName} instanceof Model || $this->{$propertyName} instanceof EloquentCollection) && $this->missingRuleFor($name),
new CannotBindToModelDataWithoutValidationRuleException($name, $this::getName())
);
$this->callBeforeAndAfterSyncHooks($name, $value, function ($name, $value) use ($propertyName, $rehash) {
throw_unless(
$this->propertyIsPublicAndNotDefinedOnBaseClass($propertyName),
new PublicPropertyNotFoundException($propertyName, $this::getName())
);
if ($this->containsDots($name)) {
$keyName = $this->afterFirstDot($name);
$targetKey = $this->beforeFirstDot($keyName);
$results = [];
$results[$targetKey] = data_get($this->{$propertyName}, $targetKey, []);
data_set($results, $keyName, $value);