title: Laravel pass optional variable to view
body: <p>I have a variable that may or may not be populated in my controller.</p>
  
  <p>For example.</p>
  
  <pre><code>public function controllerMethod() {
     if($condition) {
       $var = "value";
     }
  
     return view("viewname",[
      "var" =&gt; $var
      ]
  }
  </code></pre>
  
  <p>This gives an undefined variable error.</p>
  
  <p>How do I pass this only if it exists?</p>
  
  <p>I know that I could do another if statement, but is there a cleaner way?</p>