title: ErrorException Undefined variable when trying to show data in view
body: <p>So i was trying to display a record from a database with laravel, and i have defined the variable in <code>@foreach</code> statement but when i run it it shows <code>ErrorException Undefined variable</code> , although all variable already inside the foreach statement, am i missing a method function in my controller?</p>
  
  <p>this is the view
  welcome.blade.php</p>
  
  <pre><code>&lt;div class="blog-item"&gt;       
                          &lt;div class="blog-text text-box text-white"&gt;
                              @foreach ($guestbooks as $guestbook)    
                              &lt;div class="top-meta"&gt;{{ Carbon\Carbon::parse($guestbook-&gt;created_at)-&gt;format('d-m-Y')  }} /  di &lt;a href=""&gt;Rakitan&lt;/a&gt;&lt;/div&gt;
                              &lt;h3&gt;{{ $guestbooks-&gt;name }}&lt;/h3&gt;
                              &lt;p&gt;{!! \Illuminate\Support\Str::words($guestbook-&gt;message, 50, '...') !!}&lt;/p&gt;
                              &lt;a href="{{ route('post.read', ['post_id' =&gt; $post-&gt;id]) }}" class="read-more"&gt;Lanjutkan Baca  &lt;img src="asset/img/icons/double-arrow.png" alt="#"/&gt;&lt;/a&gt;
                          &lt;/div&gt;
                      &lt;/div&gt;
                      &lt;!-- Blog item --&gt;
                      &lt;div class="blog-item"&gt;       
                          &lt;div class="blog-text text-box text-white"&gt;   
                              &lt;div class="top-meta"&gt;{{ Carbon\Carbon::parse($guestbook-&gt;created_at)-&gt;format('d-m-Y')  }} /  di &lt;a href=""&gt;Rakitan&lt;/a&gt;&lt;/div&gt;
                              &lt;h3&gt;{{ $guestbook-&gt;name }}&lt;/h3&gt;
                              &lt;p&gt;{!! \Illuminate\Support\Str::words($guestbook-&gt;message, 50, '...') !!}&lt;/p&gt;
                              &lt;a href="{{ route('post.read', ['post_id' =&gt; $post-&gt;id]) }}" class="read-more"&gt;Lanjutkan Baca  &lt;img src="asset/img/icons/double-arrow.png" alt="#"/&gt;&lt;/a&gt;
                          &lt;/div&gt;
                      &lt;/div&gt;
                      &lt;!-- Blog item --&gt;
                      &lt;div class="blog-item"&gt;       
                          &lt;div class="blog-text text-box text-white"&gt;   
                              &lt;div class="top-meta"&gt;{{ Carbon\Carbon::parse($guestbook-&gt;created_at)-&gt;format('d-m-Y')  }} /  di &lt;a href=""&gt;Rakitan&lt;/a&gt;&lt;/div&gt;
                              &lt;h3&gt;{{ $guestbook-&gt;name }}&lt;/h3&gt;
                              &lt;p&gt;{!! \Illuminate\Support\Str::words($guestbook-&gt;message, 50, '...') !!}&lt;/p&gt;
                              &lt;a href="{{ route('post.read', ['post_id' =&gt; $post-&gt;id]) }}" class="read-more"&gt;Lanjutkan Baca  &lt;img src="asset/img/icons/double-arrow.png" alt="#"/&gt;&lt;/a&gt;
                              @endforeach
                          &lt;/div&gt;
                      &lt;/div&gt;
  </code></pre>
  
  <p>this is the controller
  GuestbookController.php</p>
  
  <pre><code>&lt;?php
  
  namespace App\Http\Controllers;
  
  use Illuminate\Http\Request;
  use App\Guestbook;
  
  class GuestbookController extends Controller
  {
      public function index()
      {
          $guestbooks = Guestbook::get();
          return view('post.post_textarea',[
              'guestbooks' =&gt; $guestbooks
          ]);
      }
  
      public function store(Request $request)
      {
          Guestbook::create([
              'name' =&gt; $request-&gt;name,
              'message' =&gt; $request-&gt;message
          ]);
          return redirect()-&gt;back();
      }
  }
  </code></pre>
  
  <p>and this is the routes</p>
  
  <pre><code>Route::get('/posting','GuestbookController@index')-&gt;name('guestbook');
  Route::post('/posting','GuestbookController@store')-&gt;name('guestbook.store');
  </code></pre>