Undefined variable (Can not find variable in view)
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty{ height:90px;width:728px;box-sizing:border-box;
}
I am trying to pass a variable from the controller to the view, but it is displaying the following message:
Undefined variable.
Controller
<?php
namespace AppHttpControllers;
use IlluminateHttpRequest;
class QuizController extends Controller
{
public function getUrl($url = null) {
$bandeira = '1';
$bandeira2 = '2';
if ($url == '1') {
return view('quiz')->with($bandeira);
} elseif ($url == '2') {
return view('quiz')->with($bandeira2);
} else {
return view('home');
}
}
}
View
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Copa do Mundo 2018</title>
<link rel="stylesheet" type="text/css" href="css/style.css" />
</head>
<body>
<div id="page-wrap">
<h1>Quiz Copa do Mundo 2018</h1>
<form action="grade.php" method="post" id="quiz">
<ol>
<li>
<h3> ?</h3>
@if($bandeira == '1')
<img src="{{ asset('img/espanha.jpg') }}" alt=""/>
@elseif($bandeira == '2')
<img src="{{ asset('img/argentina.jpg') }}" alt=""/>
@endif
laravel
add a comment |
I am trying to pass a variable from the controller to the view, but it is displaying the following message:
Undefined variable.
Controller
<?php
namespace AppHttpControllers;
use IlluminateHttpRequest;
class QuizController extends Controller
{
public function getUrl($url = null) {
$bandeira = '1';
$bandeira2 = '2';
if ($url == '1') {
return view('quiz')->with($bandeira);
} elseif ($url == '2') {
return view('quiz')->with($bandeira2);
} else {
return view('home');
}
}
}
View
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Copa do Mundo 2018</title>
<link rel="stylesheet" type="text/css" href="css/style.css" />
</head>
<body>
<div id="page-wrap">
<h1>Quiz Copa do Mundo 2018</h1>
<form action="grade.php" method="post" id="quiz">
<ol>
<li>
<h3> ?</h3>
@if($bandeira == '1')
<img src="{{ asset('img/espanha.jpg') }}" alt=""/>
@elseif($bandeira == '2')
<img src="{{ asset('img/argentina.jpg') }}" alt=""/>
@endif
laravel
add a comment |
I am trying to pass a variable from the controller to the view, but it is displaying the following message:
Undefined variable.
Controller
<?php
namespace AppHttpControllers;
use IlluminateHttpRequest;
class QuizController extends Controller
{
public function getUrl($url = null) {
$bandeira = '1';
$bandeira2 = '2';
if ($url == '1') {
return view('quiz')->with($bandeira);
} elseif ($url == '2') {
return view('quiz')->with($bandeira2);
} else {
return view('home');
}
}
}
View
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Copa do Mundo 2018</title>
<link rel="stylesheet" type="text/css" href="css/style.css" />
</head>
<body>
<div id="page-wrap">
<h1>Quiz Copa do Mundo 2018</h1>
<form action="grade.php" method="post" id="quiz">
<ol>
<li>
<h3> ?</h3>
@if($bandeira == '1')
<img src="{{ asset('img/espanha.jpg') }}" alt=""/>
@elseif($bandeira == '2')
<img src="{{ asset('img/argentina.jpg') }}" alt=""/>
@endif
laravel
I am trying to pass a variable from the controller to the view, but it is displaying the following message:
Undefined variable.
Controller
<?php
namespace AppHttpControllers;
use IlluminateHttpRequest;
class QuizController extends Controller
{
public function getUrl($url = null) {
$bandeira = '1';
$bandeira2 = '2';
if ($url == '1') {
return view('quiz')->with($bandeira);
} elseif ($url == '2') {
return view('quiz')->with($bandeira2);
} else {
return view('home');
}
}
}
View
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Copa do Mundo 2018</title>
<link rel="stylesheet" type="text/css" href="css/style.css" />
</head>
<body>
<div id="page-wrap">
<h1>Quiz Copa do Mundo 2018</h1>
<form action="grade.php" method="post" id="quiz">
<ol>
<li>
<h3> ?</h3>
@if($bandeira == '1')
<img src="{{ asset('img/espanha.jpg') }}" alt=""/>
@elseif($bandeira == '2')
<img src="{{ asset('img/argentina.jpg') }}" alt=""/>
@endif
laravel
laravel
edited Jan 26 at 0:02
Kirk Beard
6,791103339
6,791103339
asked Jan 3 at 1:45


