title: Passing data from one view to another view using Form in Laravel
body: <p>I have made Post An Ad page in which I succeeded. But I also want to see these Ads in another view ad.blade.php. I am willing to create all posts in post.blade.php and then accessing its data in ad.blade.php. </p>
  
  <p>But when I go to ad.blade.php. It is giving error 
  <strong>ErrorException
  Undefined variable: posts (View: E:\mobile\resources\views\ad\ad.blade.php)</strong></p>
  
  <p><strong>Ad.blade.php</strong></p>
  
  <pre><code>&gt; @extends('layout.main') 
  &gt; 
  &gt; 
  &gt; @section('content')
  &gt; 
  &gt;     &lt;!-- products listing --&gt;
  &gt;     &lt;!-- Latest SHirts --&gt;
  &gt; 
  &gt;     &lt;div class="row"&gt;
  &gt; 
  &gt;     @forelse($posts-&gt;chunk(20) as $chunk)
  &gt; 
  &gt;         @foreach($chunk as $post)
  &gt; 
  &gt;                 &lt;div class="small-3 columns"&gt;
  &gt;                     &lt;div class="item-wrapper"&gt;
  &gt;                         &lt;div class="item2"&gt;
  &gt;                             &lt;div class="img-wrapper"&gt;
  &gt;                                 &lt;a href="{{route('show.post',$post-&gt;id)}}" 
  &gt;                       class="button expanded &gt;                                            add-to-cart"&gt;
  &gt;                                     &lt;span&gt;Add to Cart &lt;/span&gt;
  &gt;                                 &lt;/a&gt;
  &gt; 
  &gt;                             &lt;/div&gt;
  &gt; 
  &gt; 
  &gt;                             &lt;a href="{{route('post', [$post-&gt;id])}}"&gt;
  &gt; 
  &gt;                         &lt;span title = "Click her for details" style="font-size: 80%;"&gt; &lt;h3&gt;
  &gt;                             {{$post-&gt;name}}
  &gt;                         &lt;/h3&gt;&lt;/span&gt;
  &gt;                             &lt;/a&gt;
  &gt;                             &lt;h5&gt;
  &gt;                                 ${{$post-&gt;title}}
  &gt; 
  &gt;                             &lt;/h5&gt;
  &gt;                             &lt;p&gt;
  &gt;                                 {{$post-&gt;price}}
  &gt;                             &lt;/p&gt;
  &gt;                         &lt;/div&gt;
  &gt;                     &lt;/div&gt;
  &gt;                 &lt;/div&gt;
  &gt;                 @endforeach
  &gt;                 @empty
  &gt;                 &lt;h3&gt;No Shirts&lt;/h3&gt;
  &gt; 
  &gt;                 @endforelse
  &gt; 
  &gt; 
  &gt;     &lt;/div&gt;
  &gt; 
  &gt; 
  &gt; 
  &gt;     &lt;br&gt;
  &gt; 
  &gt;     @endsection
  </code></pre>
  
  <p><strong>FrontController.php</strong></p>
  
  <pre><code>&gt;     public function post(){
  &gt; 
  &gt; 
  &gt;         return view('front.post');
  &gt;     }
  &gt; 
  &gt;     public function StorePost(Request $request)
  &gt;     {  
  &gt;         $this-&gt;validate($request, [
  &gt;             'title' =&gt; 'required',
  &gt;             'name' =&gt; 'required',
  &gt;             'email' =&gt; 'required|email',
  &gt;             'contact' =&gt; 'required',
  &gt;             'model' =&gt; 'required',
  &gt;             'city' =&gt; 'required',
  &gt;              'description' =&gt; 'required',   ]);
  &gt; 
  &gt; 
  &gt; 
  &gt;          $destinationPath = 'public/dist/pictures';
  &gt; 
  &gt;         if (Input::hasFile('image'))
  &gt;         {
  &gt;             $file = Input::file('image');
  &gt;             $file-&gt;move('public/dist/pictures', 
                                $file-&gt;getClientOriginalName());
  &gt;         }
  &gt; 
  
  &gt;         Post::create($request-&gt;all());
  &gt; 
  &gt;         return view('ad.ad',compact('name'));
  &gt; 
  &gt; 
  &gt;     }
  &gt; 
  &gt; 
  &gt;     public function ShowPost($id)
  &gt;     {
  &gt;         $post=Post::find($id);
  &gt; 
  &gt;         Post::add($id,$post-&gt;name,$post-&gt;title,$post-&gt;price);
  &gt;         return back();
  &gt;     }
  </code></pre>
  
  <p><strong>web.php</strong></p>
  
  <pre><code>&gt; Route::get('post', 'FrontController@post')-&gt;name('posts');
  &gt; 
  &gt;  Route::get('/post/show-post/{id}', 'FrontController@ShowPost')
  &gt; -&gt;name('show.post'); 
  &gt; 
  &gt; Route::post('post', 'FrontController@StorePost')-&gt;name('post.store');
  </code></pre>
  
  <p><strong>Post.blade.php</strong></p>
  
  <pre><code>&gt; @extends('layout.main')
  &gt; 
  &gt; @section('title','Post An Ad') @section('content')
  &gt; 
  &gt;     &lt;html&gt;
  &gt;     &lt;head&gt;
  &gt;         {{--&lt;title&gt;Post An Ad&lt;/title&gt;--}}
  &gt;         {{--&lt;link rel="stylesheet" href="{{ 
  &gt;             asset('public/css/contactUS.css') }}"&gt;--}}
  &gt;         &lt;link rel="stylesheet" type="text/css" href="{{ 
  &gt;            url('/css/contactUS.css') }}" /&gt;
  &gt; 
  &gt;     &lt;/head&gt;
  &gt;     &lt;body&gt;
  &gt; 
  &gt;     &lt;div class="row2"&gt;
  &gt;         &lt;div class="small-6 small-centered columns"&gt;
  &gt;             &lt;h3 &gt;&lt;b&gt;Post An Ad&lt;/b&gt;&lt;/h3&gt;
  &gt; 
  &gt;             {!! Form::open(['route'=&gt;'post.store','method'=&gt;'post'])!!}
  &gt;             {!! csrf_field() !!}
  &gt; 
  &gt;             &lt;div class="form-group" &gt;
  &gt; 
  &gt;                 &lt;div style="display: inline-block;width: 100px;"&gt;
  &gt;               {{ Form::label('title','Title:')}}&lt;/div&gt;
  &gt;                 &lt;div style="display: inline-block;width: 420px; 
  &gt;                  " class="form-group"&gt;
  &gt;                {{Form::text('title',null,array('class'=&gt;'form-control'))}}
  &gt;                &lt;/div&gt;
  &gt; 
  &gt;             &lt;/div&gt;
  &gt; 
  &gt;             &lt;div class="form-group" &gt;
  &gt; 
  &gt;                 &lt;div style="display: inline-block;width: 100px;"&gt;
  &gt;              {{ Form::label('name','Name:')}}&lt;/div&gt;
  &gt;                  &lt;div style="display: inline-block;width: 420px;" 
  &gt;                   class="form-group"&gt;
  &gt;              {{Form::text('name',null,array('class'=&gt;'form-control'))}}&lt;/div&gt;
  &gt; 
  &gt;             &lt;/div&gt;
  &gt; 
  &gt; 
  &gt;             &lt;div class="form-group"&gt;
  &gt; 
  &gt;                 &lt;div style="display: inline-block;width: 100px;"&gt;
  &gt;               {{ Form::label('email','Email:')}}&lt;/div&gt;
  &gt;                 &lt;div style="display: inline-block;width: 420px;"&gt;
  &gt;             {{ Form::text('email',null,array('class'=&gt;'form-control'))}}&lt;/div&gt;
  &gt; 
  &gt;             &lt;/div&gt;
  &gt; 
  &gt; 
  &gt;             &lt;div class="form-group"&gt;
  &gt; 
  &gt;                 &lt;div style="display: inline-block;width: 100px;"&gt;
  &gt;             {{ Form::label('contact','Contact No:')}}&lt;/div&gt;
  &gt;                 &lt;div style="display: inline-block;width: 420px;"&gt;
  &gt;           {{ Form::text('contact',null,array('class'=&gt;'form-control'))}}&lt;/div&gt;
  &gt; 
  &gt;             &lt;/div&gt;
  &gt; 
  &gt; 
  &gt;             &lt;div class="form-group"&gt;
  &gt; 
  &gt;                 &lt;div style="display: inline-block;width: 100px;"&gt;
  &gt;             {{ Form::label('model','Model:')}}&lt;/div&gt;
  &gt;                 &lt;div style="display: inline-block;width: 420px;"&gt;
  &gt;           {{ Form::text('model',null,array('class'=&gt;'form-control'))}}&lt;/div&gt;
  &gt; 
  &gt;             &lt;/div&gt;
  &gt; 
  &gt; 
  &gt;             &lt;div class="form-group"&gt;
  &gt; 
  &gt;                 &lt;div style="display: inline-block;width: 100px;"&gt;
  &gt;             {{ Form::label('color','Color:')}}&lt;/div&gt;
  &gt;                 &lt;div style="display: inline-block;width: 420px;"&gt;
  &gt;             {{ Form::text('color',null,array('class'=&gt;'form-control'))}}&lt;/div&gt;
  &gt; 
  &gt;             &lt;/div&gt;
  &gt; 
  &gt;             &lt;div class="form-group"&gt;
  &gt; 
  &gt;                 &lt;div style="display: inline-block;width: 100px;"&gt;
  &gt;             {{ Form::label('city','City:')}}&lt;/div&gt;
  &gt;                 &lt;div style="display: inline-block;width: 420px;"&gt;
  &gt;            {{ Form::text('city',null,array('class'=&gt;'form-control'))}}&lt;/div&gt;
  &gt; 
  &gt;             &lt;/div&gt;
  &gt; 
  &gt;             &lt;div class="form-group"&gt;
  &gt; 
  &gt;                 &lt;div style="display: inline-block;width: 100px;"&gt;
  &gt;               {{ Form::label('price','Price:')}}&lt;/div&gt;
  &gt;                 &lt;div style="display: inline-block;width: 420px;"&gt;
  &gt;               {{ Form::text('price',null,array('class'=&gt;'form-control'))}}&lt;/div&gt;
  &gt; 
  &gt;             &lt;/div&gt;
  &gt; 
  &gt;             &lt;div class="form-group"&gt;
  &gt; 
  &gt;                 &lt;div style="display: inline-block;width: 100px;"&gt;{{ Form::label('description','Description:')}}&lt;/div&gt;
  &gt;                 &lt;div style="display: inline-block;width: 420px;"&gt;{{ Form::textarea('description',null,array('class'=&gt;'form-control'))}}&lt;/div&gt;
  &gt; 
  &gt; 
  &gt;                 &lt;div class="form-group" enctype="multipart/form-data"&gt;
  &gt; 
  &gt;                     &lt;div style="display: inline-block;width: 100px;"&gt;{{ Form::label('image','Image:')}}&lt;/div&gt;
  &gt;                     &lt;div style="display: inline-block;width: 420px;"&gt;{{ Form::file('image',null,array('class'=&gt;'form-control'
  &gt; ))}}&lt;/div&gt;
  &gt; 
  &gt;                 &lt;/div&gt;
  &gt; 
  &gt; 
  &gt; 
  &gt;                 &lt;div class="form-group"&gt;
  &gt;                     &lt;button class="btn btn-success"&gt;Post&lt;/button&gt;
  &gt;                 &lt;/div&gt;
  &gt; 
  &gt; 
  &gt;             {!! Form::close() !!}
  &gt; 
  &gt;         &lt;/div&gt;
  &gt; 
  &gt; 
  &gt;         &lt;/div&gt;
  &gt;     &lt;/div&gt;
  &gt; 
  &gt;     &lt;/body&gt;
  &gt;     &lt;/html&gt;
  &gt; 
  &gt; @endsection
  </code></pre>