SHARE
TWEET

Untitled

a guest Jan 12th, 2017 71 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. <section class="new-post">
  2.             <div class="col-md-6 col-md-offset-3">
  3.                 <header><h4>What do you have to say?</h4></header>
  4.                 <form class="ajax" action="{{ route('post.create') }}" method="post">
  5.                     <div class="form-group">
  6.                         <textarea class="form-control" name="body" id="new-post" rows="5" placeholder="Your Post"></textarea>
  7.                     </div>
  8.                     <button type="submit" class="btn btn-primary">Create Post</button>
  9.                     <input type="hidden" value="{{ Session::token() }}" name="_token">
  10.                 </form>
  11.             </div>
  12.         </section>
  13.  
  14.  
  15.         @foreach($posts as $post)
  16.         <section class="posts">
  17.             <div class="col-md-6 col-md-offset-3">
  18.                 <header><span class="twit-h"> <a href="{{ route('user.profile', strtolower($user->username)) }}">{{ $post->user->username }}</a>
  19.                     <img src="/uploads/avatars/{{$post->user->avatar}}" alt="" id="pro2-img">
  20.                     </span></header>
  21.                     <article class="post">
  22.                         <p class="post-bod">
  23.                             {{ $post->body }}
  24.                         </p>
  25.                         <div class="info">
  26.                            made on {{ date('F d, Y', strtotime($post->created_at)) }}
  27.                         </div>
  28.                     </article>
  29.  
  30.             </div>
  31.         </section>
  32.         @endforeach
  33.     </div>
  34. @endsection
  35.    
  36. $(document).ready(function(){
  37.     $('form.ajax').on('submit', function(e){
  38.         e.preventDefault();
  39.  
  40.  
  41.         $.ajax({
  42.             //    Clueless
  43.  
  44.         })
  45.     });
  46. });
  47.    
  48. class PostController extends Controller
  49. {
  50.     //
  51.  
  52.     public function getDashboard()
  53.     {
  54.         $posts = Post::orderBy('created_at', 'desc')->get();
  55.         $cookie = cookie('saw-dashboard', true, 15);
  56.         $users = User::all();
  57.         $user = new User();
  58. //        return view('dashboard', array('user'=> Auth::user()), compact('users'))->withCookie($cookie);
  59.  
  60.         return view('dashboard',array('user'=> Auth::user(), 'posts' => $posts,  compact('users')))->withCookie($cookie);
  61.     }
  62.  
  63.  
  64.     public function postCreatePost(Request $request)
  65.     {
  66.         $this->validate($request,[
  67.             'body' => 'required|max:1000'
  68.  
  69.         ]);
  70.  
  71.         $post = new Post();
  72.         $post->body = $request['body'];
  73.         $message = 'There was an error';
  74.         if($request->user()->posts()->save($post)){
  75.             $message = 'Post Successfully created';
  76.         }
  77.  
  78.         return redirect()->route('dashboard')->with(['message'=> $message]);
  79.     }
  80. }
  81.    
  82. Route::get('/dashboard',[
  83.     'middleware' => 'auth',
  84.     'uses' => 'PostController@getDashboard',
  85.     'as' => 'dashboard'
  86.  
  87. ]);
  88.  
  89.  
  90. Route::post('/createpost',[
  91.  
  92.     'uses'=>'PostController@postCreatePost',
  93.     'as' => 'post.create',
  94.     'middleware' => 'auth'
  95.  
  96. ]);
RAW Paste Data
Pastebin PRO Summer Special!
Get 40% OFF on Pastebin PRO accounts!
Top