L.LovatoL.Lovato
163
163
add a comment |
add a comment |
4 Answers
4
active
oldest
votes
When passing information in this manner, the data should be an array with key / value pairs. Inside your view, you can then access each value using its corresponding key, such as <?php echo $key; ?>
.
Correction of your code:
namespace AppHttpControllers;
use IlluminateHttpRequest;
class QuizController extends Controller
{
public function getUrl($url = null) {
$data_to_view['bandeira'] = url;
if ($url != null) {
return view('quiz')->with($data_to_view);
} else {
return view('home');
}
}
}
In your view:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Copa do Mundo 2018</title>
<link rel="stylesheet" type="text/css" href="css/style.css" />
</head>
<body>
<div id="page-wrap">
<h1>Quiz Copa do Mundo 2018</h1>
<form action="grade.php" method="post" id="quiz">
<ol>
<li>
<h3> ?</h3>
@if($bandeira == '1')
<img src="{{ asset('img/espanha.jpg') }}" alt=""/>
@elseif($bandeira == '2')
<img src="{{ asset('img/argentina.jpg') }}" alt=""/>
@endif
1
Oh yah’ thx my brother
– L.Lovato
Jan 4 at 1:05
It's my pleasure, you can up vote my answer
– Googlian
Jan 4 at 4:29
add a comment |
write your variable like this
$bandeira['bandeira'] = 1;
return view('quiz')->with($bandeira);
add a comment |
I think you should write your getUrl method just like this
return view('home', ['bandeira' => $url]);
and no if statement required
add a comment |
change your view page
<?php
if(isset($bandeira) && $bandeira==1)
{
// your code here....
}
else if(isset($bandeira) && $bandeira==2)
{
// your code here....
}
?>
I think it is helpful for you
add a comment |
Your Answer
StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");
StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});
function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});
}
});
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54015370%2fundefined-variable-can-not-find-variable-in-view%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
4 Answers
4
active
oldest
votes
4 Answers
4
active
oldest
votes
active
oldest
votes
active
oldest
votes
When passing information in this manner, the data should be an array with key / value pairs. Inside your view, you can then access each value using its corresponding key, such as <?php echo $key; ?>
.
Correction of your code:
namespace AppHttpControllers;
use IlluminateHttpRequest;
class QuizController extends Controller
{
public function getUrl($url = null) {
$data_to_view['bandeira'] = url;
if ($url != null) {
return view('quiz')->with($data_to_view);
} else {
return view('home');
}
}
}
In your view:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Copa do Mundo 2018</title>
<link rel="stylesheet" type="text/css" href="css/style.css" />
</head>
<body>
<div id="page-wrap">
<h1>Quiz Copa do Mundo 2018</h1>
<form action="grade.php" method="post" id="quiz">
<ol>
<li>
<h3> ?</h3>
@if($bandeira == '1')
<img src="{{ asset('img/espanha.jpg') }}" alt=""/>
@elseif($bandeira == '2')
<img src="{{ asset('img/argentina.jpg') }}" alt=""/>
@endif
1
Oh yah’ thx my brother
– L.Lovato
Jan 4 at 1:05
It's my pleasure, you can up vote my answer
– Googlian
Jan 4 at 4:29
add a comment |
When passing information in this manner, the data should be an array with key / value pairs. Inside your view, you can then access each value using its corresponding key, such as <?php echo $key; ?>
.
Correction of your code:
namespace AppHttpControllers;
use IlluminateHttpRequest;
class QuizController extends Controller
{
public function getUrl($url = null) {
$data_to_view['bandeira'] = url;
if ($url != null) {
return view('quiz')->with($data_to_view);
} else {
return view('home');
}
}
}
In your view:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Copa do Mundo 2018</title>
<link rel="stylesheet" type="text/css" href="css/style.css" />
</head>
<body>
<div id="page-wrap">
<h1>Quiz Copa do Mundo 2018</h1>
<form action="grade.php" method="post" id="quiz">
<ol>
<li>
<h3> ?</h3>
@if($bandeira == '1')
<img src="{{ asset('img/espanha.jpg') }}" alt=""/>
@elseif($bandeira == '2')
<img src="{{ asset('img/argentina.jpg') }}" alt=""/>
@endif
1
Oh yah’ thx my brother
– L.Lovato
Jan 4 at 1:05
It's my pleasure, you can up vote my answer
– Googlian
Jan 4 at 4:29
add a comment |
When passing information in this manner, the data should be an array with key / value pairs. Inside your view, you can then access each value using its corresponding key, such as <?php echo $key; ?>
.
Correction of your code:
namespace AppHttpControllers;
use IlluminateHttpRequest;
class QuizController extends Controller
{
public function getUrl($url = null) {
$data_to_view['bandeira'] = url;
if ($url != null) {
return view('quiz')->with($data_to_view);
} else {
return view('home');
}
}
}
In your view:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Copa do Mundo 2018</title>
<link rel="stylesheet" type="text/css" href="css/style.css" />
</head>
<body>
<div id="page-wrap">
<h1>Quiz Copa do Mundo 2018</h1>
<form action="grade.php" method="post" id="quiz">
<ol>
<li>
<h3> ?</h3>
@if($bandeira == '1')
<img src="{{ asset('img/espanha.jpg') }}" alt=""/>
@elseif($bandeira == '2')
<img src="{{ asset('img/argentina.jpg') }}" alt=""/>
@endif
When passing information in this manner, the data should be an array with key / value pairs. Inside your view, you can then access each value using its corresponding key, such as <?php echo $key; ?>
.
Correction of your code:
namespace AppHttpControllers;
use IlluminateHttpRequest;
class QuizController extends Controller
{
public function getUrl($url = null) {
$data_to_view['bandeira'] = url;
if ($url != null) {
return view('quiz')->with($data_to_view);
} else {
return view('home');
}
}
}
In your view:
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Copa do Mundo 2018</title>
<link rel="stylesheet" type="text/css" href="css/style.css" />
</head>
<body>
<div id="page-wrap">
<h1>Quiz Copa do Mundo 2018</h1>
<form action="grade.php" method="post" id="quiz">
<ol>
<li>
<h3> ?</h3>
@if($bandeira == '1')
<img src="{{ asset('img/espanha.jpg') }}" alt=""/>
@elseif($bandeira == '2')
<img src="{{ asset('img/argentina.jpg') }}" alt=""/>
@endif
answered Jan 3 at 6:07


