protected $categories;
public function mount(Category $categorie )
{
$this->categories= $categorie;
}
in render method $this->categories still has data
public function render()
{
return view('livewire.product.products', [
'categories'=> $this->categories->all(),
]);
}
when I call {{dd($categories)}} in blade view('livewire.product.products') … Data it's still no problem here 💯
but when I call a method from submit Form example :
and inside submit() function I need $this->categories example ::
public function submit()
{
dd($this->categories ); return null
}
$this->categories return null after any action !!!
solution I use is inject Model in function again but i don't like it !!!
public function submit(Category $categorie)
{
dd($categorie->all() ); return data
}
Context
That is how it works, only public properties are accessible between requests. So you have to make $categories public if you want it accessible in your submit method.
See here in the docs https://laravel-livewire.com/docs/2.x/properties#important-notes
protected and private properties DO NOT persist between Livewire updates. In general, you should avoid using them for storing state.
Hope this helps!
👋 Oh Hi! I'm Squishy, the friendly jellyfish that manages Livewire issues.
I see this issue has been closed.
Here in the Livewire repo, we have an "issues can be closed guilt-free and without explanation" policy.
If for ANY reason you think this issue hasn't been resolved, PLEASE feel empowered to re-open it.
Re-opening actually helps us track which issues are a priority.
Reply "REOPEN" to this comment and we'll happily re-open it for you!
(More info on this philosophy here: https://twitter.com/calebporzio/status/1321864801295978497)
Thanks Josh!
Most helpful comment
That is how it works, only public properties are accessible between requests. So you have to make $categories public if you want it accessible in your submit method.
See here in the docs https://laravel-livewire.com/docs/2.x/properties#important-notes
Hope this helps!