Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/250.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/7/sqlite/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 将auth::user作为数据变量传递给路由_Php_Laravel_Url_Routes - Fatal编程技术网

Php 将auth::user作为数据变量传递给路由

Php 将auth::user作为数据变量传递给路由,php,laravel,url,routes,Php,Laravel,Url,Routes,我希望当用户单击配置文件页面时,我希望将Auth::user()->username作为参数传递给我的userController的show方法。我有如下配置文件链接: <li><a href="{{URL::to('/profile')}}">Profile</a></li> 我的问题是如何将我的'/profile/{username}'中的用户名设置为Auth::user()->用户名当我单击配置文件链接时?当前配置文件链接没有附加任何参数一

我希望当用户单击配置文件页面时,我希望将
Auth::user()->username
作为参数传递给我的userController的show方法。我有如下配置文件链接:

<li><a href="{{URL::to('/profile')}}">Profile</a></li>

我的问题是如何将我的
'/profile/{username}'
中的
用户名设置为
Auth::user()->用户名
当我单击配置文件链接时?当前配置文件链接没有附加任何参数

一个快速的方法是从/profile设置重定向,如果他们想查看其他人的配置文件,它不会中断该功能

Route::get('/profile',function(){
    return Redirect::to('/profile/'.Auth::user()->username);
}

但是,我建议在重定向之前执行Auth::check()。

一个快速的方法是从/profile设置重定向,如果他们想查看其他人的配置文件,它不会破坏功能

Route::get('/profile',function(){
    return Redirect::to('/profile/'.Auth::user()->username);
}
但是,我建议在重定向之前执行Auth::check()
{{URL::to('/profile')}
没有指向
Route::get('/profile/{username})
URL,有两种不同的路由

所以你需要做的是改变链接,即

{{URL::to('/profile/' . \Auth::user()->username)}}
然后在路由文件中

Route::get('/profile/{username}',function($username){
    return View::make('user.show')->with(['username' => $username]);
});
//请注意,您需要使用()方法传入数组 或者你可以这样做

Route::get('/profile/{username}',function($username){
    return View::make('user.show',compact('username'));
});
首先
{{URL::to('/profile')}
没有指向
Route::get('/profile/{username})
URL,有两种不同的路由

所以你需要做的是改变链接,即

{{URL::to('/profile/' . \Auth::user()->username)}}
然后在路由文件中

Route::get('/profile/{username}',function($username){
    return View::make('user.show')->with(['username' => $username]);
});
//请注意,您需要使用()方法传入数组 或者你可以这样做

Route::get('/profile/{username}',function($username){
    return View::make('user.show',compact('username'));
});

当用户单击配置文件链接时:

<li>
  <a href="{!! route('user.show', Auth::user()->username) !!}">My Profile</a>
</li>

当用户单击配置文件链接时:

<li>
  <a href="{!! route('user.show', Auth::user()->username) !!}">My Profile</a>
</li>

我做了如下的事情

<li><a href="{{URL::to('/profile')}}">Profile</a></li>

我做了如下的事情

<li><a href="{{URL::to('/profile')}}">Profile</a></li>

我没有名为profile的页面。我必须将其发送给user.show页面我不确定您的意思。我的代码只会重定向用户,并最终使用您在问题中使用的配置文件/用户名路径。我没有名为“配置文件”的页面。我必须将其发送到user.show页面我不确定您的意思。我的代码只会重定向用户,并最终使用您在问题中的配置文件/用户名路径。
Route::get('/profile',function(){
        return redirect()->route('user.show',[Auth::user()->username]);

    });