How access to emit parameter in mount() method

i need ask_id in mount() method,but it dont work…

public $ask_id;
public $products;
public $votes;
public $users;

protected $listeners = ['askAdd'];

public function askAdd(Ask $ask){

    $this->ask_id=$ask->id;

}

public function mount(){

    $this->products=Product::where('ask_id',$this->ask_id)->get();
    $this->votes=Vote::where('ask_id',$this->ask_id)->get();
    $this->users=User::all();
   
}

Hey, @keivantatari

If you want to pass the parameter to the mount method, you have two options:

First one:

<livewire:name-of-your-component :paramName="paramName"/>

In your component

public function mount($paramName)
{
  //
}

Or if you want to pass the parameter into your blade file (to fetch the votes) do the following:

public $ask_id = null;

public function render()
{
   if (is_null($this->ask_id)) {
      $this->votest = [];
   } else {
        $this->votes=Vote::where('ask_id',$this->ask_id)->get();
    }

    return view('...', ['votes' => $this->votes]));  

   
}
2 Likes

Hi!
I found this afer I’m still working on the HTML editor and try to pass the HTML value into the component’s blade to display it.

Question: like in this sample: :variable="$variable" I can only pass plain text (?) html is not arriving if I’m not mistaken.

I decided to do 2 listeners one is askink the parent componet for the value of the filed and the parnt is sending back the variable value and the child is setting to the default “htmlvalue” variable to render the ckeditor.
As here above i placed to mout the request for the field valie ==> not working.
If I place a button the 2x listener solution seams to work.
Any Idea how I could do it automated?
Thx
Br