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;
}







1















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









share|improve this question































    1















    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









    share|improve this question



























      1












      1








      1


      0






      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









      share|improve this question
















      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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Jan 26 at 0:02









      Kirk Beard

      6,791103339




      6,791103339










      asked Jan 3 at 1:45









      L.LovatoL.Lovato

      163




      163
























          4 Answers
          4






          active

          oldest

          votes


















          1














          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





          share|improve this answer



















          • 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



















          0














          write your variable like this



             $bandeira['bandeira'] = 1;
          return view('quiz')->with($bandeira);





          share|improve this answer































            0














            I think you should write your getUrl method just like this
            return view('home', ['bandeira' => $url]); and no if statement required






            share|improve this answer































              -1














              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






              share|improve this answer
























                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
                });


                }
                });














                draft saved

                draft discarded


















                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









                1














                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





                share|improve this answer



















                • 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














                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





                share|improve this answer



















                • 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








                1







                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





                share|improve this answer













                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






                share|improve this answer












                share|improve this answer



                share|improve this answer










                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














                • 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













                0














                write your variable like this



                   $bandeira['bandeira'] = 1;
                return view('quiz')->with($bandeira);





                share|improve this answer




























                  0














                  write your variable like this



                     $bandeira['bandeira'] = 1;
                  return view('quiz')->with($bandeira);





                  share|improve this answer


























                    0












                    0








                    0







                    write your variable like this



                       $bandeira['bandeira'] = 1;
                    return view('quiz')->with($bandeira);





                    share|improve this answer













                    write your variable like this



                       $bandeira['bandeira'] = 1;
                    return view('quiz')->with($bandeira);






                    share|improve this answer












                    share|improve this answer



                    share|improve this answer










                    answered Jan 3 at 1:53









                    DineshDinesh

                    4110




                    4110























                        0














                        I think you should write your getUrl method just like this
                        return view('home', ['bandeira' => $url]); and no if statement required






                        share|improve this answer




























                          0














                          I think you should write your getUrl method just like this
                          return view('home', ['bandeira' => $url]); and no if statement required






                          share|improve this answer


























                            0












                            0








                            0







                            I think you should write your getUrl method just like this
                            return view('home', ['bandeira' => $url]); and no if statement required






                            share|improve this answer













                            I think you should write your getUrl method just like this
                            return view('home', ['bandeira' => $url]); and no if statement required







                            share|improve this answer












                            share|improve this answer



                            share|improve this answer










                            answered Jan 3 at 2:55









                            Muhajirin IlyasMuhajirin Ilyas

                            1




                            1























                                -1














                                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






                                share|improve this answer




























                                  -1














                                  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






                                  share|improve this answer


























                                    -1












                                    -1








                                    -1







                                    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






                                    share|improve this answer













                                    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







                                    share|improve this answer












                                    share|improve this answer



                                    share|improve this answer










                                    answered Jan 3 at 3:30









                                    Md. Fazlur RahmanMd. Fazlur Rahman

                                    843




                                    843






























                                        draft saved

                                        draft discarded




















































                                        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.




                                        draft saved


                                        draft discarded














                                        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





















































                                        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







                                        Popular posts from this blog

                                        MongoDB - Not Authorized To Execute Command

                                        How to fix TextFormField cause rebuild widget in Flutter

                                        in spring boot 2.1 many test slices are not allowed anymore due to multiple @BootstrapWith