如何在laravel路由中传递字符串

$doc 有一个链接。例如


$doc = /storage/source/logo.jpg

我在下面有这样的看法。


<a class="dropdown-item" href="{{url('admin/download/take')}}/{{$doc}}">{{$doc}}</a>

我在下面有这条路线


Route::get('download/take/{link})','IncomingController@getGo');

这是我的功能


    public function getGo(Request $request, $link){

    print_r($link);


}

该功能不起作用,laravel route 不能接受任何字符串。我如何获取函数内的字符串


猛跑小猪
浏览 117回答 3
3回答

临摹微笑

设置 name() 您的路线的别名。&nbsp;Route::get('download/take/{link})','IncomingController@getGo')->name('download.take.link');更改您的锚链接如下<a class="dropdown-item" href="{{ route('download.take.link', ['link' => base64_encode($doc)])}}">{{$doc}}</a>控制器功能&nbsp;public function getGo(Request $request, $link){&nbsp; &nbsp; &nbsp;$link = base64_decode($link);&nbsp; &nbsp; &nbsp;print_r($link); // here you will have link you have passed with URL.&nbsp;}

Smart猫小萌

尝试将它作为 url 中的 json 字符串传递,然后在控制器中将其解码回 url

MMMHUHU

尝试这个$doc = /storage/source/logo.jpg ;<a class="dropdown-item" href="{{ Storage::url($doc) }}">{{$doc}}</a>如果它不起作用,请配置您的文件系统filesystems.php&nbsp;'public' => [&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'driver' => 'local',&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'root' => storage_path('app/public'),&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'url' => env('APP_URL').'/storage',&nbsp; &nbsp; &nbsp; &nbsp; &nbsp; &nbsp; 'visibility' => 'public',&nbsp; &nbsp; &nbsp; &nbsp; ],这里 'url' => env('APP_URL').'/storage'根据您的需要配置此
打开App,查看更多内容
随时随地看视频慕课网APP