【问题标题】:Laravel 5.8 routing issueLaravel 5.8 路由问题
【发布时间】:2019-09-11 23:34:06
【问题描述】:

我刚刚安装了 Laravel 5.8,但遇到了一个路由问题,我无法提供 URL 并命名为我想要的任何名称。

Route::get('profile/my-profile', [
    'uses' => 'ProfileController@profile',
    'as' => 'profile'
]);

我尝试了上面的方法,结果是当我这样写时,它并没有在浏览器中显示我的头像。它只显示我的名字,但当我像下面这样写时,没关系。

Route::get('profile', [
    'uses' => 'ProfileController@profile',
    'as' => 'profile'
]);

【问题讨论】:

  • 那么,到底是什么问题呢? “我无法提供任何我想要的网址名称”“不在浏览器中显示我的头像”?
  • 我还希望我的头像旁边有我的名字,我使用{{ Auth::user()->profile_picture }} 实际上在基本路径之后我可以使用像“profile”这样的词,如果我使用“profile/something”,它不会显示我的头像,我该如何解决这个问题? @Tarasovych
  • @Tarasovych 感谢兄弟的评论我解决了这个问题,通过使用{{ asset(Auth::user()->profile_picture) }} 现在我可以给 url name 任何我想要的,如果我们不使用 asset() 那么我们必须写一个 url像这样Route::get('profile', [ 'uses' => 'ProfileController@profile', 'as' => 'profile' ]);,如果我们使用asset(),那么我们可以使用任何我们想要的url名称,比如Route::get('profile/blah/blah', [ 'uses' => 'ProfileController@profile', 'as' => 'profile' ]);快乐编码..

标签: laravel laravel-routing laravel-5.8


【解决方案1】:

我使用这种类型的路由,很好,没有错误

http://yoursite.com/profile/myprofile

Route::group(['prefix' => 'profile'], function (){
     Route::get('/myprofile', [
        'uses' => 'ProfileController@profile',
        'as' => 'pages.profile'
     ]);
});

or:

http://yoursite.com/myprofile

Route::get('/myprofile', [
   'uses' => 'ProfileController@profile',
   'as' => 'pages.profile'
]);

{{ route('pages.profile') }}

对于您要附加的图像或任何文件,请使用以下代码:

{{ URL::to('your file path') }}

【讨论】:

    【解决方案2】:

    这一切都很好......

    {{ asset(Auth::user()->profile_picture) }}
    

    【讨论】:

      猜你喜欢
      • 2019-11-26
      • 2019-11-10
      • 2020-01-11
      • 2014-08-14
      • 2018-11-20
      • 1970-01-01
      相关资源
      最近更新 更多