php - 如何在 Laravel 5 中返回带有 anchor 的 View ?

标签 php laravel

在我的 Controller 中

return view('pages.index', compact('errors'));

它工作正常,但我不知道如何将 View 返回到 anchor 。

return view('pages.index#contact', compact('errors'));

无效。出现这样的错误。

InvalidArgumentException in FileViewFinder.php line 137:
View [pages.index#contact] not found.

最佳答案

你可以使用一些 JS。首先传递 anchor 变量:

$anchor = 'contact';
return view('pages.index', compact('errors', 'anchor'));

然后使用hidden 或其他方式将数据传递给JS:

@if (isset($anchor))
    <input type="hidden" name="anchor" value="{{ $anchor }}">
@endif

最后用JS移动页面:

$(function () {
    if ( $( "[name='anchor']" ).length ) {
        window.location = '#' + $( "[name='anchor']" ).val();
    }
};

这只是一个给你一个想法的例子。

关于php - 如何在 Laravel 5 中返回带有 anchor 的 View ?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40673397/

相关文章:

laravel - 如何更改 Laravel 5.2 更改登录路径?

php - Laravel 查询生成器通过对常见结果进行分组来进行计数

Laravel - 使模型中的全局变量仅在模型内部使用

php - Laravel 扩展 Blade 模板 - $errors 集合中的错误

php - 使用 html 表单更新 php 上的 sql 表

php - MySQL查询: return rows where field is made of characters from the given php string

php - 一次更新多个等级

运行主管队列时,Php-worker 在内存中不断增长

php - 在 Laravel 中创建一个进程来动态监听、工作或监控队列

php - 拉拉维尔 : Install Microsoft Azure Client Library with composer