我知道在 Laravel 的早期版本(例如 4)中,可以通过
Route::current()->uri();
但是,这在 Laravel 5.7 或更高版本中似乎不起作用。我想知道它应该如何重写。
请注意,我在 Blade View 中访问 uri,因此不能使用非静态方法。
最佳答案
您可以使用以下方法在 laravel 中获取当前 url。
// Get the current URL without the query string...
echo url()->current();
// Get the current URL including the query string...
echo url()->full();
// Get the full URL for the previous request...
echo url()->previous();
这些方法中的每一个也可以通过 URL 门面访问:
use Illuminate\Support\Facades\URL;
echo URL::current();
有关更多信息,您可以阅读完整文档 here .
关于laravel - 在 Laravel 5.7 中获取当前 URL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55016717/