@extends('adminpanel.layouts.app')

@section('title')Все новости @endsection

@section('content')
    <div class="content">
        <div class="col-12">
            <div class="card" style="width: 100%;">
                <div class="card-body">
                    <a class="btn btn-success btn-sm m-2" href="{{route('createNews')}}">Создать новость</a>
                    <div class="table-responsive">
                        <table class="table table-striped table-sm">
                            <thead>
                            <tr>
                                <th>ID</th>
                                <th>Категория</th>
                                <th>Статус</th>
                                <th>Название новости (Рус)</th>
                                <th>Дата публикации</th>
                                <th></th>
                            </tr>
                            </thead>
                            <tbody>
                            @foreach($news as $item)
                                <tr>
                                    <td>{{$item->id}}</td>
                                    <td>{{(isset($item->category->title_ru))?$item->category->title_ru : null }}</td>
                                    <td>{{ ($item->status === 1)? 'Опубликовано': 'Не опубликовано' }}</td>
                                    <td>{{ $item->title_ru }}</td>
                                    <td style="min-width:130px">{{ ($item->date_publication !== null)? $item->date_publication->format('d/m/Y h:m') : null }}</td>
                                    <td style="min-width:200px">
                                        <a class="btn btn-primary btn-sm"
                                           href="{{route('editNews',['news'=>$item->id])}}">Редактировать</a>
                                        <a class="btn btn-danger btn-sm"
                                           href="{{route('deleteNews',['news'=>$item->id])}}">Удалить</a>
                                    </td>
                                </tr>
                            @endforeach
                            </tbody>
                        </table>
                    </div>
                </div>
            </div>
        </div>
    </div>
@endsection
