doushi1900 2018-06-11 07:41
浏览 165
已采纳

Laravel将参数从Route传递到Controller分解页面

I am trying to pass a route variable to the controller and it breaks down the whole page because if I go to network tab, it's being fetched as a document.

Here is the function in the controller:

public function watch($id)
{
      //Some logic goes here
}

Here is my Route:

Route::get('/watch/{id}', "HomeController@watch");

and the page looks something like:

localhost:8040/mysite/public/watch/1J76wN0TPI4

Here is a screenshot of the page after it loads:

Please check this image

  • 写回答

1条回答 默认 最新

  • dosryjij88555 2018-06-11 07:56
    关注

    The problem is that your assets are being loaded incorrectly.

    Assets meaning JS and CSS files, your base template or your main blade file is probably linking directly to a source url, once you add the new url that becomes obsolete.

    example

    mysite.com/mycss.css
    

    The above being a css file in your main blade, and a lot of people develop this with a absolute url

    when you add the route watch/id the file is then reading like this

    mysite.com/watch/1/mycss.css
    

    That is the error

    In your blade template, reference all assets using the asset helper https://laravel.com/docs/5.6/helpers#method-asset

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?