title: laravel 5.4 undefined variable in view
body: <p>I'm kind of new to laravel and trying to pull data from a database but keep hitting an error page saying there's an undefined variable within the view. </p>
  
  <p>I'm supposing there's something I'm doing wrong (or not doing) within the controller. So I have a <strong>create.blade.php</strong> that posts data from a form to the database and everything works fine, however I want it such that after posting to the database to redirect to the <strong>show.blade.php</strong> showing the uploaded data and here is where I hit a brick wall with the error messages. </p>
  
  <p>This is my store function within the controller -</p>
  
  <pre><code>public function store(Request $request)
      {
       $data4page = new Data4page;
  
       $data4page-&gt;h1Ttle = $request-&gt;h1Ttle;
       $data4page-&gt;h4Ttle = $request-&gt;h4Ttle;
       $data4page-&gt;description = $request-&gt;description;
       $data4page-&gt;save();
  
       /*redirecting to the content's show page*/
       return redirect()-&gt;route('content.show', $data4page-&gt;id);
  }
  </code></pre>
  
  <p>And this is the show function within the same controller -</p>
  
  <pre><code>public function show($id)
      {
          //
          $data4page = Data4page::find($id);
          return view('digital.show')-&gt;with(compact('data4page'));
      }
  </code></pre>
  
  <p>The error message I'm getting is -</p>
  
  <pre><code>Undefined variable: data4page (View: /var/www/html/theproject/resources/views/content/show.blade.php)
  </code></pre>
  
  <p>And in the show.blade.php this is a sample of what I have -</p>
  
  <pre><code>&lt;h1&gt;{{ $data4page-&gt;h4Ttle }}&lt;/h1&gt;
  &lt;p&gt;{{ $data4page-&gt;description }}&lt;/p&gt;
  &lt;h4&gt;{{ $data4page-&gt;h4Ttle }}&lt;/h4&gt;
  </code></pre>
  
  <p>Having said all that, I have also tried various means of returning the view within the show function of the controller but all these result in the same error message above. These variants include -</p>
  
  <pre><code>return view('content.show')-&gt;with('data4page', $data4page);
  return view('content.show',['data4page'=&gt;$data4page]);
  </code></pre>
  
  <p><strong>Update: I earlier had typos but now the error I get is -</strong></p>
  
  <pre><code>undefined variable: {"id":9,"h1Ttle":"h1 sample text","h4Ttle":"h4 sample text","description":"body text goes here"} (View: /var/www/html/theproject/resources/views/content/show.blade.‌​‌​php)
  </code></pre>
  
  <p>This is the show.blade.php -</p>
  
  <pre><code>@extends('main')
  @section('title')
  @section('content')
        &lt;div class="app-template"&gt;
           &lt;main class="wrapperMain"&gt;
              &lt;div class=""&gt;
                 &lt;aside class="navSidebar"&gt;
                    &lt;nav class="navProperty"&gt;
                       &lt;h1 class="navProperty-title"&gt;{{ $data4page-&gt;h1Ttle }}&lt;/h1&gt;
                    &lt;/nav&gt;
                    &lt;footer class="footerProperty"&gt;
                       &lt;div class="upcomingSchedule"&gt;
                          &lt;h4 class="upcomingSchedule-heading"&gt;{{ $data4page-&gt;h4Ttle }}&lt;/h4&gt;
                       &lt;/div&gt;
                    &lt;/footer&gt;
                 &lt;/aside&gt;
              &lt;/div&gt;
              &lt;div class="content content--withSidebar"&gt;
                 &lt;div class="lead--Home"&gt;
                    &lt;p&gt;{{ $data4page-&gt;description }}&lt;/p&gt;
                 &lt;/div&gt;
              &lt;/div&gt;
           &lt;/main&gt;
  @endsection
  </code></pre>