aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--app/Http/Controllers/NewsController.php63
-rw-r--r--app/Http/Controllers/SpecialCallsController.php2
-rw-r--r--resources/views/inc/navbar.blade.php2
-rw-r--r--resources/views/pages/callsigns.blade.php2
-rw-r--r--resources/views/pages/editpost.blade.php52
-rw-r--r--resources/views/pages/index.blade.php2
-rw-r--r--resources/views/pages/news-admin.blade.php73
-rw-r--r--resources/views/pages/news.blade.php7
-rw-r--r--routes/web.php4
9 files changed, 194 insertions, 13 deletions
diff --git a/app/Http/Controllers/NewsController.php b/app/Http/Controllers/NewsController.php
index d44ebd9..306066c 100644
--- a/app/Http/Controllers/NewsController.php
+++ b/app/Http/Controllers/NewsController.php
@@ -5,6 +5,9 @@ namespace App\Http\Controllers;
use Illuminate\Http\Request;
use function dd;
+use Illuminate\Support\Facades\Validator;
+use Illuminate\Support\Facades\Redirect;
+
use App\Models\Post;
class NewsController extends Controller
@@ -32,6 +35,8 @@ class NewsController extends Controller
public function create()
{
//
+ $data = Post::orderBy('created_at', 'desc')->get();
+ return view('pages.news-admin', compact('data'));
}
/**
@@ -42,7 +47,29 @@ class NewsController extends Controller
*/
public function store(Request $request)
{
- //
+ $rules = [
+ 'title' => 'required',
+ 'text' => 'required'
+ ];
+ $messages = [
+ 'sign.required' => 'You need to provide a title!',
+ 'text.required' => 'Your post needs to have some information!'
+ ];
+ $validator = Validator::make($request->all(), $rules, $messages);
+
+ if ($validator->fails()) {
+ return Redirect::back()
+ ->withErrors($validator)
+ ->withInput();
+ }
+
+ $post = new Post();
+ $post->title = $request->title;
+ $post->author = $request->author;
+ $post->text = $request->text;
+ $post->saveOrFail();
+
+ return Redirect::back()->with('status', "New post added.");
}
/**
@@ -64,7 +91,8 @@ class NewsController extends Controller
*/
public function edit($id)
{
- //
+ $data = Post::findOrFail($id);
+ return view('pages.editpost', compact('data'));
}
/**
@@ -76,7 +104,31 @@ class NewsController extends Controller
*/
public function update(Request $request, $id)
{
- //
+ if ($request->input('submit') == 'Edit post') {
+ $rules = [
+ 'title' => 'required',
+ 'text' => 'required'
+ ];
+ $messages = [
+ 'sign.required' => 'You need to provide a title!',
+ 'text.required' => 'Your post needs to have some information!'
+ ];
+ $validator = Validator::make($request->all(), $rules, $messages);
+
+ if ($validator->fails()) {
+ return Redirect::back()
+ ->withErrors($validator)
+ ->withInput();
+ }
+
+ $post = Post::findOrFail($id);
+ $post->title = $request->title;
+ $post->author = $request->author;
+ $post->text = $request->text;
+ $post->saveOrFail();
+
+ return Redirect::route('newsAdd')->with('statusE', "Post edited.");
+ } else return Redirect::route('newsAdd');
}
/**
@@ -87,6 +139,9 @@ class NewsController extends Controller
*/
public function destroy($id)
{
- //
+ $post = Post::findOrFail($id);
+ $title = $post->title;
+ $post->delete();
+ return Redirect::back()->with('statusE', "Post \"$title\" deleted.");
}
}
diff --git a/app/Http/Controllers/SpecialCallsController.php b/app/Http/Controllers/SpecialCallsController.php
index ed29346..b99b7ac 100644
--- a/app/Http/Controllers/SpecialCallsController.php
+++ b/app/Http/Controllers/SpecialCallsController.php
@@ -67,7 +67,7 @@ class SpecialCallsController extends Controller
} else return Redirect::route('addSign');
}
- public function delete(Request $request, int $id)
+ public function destroy(Request $request, int $id)
{
//SpecialCall::findOrFail($id)->delete();
$sign = SpecialCall::findOrFail($id);
diff --git a/resources/views/inc/navbar.blade.php b/resources/views/inc/navbar.blade.php
index 485dc9c..60bda7b 100644
--- a/resources/views/inc/navbar.blade.php
+++ b/resources/views/inc/navbar.blade.php
@@ -20,7 +20,7 @@
Administration
</a>
<div class="dropdown-menu" aria-labelledby="navbarDropdownMenuLink">
- <a class="dropdown-item" href="#">News</a>
+ <a class="dropdown-item" href="{{ route('newsAdd') }}">News</a>
<a class="dropdown-item" href="#">Gallery</a>
</div>
</div>
diff --git a/resources/views/pages/callsigns.blade.php b/resources/views/pages/callsigns.blade.php
index 6c795c4..feed795 100644
--- a/resources/views/pages/callsigns.blade.php
+++ b/resources/views/pages/callsigns.blade.php
@@ -37,7 +37,7 @@
@csrf
<div class="form-group">
<label for="Sign">Special Callsign:</label>
- <input type="text" name="sign" value="" id="Sign" class="form-control">
+ <input type="text" name="sign" value="" id="Sign" class="form-control" required>
@error('sign')
<div class="alert alert-danger mt-2">{{ $message }}</div>
@enderror
diff --git a/resources/views/pages/editpost.blade.php b/resources/views/pages/editpost.blade.php
new file mode 100644
index 0000000..4be1dff
--- /dev/null
+++ b/resources/views/pages/editpost.blade.php
@@ -0,0 +1,52 @@
+@extends('layouts.app')
+
+@section('title', 'Edit post')
+
+@section('navbar', View::make('inc.navbar'))
+
+@section('content')
+ <h3 class="mt-2">Edit Post:</h3>
+ @if (session('status'))
+ <div class="alert alert-success">
+ {{ session('status') }}
+ </div>
+ @endif
+ <form action="{{ route('newsEditForm', request()->route()->parameter('id')) }}" method="POST">
+ @csrf
+ <div class="form-group">
+ <label for="title">Title:</label>
+ <input type="text" name="title" value="{{ old('title') ?? $data->title }}" id="title" class="form-control" required>
+ @error('title')
+ <div class="alert alert-danger mt-2">{{ $message }}</div>
+ @enderror
+ </div>
+
+ <div class="form-group">
+ <label for="author">Author:</label>
+ <input type="text" name="author" value="{{ old('author') ?? $data->author }}" id="author" class="form-control">
+ </div>
+
+ <div class="form-group">
+ <label for="editor">Text:</label>
+ <textarea name="text" id="editor" class="form-control">{{ old('text') ?? $data->text }}</textarea>
+ @error('text')
+ <div class="alert alert-danger mt-2">{{ $message }}</div>
+ @enderror
+ </div>
+
+ <div class="form-group">
+ <input type="submit" name="submit" value="Edit post" class="btn btn-primary">
+ <input type="submit" name="submit" value="Cancel" class="btn btn-secondary">
+ </div>
+ </form>
+@endsection
+
+@section('scripts')
+<script src="https://cdn.ckeditor.com/ckeditor5/23.1.0/classic/ckeditor.js"></script>
+<script>
+ClassicEditor.create(document.querySelector('#editor'))
+ .catch(error => {
+ console.error( error );
+ });
+</script>
+@endsection
diff --git a/resources/views/pages/index.blade.php b/resources/views/pages/index.blade.php
index 22e6a6c..5c16327 100644
--- a/resources/views/pages/index.blade.php
+++ b/resources/views/pages/index.blade.php
@@ -32,7 +32,7 @@ Here one can get information and seek help,
take the advertising materials,
buy authentic souvenirs and prepare local or international projects.
</p><p>
-<strong>School-recreational center “The Sand Pits of Deliblato“– “Čardak”</strong> is situated in the forest part of The Sand Pits,
+<strong>School-recreational center “The Sand Pits of Deliblato“ – “Čardak”</strong> is situated in the forest part of The Sand Pits,
only 7 kilometers away from the village Deliblato.
It is consisted of the management building,
restaurant (for 500 people),
diff --git a/resources/views/pages/news-admin.blade.php b/resources/views/pages/news-admin.blade.php
new file mode 100644
index 0000000..55c94e6
--- /dev/null
+++ b/resources/views/pages/news-admin.blade.php
@@ -0,0 +1,73 @@
+@extends('layouts.app')
+
+@section('title', 'News administration')
+
+@section('navbar', View::make('inc.navbar'))
+
+@section('content')
+ <h3>News Administration:</h3>
+ @if (session('statusE'))
+ <div class="alert alert-success">
+ {{ session('statusE') }}
+ </div>
+ @endif
+ @if (count($data) > 0)
+ <div class="p-0 mt-3 col-lg-6 table-responsive">
+ <table class="table table-bordered">
+ @foreach ($data as $row)
+ <tr>
+ <td class="align-middle">{{ $row->title }}</td>
+ <td><a href="{{ route('newsEdit', $row->id) }}" class="btn btn-warning">Edit</a></td>
+ <td><a href="{{ route('newsDelete', $row->id) }}" class="btn btn-danger">Delete</a></td>
+ </tr>
+ @endforeach
+ </table>
+ </div>
+ @else
+ <strong>There are currently no callsigns.</strong>
+ @endif
+
+ <h3 class="mt-4">Add Post:</h3>
+ @if (session('status'))
+ <div class="alert alert-success">
+ {{ session('status') }}
+ </div>
+ @endif
+ <form action="{{ route('newsAddForm') }}" method="POST">
+ @csrf
+ <div class="form-group">
+ <label for="title">Title:</label>
+ <input type="text" name="title" value="{{ old('title') }}" id="title" class="form-control" required>
+ @error('title')
+ <div class="alert alert-danger mt-2">{{ $message }}</div>
+ @enderror
+ </div>
+
+ <div class="form-group">
+ <label for="author">Author:</label>
+ <input type="text" name="author" value="{{ old('author') }}" id="author" class="form-control">
+ </div>
+
+ <div class="form-group">
+ <label for="editor">Text:</label>
+ <textarea name="text" id="editor" class="form-control">{{ old('text') }}</textarea>
+ @error('text')
+ <div class="alert alert-danger mt-2">{{ $message }}</div>
+ @enderror
+ </div>
+
+ <div class="form-group">
+ <input type="submit" name="submit" value="Add post" class="btn btn-primary">
+ </div>
+ </form>
+@endsection
+
+@section('scripts')
+<script src="https://cdn.ckeditor.com/ckeditor5/23.1.0/classic/ckeditor.js"></script>
+<script>
+ClassicEditor.create(document.querySelector('#editor'))
+ .catch(error => {
+ console.error( error );
+ });
+</script>
+@endsection
diff --git a/resources/views/pages/news.blade.php b/resources/views/pages/news.blade.php
index 44d0202..1e9b83b 100644
--- a/resources/views/pages/news.blade.php
+++ b/resources/views/pages/news.blade.php
@@ -4,10 +4,11 @@
@section('content')
@foreach($news as $post)
- <div class="well">
- <h3>{{ $post->title }}</h3>
+ <div class="well border border-secondary rounded p-2 mb-3">
+ <h2>{{ $post->title }}</h2>
<small>Published at {{ $post->created_at->format('Y-m-d') }}@isset ($post->author) by {{$post->author }}@endisset</small>
- <p>{{ $post->text }}</p>
+ <hr class="bg-secondary">
+ <div>{!! $post->text !!}</div>
</div>
@endforeach
@endsection()
diff --git a/routes/web.php b/routes/web.php
index 4e6b85c..aa5492b 100644
--- a/routes/web.php
+++ b/routes/web.php
@@ -27,7 +27,7 @@ Route::get('/news/add', [NewsController::class, 'create'])->name('newsAdd')->mid
Route::post('/news/add', [NewsController::class, 'store'])->name('newsAddForm')->middleware(['auth']);
Route::get('/news/edit/{id}', [NewsController::class, 'edit'])->name('newsEdit')->middleware(['auth']);
Route::post('/news/edit/{id}', [NewsController::class, 'update'])->name('newsEditForm')->middleware(['auth']);
-Route::get('/news/delete/{id}', [NewsController::class, 'delete'])->name('newsDelete')->middleware(['auth']);
+Route::get('/news/delete/{id}', [NewsController::class, 'destroy'])->name('newsDelete')->middleware(['auth']);
Route::get('/gallery', [PagesController::class, 'gallery'])->name('gallery');
@@ -44,7 +44,7 @@ Route::get('/special-calls/add', [SpecialCallsController::class, 'create'])->nam
Route::post('/special-calls/add', [SpecialCallsController::class, 'store'])->name('addSignForm')->middleware(['auth']);
Route::get('/special-calls/edit/{id}', [SpecialCallsController::class, 'edit'])->name('editSign')->middleware(['auth']);
Route::post('/special-calls/edit/{id}', [SpecialCallsController::class, 'update'])->name('editSignForm')->middleware(['auth']);
-Route::get('/special-calls/delete/{id}', [SpecialCallsController::class, 'delete'])->name('deleteSign')->middleware(['auth']);
+Route::get('/special-calls/delete/{id}', [SpecialCallsController::class, 'destroy'])->name('deleteSign')->middleware(['auth']);
Route::get('/login', [LoginController::class, 'login'])->name('login');