Reputation: 25
I embed a php in one of my views with:
<iframe src="{{URL::to('/')}}/game/game.blade.php" width="1519" height="690"></iframe>
In this file I have the following code:
<script>
var userID = {{ auth()->user()->id }};
var userCredit = {{ auth()->user()->id }};
</script>
I get the following error: Uncaught SyntaxError: Unexpected token '{'
I already tried to use {{ Auth::user()->name }}
etc.
I also tried to embed a link that used a route to another view but with this I got a 403 forbidden error.
Does anyone know how I could fix this? or have another solution for me?
Upvotes: 1
Views: 104
Reputation: 145
First, iframe src is never .blade.php file. You can create a route /game and map that route to controller which then returns the .blade.php view. So, in your view:
<iframe src="{{URL::to('/')}}/game" width="1519" height="690"></iframe>
And then in web.php
Route::get('game', 'HomeController@game');
And in HomeController.php:
public function game(){
return view('game');
}
In which file are you writing tag? What's the full error that you are getting? Maybe enclosing your variables inside quotes like this will solve the problem.
<script>
var userID = "{{ auth()->user()->id }}";
var userCredit = "{{ auth()->user()->id }}";
</script>
Upvotes: 1