Hi!
livewire class Consumers.php
> <?php > namespace App\Http\Livewire; > > [...skipped...] > > class Consumers extends Component { > public $consumers, $consumer_id, $name, $fullname, $ls, $inn, $kpp, $kvartira, $litera, $phone, $space, $type, $active; > public $homes, $home_id; > public $organizations, $organization_id; > public $user_id; > public $isOpen = true; > > public function mount() { > $this->organizations = Organization::all(); > $this->user_id = Auth::id(); > $this->homes = collect(); > $this->home_id = 0; > } > > public function updatedOrganizationId($value) { > $this->homes = DB::table('homes') > ->select('id', 'name') > ->where('organization_id', '=', $this->organization_id) > ->where('active', '=', true) > ->get(); > } > > public function updatedHomeId($value) { > $this->ls = DB::table('homes') > ->select('prefix') > ->where('id', '=', $this->home_id) > ->value('prefix'); > } > > public function render() { > $this->consumers = DB::table('consumers') > [...skipped...] > > return view('livewire.consumers'); > } > }
livewire blade create-consumer.blade.php
<div class="container"> <div class="row justify-content-md-center border bg-light"> <div class="col-7"> <form> @csrf <div class="form-row mb-2"> <div class="col"> <select wire:model="organization_id" class="form-control" name="organization_id"> <option value="0">-- choose organization --</option> @foreach($organizations as $org) <option value="{{ $org->id }}">{{ $org->name }}</option> @endforeach </select> </div> <div class="col"> <select wire:model="home_id" class="form-control" name="home_id"> <option @if ($home_id == 0 ) selected @endif value="0">-- choose building --</option> @foreach($homes as $hm) <option value="{{ $hm->id }}">{{ $hm->name }}</option> @endforeach </select> </div> </div> </form> </div> </div> </div>
after selecting organization and selecting Home get an error
Trying to get property 'id' of non-object (View: C:\laragon\www\bill2\resources\views\livewire\create-consumer.blade.php)
at <option value="{{ $hm->id }}">{{ $hm->name }}</option>
Why?