metarzan
metarzan

Reputation: 121

Laravel 4 Undefined variable errors

Getting *ErrorException' with message 'Undefined variable: textareaBBCode*

I do assign a value in the Controller before the foreach loop

   $textareaBBCode = "";
   $textareaHtmlCode = "";
   foreach($results as $result){

   $textareaBBCode .= $result->bbCode.' ';
   $textareaHtmlCode .= $result->htmlCode.' ';

and use ->with to send it to the view

return View::make('layouts/show')
              ->with('results', $results)
              ->with('textareaBBCode', $textareaBBCode)
              ->with('textareaHtmlCode', $textareaHtmlCode);

Then in the view I have attempted to remedy the error with if(Session)

@extends('layouts.master')

    @section('display')
        @if(Session::has('textareaBBCode'))
        {{Session::get('textareaBBCode')}}
        @endif
        @if(Session::has('textareahtmlCode'))
        {{Session::get('textareahtmlCode')}}
        @endif
<textarea id='textareaBBCode'>{{$textareaBBCode}}</textarea>
<textarea id='textareahtmlCode'>{{$textareaHtmlCode}}</textarea>

But the error persists. I have searched for a few hours now and would really like some help thanks.

Upvotes: 0

Views: 300

Answers (1)

kyle
kyle

Reputation: 2638

You don't need to use sessions to access the variables. You are just able to use $textareaBBCode in the view.

See how the $name variable is accessed in this example from the docs: http://laravel.com/docs/4.2/responses#views

Upvotes: 1

Related Questions