Yes, you do not need to use AJAX for this. Laravel has a function called view composer
, where you can do exactly what you need.
I'll give you a brief summary of the two necessary files and leave the link to the documentation, where you can see the correct syntax.
First you have to create within the app/Http
directory, the file that will contain the code that will be displayed in the view. I advise you to create a folder to stay more organized.
$cidades = Cidades::get();
$view->with('cidades', $cidades);
Then you need to create a file within app/Providers
, which will be responsible for calling the previously created file.
view()->composer(
['nome-view-navbar'], 'App\Http\nome-pasta-criada\nome-arquivo-cidades'
);
Here is the link to the documentation: link
As you did not specify the version of your project, I put the link to the last one.