1

I have a datatable using yajrabox package with links to various strings. When I click on a link, it takes me to a 404 page with "/teams/"string". How do I make this string a viewable page? I have tried using a slug, but I could be using it incorrectly and honestly I don't know where my error is. Here is the impt. parts of my code:

Route:

Route::get('/teams/display/{$slug}', 'TeamsController@display');

TeamsController:

public function display($slug)
{
    $teamdatas = LoserData::findBySlugOrFail($slug);



    return view('teams/display', compact('teamdatas'));

}

DataTable.blade

      {data: 'homeTeam', name: 'homeTeam', "fnCreatedCell": function (nTd, sData, oData, iRow, iCol) {
        $(nTd).html("<a href=/teams/display/"+oData.homeTeam+">"+oData.homeTeam+"</a>");
        }},

teams/display.blade.php

<div class="container">
<div class="row">
    <div class="col-sm-8">
        <h1> Welcome the {{$teamdatas->slug}} profile page</h1>



    </div>
</div>

Bw70316
  • 37
  • 2
  • 12
  • your route is `teams/display/{slug}` not `teams/{slug}`, thus `teams/string` will throw a 404, it should be `teams/display/string` – Wreigh Mar 01 '18 at 01:02
  • thanks, I referenced the docs and got it to work, but this comment sparked the investigation so thank you. – Bw70316 Mar 01 '18 at 15:05

1 Answers1

0

I guess I should have checked the routing docs because it was definitely a routing issue. To solve it put this in your routes:

Route::get('/teams/display/{teamdatas?}', 'TeamsController@display', function ($teamdatas = 'Oilers-84') {

return $teamdatas;

});

Here is the info from the Laravel Docs 5.5:

Optional Parameters Occasionally you may need to specify a route parameter, but make the presence of that route parameter optional. You may do so by placing a ? mark after the parameter name. Make sure to give the route's corresponding variable a default value:

Route::get('user/{name?}', function ($name = null) {
    return $name;
});

Route::get('user/{name?}', function ($name = 'John') {
    return $name;
});
Bw70316
  • 37
  • 2
  • 12