Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/253.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 在不更改目录的情况下在Laravel中路由_Php_Laravel_Url Routing - Fatal编程技术网

Php 在不更改目录的情况下在Laravel中路由

Php 在不更改目录的情况下在Laravel中路由,php,laravel,url-routing,Php,Laravel,Url Routing,我的路线定义如下: Route::get('products/{name}', function($name) { return View::make('product')->with('name', $name); }); 问题是,当使用此路由时,当前目录被更改为example.com/products/,这非常可怕,因为这完全破坏了链接(指向images/nameOfImage.png的图像现在指向products/images/nameOfImage.png,它不存在) 如

我的路线定义如下:

Route::get('products/{name}', function($name) {
    return View::make('product')->with('name', $name);
});
问题是,当使用此路由时,当前目录被更改为
example.com/products/
,这非常可怕,因为这完全破坏了链接(指向
images/nameOfImage.png
的图像现在指向
products/images/nameOfImage.png
,它不存在)


如何防止这种情况发生?

事实上,问题出在其他方面(这是因为相对
URL
),请尝试以下方法:

<img src="{{ asset('images/nameOfImage.png') }}" />


与直接使用

相比,如何使用图像链接,使用
资产
?它只是指向公共目录中的图像文件夹的一个直接href。您使用的是刀片吗?@WereWolf TheAlpha YesHmm,这样就可以工作了。问题是,我有很多不同的文件,可能有数百个资源已经直接链接。如果有另一种方法来修复此
,则会容易得多。欢迎使用,但如果可以避免使用base,则最好选择其他
,以便回答(前面的评论中给出了链接)。