issue is that the second select box in never shown. I tried both tutorials talltips.novate.co.uk/livewire/dynamic-cascading-dropdown-with-livewire and this one canbayat.com.tr/post/laravel-dynamic-dependent-dropdown-livewire but none of them showed me the second select box.
$projects always stays NULL. I cannot find my error. Maybe you can help. Here is my code with some debug info.
<?php
namespace App\Http\Livewire;
use Livewire\Component;
use App\Models\Price;
use App\Models\Sponsor;
class Showbookingprice extends Component
{
public $sponsors;
public $projects = [];
public $sponsor;
public $project;
public function mount()
{
$this->refreshData();
}
private function refreshData()
{
$this->sponsors = Sponsor::orderBy('name')->get();
if (!empty($this->sponsor)) {
$this->projects = Price::orderBy('name')->get();
}
}
public function render()
{
$this->refreshData();
return view('livewire.showbookingprice');
}
}
Is this a component inside another or is this a full page component? If it just a regular component, is there then any chance that projects are defined further up?
<?php
namespace App\Http\Controllers\Object;
use Acaronlex\LaravelCalendar\Calendar;
use App\Http\Controllers\Controller;
use Illuminate\Support\Collection;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Log;
use Illuminate\Http\Request;
use App\Models\Asset;
use App\Models\Price;
use App\Models\Booking;
use App\Models\BookingStatus;
use App\Models\Organisation;
use App\Models\User;
use Spatie\MediaLibrary\MediaCollections\Models\Media;
use Gate;
use Illuminate\View\ViewName;
use Symfony\Component\HttpFoundation\Response;
use Yajra\DataTables\Facades\DataTables;
class ObjectController extends Controller
{
[...]
/**
* Show the form for creating a new resource.
*
* @return \Illuminate\Http\Response
*/
public function create(Request $request)
{
$id = $request->id;
$asset = Asset::with('media', 'category', 'step')->findOrFail($id);
$prices = Price::where('asset_id', $id)
//->wherein('orga_category_id', $orga_category_id)
->where('orga_category_id', $orga_category_id)
->firstOrFail();
$users = User::with('orgas')->get();
$orgas = Organisation::with('orgaUsers')->get();
//dd($asset);
return view('object.create', compact('asset', 'users', 'prices', 'orgas'));
}
}
@Snapey thanks for the hint ! I changed sponsor to sponsor_id in the blade, but still null as value. Something wrong with the naming of the select field that it stays at null?