Accessing private/protected variables

Hello

Is there a way to use private/protected variables in livewire?
I just don’t seem to be able to access them in different functions

    public function filterArticlesWithKeyword($searchArticlesString = NULL)
    {

        $articlesSearchService  = new ArticlesSearchService();
        $this->result = $articlesSearchService->getMyArticlesWithKeyword($searchArticlesString);


    }



    public function filterArticlesWithString()
    {

        $articlesSearchService  = new ArticlesSearchService();
        $this->result = $articlesSearchService->getMyArticlesWithString($this->search);

    }

public function render()
    {

return view('livewire.frontend.articles-search-engine', [
            'articles' => $this->results->paginate(10)
            ]);

}


HI!
Try to use public $articlesSearchService in your CLASS
Then you can reach the variable in the class and in the blade component too.
Important is that you use public function mount to assign the value
public function mount($articlesSearchService =null)
{
if ($articlesSearchService) {
$this->articlesSearchService = $articlesSearchService ;
}
}

and / or you should pass as parameter to the blade component
Br.
Gergely

I get a new error
Typed property App\Http\Livewire\Frontend\ArticlesSearchEngine::$articlesSearchService must not be accessed before initialization

private ArticlesSearchService $articlesSearchService;

public function mount($articlesSearchService = NULL)
    {

        if ($articlesSearchService) {
            $this->articlesSearchService = $articlesSearchService;
        }

}

Check this.

https://laravel-livewire.com/docs/2.x/properties#important-notes

Can you specify the exact problem, or provide an error?

Sorry, for now in Livewire there is no way to access private/protected properties
if you want to hide some sensitive data, you can do it by combining it with custom-id, slug, or encrypting then in the backend with a private method you make the data manipulation.

@xtreme2020
Oh from your response, I get the sense the data used in a livewire component is totally visible from the browser. Am I correct?

Yes, every public property or method is visible to the client, also from the browser console anyone can change a property, that why is really important no sensitive data should be set as public properties, also always validate any public properties.
Any additional detail let me know.
if this solves your doubts please mark it as the solution to help others.

Okay. that’s very good to know