@extends('layouts.master')

@section('content')
    <div class="col-sm-8 blog-main">
        <h1>{{ $post->title }}</h1>
        <p class="blog-post-meta">
            {{ $post->created_at->toFormattedDateString() }}
            by <a href="#">{{ $post->user->name }}</a>
        </p>

        {{ $post->body }}
        @if (count($post->comments))
            <hr />
            <div class="comments">
                <ul class="list-group">
                    @foreach($post->comments as $comment)
                        <li class="list-group-item">
                            <strong>{{ $comment->created_at->diffForHumans() }}</strong>
                            :&nbsp;
                            {{ $comment->body }}
                        </li>
                    @endforeach
                </ul>
            </div>
        @endif

        {{-- Add a comment --}}
        <div class="card">
            <div class="card-block">
                <form method="post" action="/posts/{{ $post->id }}/comments">
                    {{-- Only needed for methods other than GET/POST, since most
                         browsers only support those two --}}
                    {{ method_field('POST') }}
                    {{ csrf_field() }}

                    @include('layouts.errors')
                    <div class="form-group">
                        <textarea required class="form-control" name="body" placeholder="Your comment here">
                        </textarea>
                    </div>

                    <div class="form-group">
                        <button type="submit" class="btn btn-primary">Add comment</button>
                    </div>
                </form>
            </div>
        </div>
    </div>
@endsection