I try build a React Laravel webpage.
The main.blade.php responsible the layout and that pass data and React components to other blade
I test my app and make few blade.php
So I try comment out several way this line:
/* const data = {{ Illuminate\Support\Js::from($data)}};*/
but not work. It still perceives it as if it were there
I have to pass data for every route for testing because I can't comment the above line
Route::get('/react', function () {
$data = User::find(1);
return view('reactpractice', compact("data"));
})->name('react');
main.blade.php
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="/css/app.css"/>
<title>@yield('title')</title>
<title>{{env('APP_NAME')}}</title>
</head>
<body>
<header>
Motto
</header>
<nav>
<a href="/">Index</a>
<a href="/about">About</a>
<a href="{{route('react')}}">React</a>
<a href="{{route('users')}}">Users</a>
<a href="{{route('login')}}">Login</a>
<a href="{{route('register')}}">Register</a>
</nav>
@yield('contenttop')
@if(Session::has('successmessage'))
<div >
{{Session::get('successmessage')}}
</div>
@endif
@yield('example')
<script>
const data = {{ Illuminate\Support\Js::from($data)}};
const token = '{{@csrf_token()}}'
</script>
<h2> React</h2>
<script src="js/app.js"></script>
</body>
</html>
So how comment script tag content in blade.php?
CodePudding user response:
Rather than comment the line in JavaScript, why not make it conditional?
@if (isset($data))
const data = {{ Illuminate\Support\Js::from($data)}};
@endif
This way, if $data is provided, the JavaScript variable will be created. If $data is missing, it will be ignored and won't break your code.
CodePudding user response:
<!-- Try like this -->
// or /* */
I hope it was helpfull.