Home > Net >  Livewire public function mount() not recieving parametter from route model binding
Livewire public function mount() not recieving parametter from route model binding

Time:05-30

I am running into the following problem, I want to pass from one livewire controller a series of variables to another livewire controller which is in another view. From what I've read the most efficient method would be to pass the parameter through the route (Route Model Binding), and receive it via the mount() method in the livewire controller.

But when receiving the parameter from the livewire controller, I get the following error. (Even though the parameter appears in the route)

Unable to resolve dependency [Parameter #0 [ <required> $prioridad ]] in class App\Http\Livewire\ResultadoConsultaPresupuesto

Controller that redirects to the required route by passing the variable

$this->validate($validationMoto);
return redirect()->route('resultado-presupuesto', ['prioridad' => $this->Prioridad]);

Second controller (receives the parameter)

class ResultadoConsultaPresupuesto extends Component{   
public $Prioridad;

public function mount($prioridad){
   $this->Prioridad = $prioridad;
}

public function render()
{
    return view('livewire.resultado-consulta-presupuesto');
}
}

Route (web.php)

Route::get('/resultado-presupuesto/{prioridad}', [PageController::class, 'showResultadosPresupuesto'])->name('resultado-presupuesto');

I have already made

php artisan route:clear && php artisan route:cache

If instead of receiving the parameter in the mount function I receive it in the following way if it works, but I don't understand why the first one doesn't work

public function mount(){
    $prioridad = \Route::current()->parameter('prioridad');
    $this->Prioridad = $prioridad;  
}

CodePudding user response:

Looking at this you are using standard Laravel controller. So you should pass variable to Livewire component in your view

Something like:

<livewire.resultado-consulta-presupuesto :prioridad="$proridad" />

and before you need to set it it controller

  • Related