【发布时间】:2021-05-13 04:56:54
【问题描述】:
我正在使用 laravel6 和 laracasts https://github.com/laracasts/PHP-Vars-To-Js-Transformer。
我的控制器看起来像这样。
public function index()
{
$posts = Post::where('user_id', '<>', \Auth::id())->orderBy('created_at', 'desc')->paginate(3);
\JavaScript::put([
'foo' => 'bar',
]);
return view('posts/index', ['posts' => $posts]);
}
这是我的index.blade.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>{{ config('app.name')}}</title>
<link rel="stylesheet" href="{{ asset('/css/main.css') }}">
</head>
<body>
<header>
<div class="container">
<a class="brand" href="/">{{ config('app.name') }}</a>
@include('commons/nav')
</div>
</header>
<main>
<script>
console.log(foo);
</script>
<div class="container2">
@yield('content')
</div>
</main>
</body>
</html>
当我运行时,我在浏览器控制台上得到了Uncaught ReferenceError: foo is not defined。
我想我确实将示例代码复制并粘贴到https://github.com/laracasts/PHP-Vars-To-Js-Transformer
谁能告诉我怎么了?谢谢。
【问题讨论】:
标签: javascript php html laravel-6