Level 104
You are not passing the id here:
@livewire('property.update')
You have the $property variable available, so...
@livewire('property.update', ['id' => $property->id])
2 likes
I have a View of Property Views that is the Read portion of my CRUD app. I have added a modal to update said Property.
But I'm getting a resolve dependency error on the $id which I presume means it is failing to mount the data and ID from the Properties and therefore is failing.
How do I utilise a modal view inside another view to update its parent?
Here is my code so far...
Update.php
namespace App\Http\Livewire\Property;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\Input;
use App\Models\Properties;
use Livewire\WithFileUploads;
use Livewire\Component;
class Update extends Component
{
use WithFileUploads;
public $address;
public $user_id;
public $city;
public $county;
public $post_code;
public $purchase_price;
Public $purchase_date;
Public $current_value;
Public $paid_cash;
Public $mortgage_balance;
Public $mortgage_initial;
Public $mortgage_term;
Public $interest_rate;
// Image Upload
public $property_image;
public $iteration;
public function mount($id){
$this->property = Properties::find($id);
$this->fill($this->property);
}
public function update(){
$this->validate([
'property_image' => 'image|mimes:png,jpg|max:2048', // 1MB Max
]);
$prop->address = $this->address;
$prop->property_image = $this->property_image->store('property_images','public');// Image Upload
$prop->city = $this->city !== null ? $this->city : '';
$prop->county = $this->county !== null ? $this->county : '';
$prop->post_code = $this->post_code !== null ? $this->post_code : '';
$prop->purchase_price = $this->purchase_price !== null ? $this->purchase_price : 0;
$prop->purchase_date = $this->purchase_date;
$prop->current_value = $this->current_value;
$prop->paid_cash = $this->paid_cash !== null ? $this->paid_cash : 0;
$prop->mortgage_balance = $this->mortgage_balance;
$prop->mortgage_initial = $this->mortgage_initial;
$prop->mortgage_term = $this->mortgage_term;
$prop->interest_rate = $this->interest_rate;
$prop->save();
$this->emit('saved');
}
View,php
namespace App\Http\Livewire\Property;
use Illuminate\Support\Facades\Auth;
use App\Models\Properties;
use Livewire\Component;
use Asantibanez\LivewireCharts\Facades\LivewireCharts;
use Asantibanez\LivewireCharts\Models\PieChartModel;
use Mapper;
class View extends Component
{
public $user_id;
public $property;
public $deleteId;
public function mount($id){
$user_id = Auth::id();
$this->property = Properties::where('user_id', $user_id)->where('id', $id)->first();
}
public function render()
{
return view('livewire.property.view', [
'pieChartModel' =>
(new PieChartModel())
->addSlice('Food', 100, '#f6ad55')
->addSlice('Shopping', 200, '#fc8181')
->addSlice('Travel', 300, '#90cdf4'),
]);
}
View,Blade
<div>
<div class="grid grid-cols-12 gap-4">
<div class="col-span-7">
<img class="border rounded-lg" src="{{ asset('storage/' . $property->property_image) }}" />
</div>
<div class="col-span-5 bg-white border rounded-lg p-4">
<div class="grid grid-cols-4 gap-4">
<div class="col-span-4">
<div class="text-2xl">{{ $property->address }}</div>
<div class="text-sm">{{ $property->city }}, {{ $property->county }} {{ $property->post_code }}</div>
</div>
<div class="col-span-2 align-bottom">
<x-jet-button wire:click="editModal" class="w-full justify-center">
{{ __('Edit') }}
</x-jet-button>
</div>
<div class="col-span-2">
<x-jet-danger-button wire:click="deleteModal" class="w-full">
{{ __('Delete') }}
</x-jet-button>
</div>
<!-- UPDATE MODAL -->
<x-jet-dialog-modal wire:model="showEditModal">
<x-slot name="title">
{{ __('Update Property') }}
</x-slot>
<x-slot name="content">
<div>
@livewire('property.update')
</div>
</x-slot>
<x-slot name="footer">
<x-jet-button >
{{ __('Update Property') }}
</x-jet-button>
<x-jet-secondary-button wire:click="closeModal" wire:loading.attr="disabled">
{{ __('Close') }}
</x-jet-secondary-button>
</x-slot>
</x-jet-dialog-modal>
You are not passing the id here:
@livewire('property.update')
You have the $property variable available, so...
@livewire('property.update', ['id' => $property->id])
Please or to participate in this conversation.