Search code examples
phplaravelroutesurl-parameters

Variables as Route Parameters (LARAVEL)


I am looking for some help,

I have a bunch of tags that I would like to make dynamic by using variables for the routing:

blade snippet:

<div class="project-card">
   <a href="{{ route('title', ['project' => '1978-reel-boom'], app()->getLocale() ) }}" >
      <img alt="1978 Reel Boom" title="1978 Reel Boom" src="{image}">
      <p>1978 Reel Boom</p>
   </a>
</div>
<div class="project-card">
   <a href="{{ route('title', ['project' => '1979-cubus-diebach'], app()->getLocale() ) }}" >
      <img alt="1979 Cubus Diebach" title="1979 Cubus Diebach" src="{image}">
      <p>1979 Cubus Diebach</p>
   </a>
</div>

My route looks like this:

Route::get('architectuur/{project}', ['as' => 'title', 'uses' => 'App\Http\Controllers\ArchitectureController@showProject'])->name('title');

but I am getting this error:

laravel error message (img)

the idea would be that I could make a single blade page that will respond to the title and display a carousel with images from that project according to the title. (no databases)


Solution

  • You need to just define the name of your route, there is no need to add as.

    Route::get('architectuur/{project}',  'App\Http\Controllers\ArchitectureController@showProject')
        ->name('title');