Code Shortcut for route function with multiple parameters

Posted 4 months ago by RaymondE

Hi guys,

i have a piece of code that i use in multiple parts of my app. I believe there is a way more elegant way to display my code.

So i have this route:

Route::get('/{country}/{city}/{post}', [PostController::class, 'show'])->name('show');

My Post.php Model is connected to Country.php, as well as City.php

My application also uses dynamic language subdomains e.g. & The Language.php Model is shared with every view, so i can get access to the Model via $language.

While building my templates in Blade i always have a really long functions to access the correct link.

{{ route('', [ $post->country()->where('language_id', $language->id)->first(), $post->city()->where('language_id', $language->id)->first(),  $post]) }}

Using scopes i could shorten the code a bit, but can i set up a scope that can access to the current $language variable?

Or is there another way i can simplify my code?

Thanks :)


Please sign in or create an account to participate in this conversation.

Reply to

Use Markdown with GitHub-flavored code blocks.