Yes, no need to use AJAX for that. The Laravel has a function called view composer
, where it is possible to do exactly what you need.
I will give a brief summary of the two files needed and leave the link to the documentation, where you can consult the correct syntax.
First you have to create inside the directory app/Http
, the file that will contain the code that will be displayed in the view. I advise you to create a folder to get more organized.
$cidades = Cidades::get();
$view->with('cidades', $cidades);
Then you need to create a file inside app/Providers
, who will be responsible for calling the file created earlier.
view()->composer(
['nome-view-navbar'], 'App\Http\nome-pasta-criada\nome-arquivo-cidades'
);
Here is the link to the documentation: https://laravel.com/docs/5.6/views#view-Composers
As you did not specify the version of your project, I put the link to the last.
Bro was that. Thank you. I will replace all ajax by it!
– user107563