GooglianGooglian
1,6001719
1,6001719
1
Oh yah’ thx my brother
– L.Lovato
Jan 4 at 1:05
It's my pleasure, you can up vote my answer
– Googlian
Jan 4 at 4:29
add a comment |
1
Oh yah’ thx my brother
– L.Lovato
Jan 4 at 1:05
It's my pleasure, you can up vote my answer
– Googlian
Jan 4 at 4:29
1
1
Oh yah’ thx my brother
– L.Lovato
Jan 4 at 1:05
Oh yah’ thx my brother
– L.Lovato
Jan 4 at 1:05
It's my pleasure, you can up vote my answer
– Googlian
Jan 4 at 4:29
It's my pleasure, you can up vote my answer
– Googlian
Jan 4 at 4:29
add a comment |
write your variable like this
$bandeira['bandeira'] = 1;
return view('quiz')->with($bandeira);
add a comment |
write your variable like this
$bandeira['bandeira'] = 1;
return view('quiz')->with($bandeira);
add a comment |
write your variable like this
$bandeira['bandeira'] = 1;
return view('quiz')->with($bandeira);
write your variable like this
$bandeira['bandeira'] = 1;
return view('quiz')->with($bandeira);
answered Jan 3 at 1:53
DineshDinesh
4110
4110
add a comment |
add a comment |
I think you should write your getUrl method just like this
return view('home', ['bandeira' => $url]);
and no if statement required
add a comment |
I think you should write your getUrl method just like this
return view('home', ['bandeira' => $url]);
and no if statement required
add a comment |
I think you should write your getUrl method just like this
return view('home', ['bandeira' => $url]);
and no if statement required
I think you should write your getUrl method just like this
return view('home', ['bandeira' => $url]);
and no if statement required
answered Jan 3 at 2:55
Muhajirin IlyasMuhajirin Ilyas
1
1
add a comment |
add a comment |
change your view page
<?php
if(isset($bandeira) && $bandeira==1)
{
// your code here....
}
else if(isset($bandeira) && $bandeira==2)
{
// your code here....
}
?>
I think it is helpful for you
add a comment |
change your view page
<?php
if(isset($bandeira) && $bandeira==1)
{
// your code here....
}
else if(isset($bandeira) && $bandeira==2)
{
// your code here....
}
?>
I think it is helpful for you
add a comment |
change your view page
<?php
if(isset($bandeira) && $bandeira==1)
{
// your code here....
}
else if(isset($bandeira) && $bandeira==2)
{
// your code here....
}
?>
I think it is helpful for you
change your view page
<?php
if(isset($bandeira) && $bandeira==1)
{
// your code here....
}
else if(isset($bandeira) && $bandeira==2)
{
// your code here....
}
?>
I think it is helpful for you
answered Jan 3 at 3:30


Md. Fazlur RahmanMd. Fazlur Rahman
843
843
add a comment |
add a comment |
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f54015370%2fundefined-variable-can-not-find-variable-in-view%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown