v0.5.5 - Added news on the admin panel
This commit is contained in:
parent
ab4275dc33
commit
3e4e6e71ab
|
@ -0,0 +1,116 @@
|
|||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use App\News;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
|
||||
class NewsController extends Controller
|
||||
{
|
||||
public function __construct()
|
||||
{
|
||||
$this->middleware([ "auth" ]);
|
||||
|
||||
$this->middleware([ "check.auth:news.list" ])->only("index");
|
||||
$this->middleware([ "check.auth:news.show" ])->only("show");
|
||||
$this->middleware([ "check.auth:news.create" ])->only("create", "store");
|
||||
$this->middleware([ "check.auth:news.edit" ])->only("edit", "update");
|
||||
$this->middleware([ "check.auth:news.delete" ])->only("delete");
|
||||
}
|
||||
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index(Request $request)
|
||||
{
|
||||
$news = News::query()->paginate($request->input("limit", 20));
|
||||
|
||||
return Response::detect("news.index", [ "news" => $news ]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
return Response::detect("news.create");
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
$data = $request->validate([
|
||||
"name" => "required",
|
||||
"content" => "required"
|
||||
]);
|
||||
|
||||
$news = new News($data);
|
||||
$news->save();
|
||||
|
||||
return redirect()->route("news.index");
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param \App\News $news
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show(News $news)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param \App\News $news
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function edit(News $news)
|
||||
{
|
||||
return Response::detect("news.edit", [ "news" => $news ]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \App\News $news
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
*/
|
||||
public function update(Request $request, News $news)
|
||||
{
|
||||
$data = $request->validate([
|
||||
"name" => "required",
|
||||
"content" => "required"
|
||||
]);
|
||||
|
||||
$news->update($data);
|
||||
|
||||
return redirect()->route("news.index");
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param \App\News $news
|
||||
* @return \Illuminate\Http\RedirectResponse
|
||||
* @throws \Exception
|
||||
*/
|
||||
public function destroy(News $news)
|
||||
{
|
||||
$news->delete();
|
||||
return redirect()->route("news.index");
|
||||
}
|
||||
}
|
|
@ -0,0 +1,12 @@
|
|||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class News extends Model
|
||||
{
|
||||
protected $fillable = [
|
||||
'name', 'content'
|
||||
];
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateNewsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('news', function (Blueprint $table) {
|
||||
$table->id();
|
||||
$table->string("name");
|
||||
$table->text("content");
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('news');
|
||||
}
|
||||
}
|
|
@ -150,6 +150,15 @@ class PermissionSeeder extends Seeder
|
|||
"locations.edit" => "Allows editing of locations",
|
||||
"locations.delete" => "Allows deletion of locations",
|
||||
|
||||
/**
|
||||
* The NEWS specific permissions
|
||||
*/
|
||||
"news.create" => "Create a new location",
|
||||
"news.list" => "Shows all locations",
|
||||
"news.show" => "Shows a specific location",
|
||||
"news.edit" => "Allows editing of locations",
|
||||
"news.delete" => "Allows deletion of locations",
|
||||
|
||||
/**
|
||||
* The ADMIN PANEL specific permissions
|
||||
*/
|
||||
|
|
|
@ -17,6 +17,9 @@
|
|||
<div class="segment">
|
||||
<h3 class="text-white"><a href="{{ route("roles.index") }}" class="text-white"><i class="fa fa-link"></i><span style="margin-left: 4px;">Roller</span></a></h3>
|
||||
</div>
|
||||
<div class="segment">
|
||||
<h3 class="text-white"><a href="{{ route("news.index")}}" class="text-white"><i class="fa fa-link"></i><span style="margin-left: 4px;">Nyheder</span></a></h3>
|
||||
</div>
|
||||
<div class="segment">
|
||||
<h3 class="text-white"><a href="{{ route("menu-plans.index")}}" class="text-white"><i class="fa fa-link"></i><span style="margin-left: 4px;">Menuplan</span></a></h3>
|
||||
</div>
|
||||
|
|
|
@ -0,0 +1,41 @@
|
|||
@extends("admin.layout.base")
|
||||
@extends("admin.layout.header")
|
||||
|
||||
@section("title")
|
||||
Opret Nyheder
|
||||
@endsection
|
||||
|
||||
@section("path")
|
||||
<a href="{{ route('news.create') }}" class="text-white">Opret Nyheder</a> /
|
||||
@endsection
|
||||
|
||||
@section("content")
|
||||
<style>
|
||||
.ck-editor__main {
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
</style>
|
||||
<script src="https://cdn.ckeditor.com/ckeditor5/21.0.0/classic/ckeditor.js"></script>
|
||||
<h1>Opret Nyhed</h1>
|
||||
<form method="post" action="{{ route("news.store") }}">
|
||||
@csrf
|
||||
<label for="title">Titel på nyheden:</label>
|
||||
<input type="text" name="name" id="title" placeholder="OBS: Menuplanen er ændret" required>
|
||||
<textarea name="content" id="editor"></textarea>
|
||||
<input type="submit" class="btn btn-dark text-white" value="Opret">
|
||||
</form>
|
||||
|
||||
|
||||
|
||||
<script>
|
||||
ClassicEditor
|
||||
.create( document.querySelector( '#editor' ) )
|
||||
.then( editor => {
|
||||
console.log( editor );
|
||||
} )
|
||||
.catch( error => {
|
||||
console.error( error );
|
||||
} );
|
||||
</script>
|
||||
|
||||
@endsection
|
|
@ -0,0 +1,13 @@
|
|||
@extends("admin.layout.base")
|
||||
@extends("admin.layout.header")
|
||||
|
||||
@section("title")
|
||||
Vejledning - Fjern
|
||||
@endsection
|
||||
|
||||
@section("path")
|
||||
<a href="{{ route('guides.delete') }}" class="text-white">Fjern Guide</a> /
|
||||
@endsection
|
||||
|
||||
@section("content")
|
||||
@endsection
|
|
@ -0,0 +1,46 @@
|
|||
@extends("admin.layout.base")
|
||||
@extends("admin.layout.header")
|
||||
|
||||
@section("title")
|
||||
Nyhed - Rediger
|
||||
@endsection
|
||||
|
||||
@section("path")
|
||||
<a href="{{route('news.edit', ['news' => $news])}}" class="text-white">Rediger nyhed</a> /
|
||||
@endsection
|
||||
|
||||
@section("content")
|
||||
<style>
|
||||
.ck-editor__main {
|
||||
margin-bottom: 1rem;
|
||||
}
|
||||
</style>
|
||||
<script src="https://cdn.ckeditor.com/ckeditor5/21.0.0/classic/ckeditor.js"></script>
|
||||
<h1>Rediger nyhed:</h1>
|
||||
<form method="post" action="{{route("news.update", ["news" => $news])}}">
|
||||
@csrf
|
||||
@method("PUT")
|
||||
<label for="title">Navn</label>
|
||||
<input value="{{$news->name}}" type="text" name="name" id="title" required>
|
||||
<textarea name="content" id="editor">{{$news->content}}</textarea>
|
||||
<input type="submit" class="btn btn-dark text-white" value="Rediger">
|
||||
</form>
|
||||
|
||||
<script>
|
||||
ClassicEditor
|
||||
.create( document.querySelector( '#editor' ), {
|
||||
toolbar: [ 'heading', '|', 'bold', 'italic', 'link', 'bulletedList', 'numberedList', 'blockQuote' ],
|
||||
heading: {
|
||||
options: [
|
||||
{ model: 'paragraph', title: 'Paragraph', class: 'ck-heading_paragraph' },
|
||||
{ model: 'heading1', view: 'h3', title: 'Heading 1', class: 'sde-blue' },
|
||||
{ model: 'heading2', view: 'h4', title: 'Heading 2', class: 'sde-blue' }
|
||||
]
|
||||
}
|
||||
} )
|
||||
.catch( error => {
|
||||
console.log( error );
|
||||
} );
|
||||
|
||||
</script>
|
||||
@endsection
|
|
@ -0,0 +1,38 @@
|
|||
@extends("admin.layout.base")
|
||||
@extends("admin.layout.header")
|
||||
|
||||
@section("title")
|
||||
Opret Nyhed
|
||||
@endsection
|
||||
|
||||
@section("path")
|
||||
<a href="{{ route('news.index') }}" class="text-white">Opret Nyheder</a> /
|
||||
@endsection
|
||||
|
||||
@section("content")
|
||||
<div class="row align-items-center">
|
||||
<a class="btn btn-inline btn-sde-blue mb-0" href="{{ route('news.create') }}"><img src="{{ asset('/images/icons/plus.svg') }}" alt="Create">Opret Nyheder</a>
|
||||
</div>
|
||||
<table class="tbl mt-2">
|
||||
<tr>
|
||||
<th>Navn</th>
|
||||
<th style="width: 1em;"><img class="w-100" src="{{ asset('/images/icons/pencil.svg') }}" alt="Update"></th>
|
||||
<th style="width: 1em;"><img class="w-100" src="{{ asset('/images/icons/trashcan.svg') }}" alt="Delete"></th>
|
||||
</tr>
|
||||
@foreach($news as $new)
|
||||
<tr>
|
||||
<td>{{$new->name}}</td>
|
||||
<td><a href="{{ route("news.edit", [ "news" => $new ]) }}"><img class="w-100" src="{{ asset('/images/icons/pencil-dark.svg') }}" alt="Update"></a></td>
|
||||
<td><form method="post" action="{{ route("news.destroy", [ "news" => $new ]) }}" class="w-100 nostyle">
|
||||
@csrf
|
||||
@method("delete")
|
||||
|
||||
<button onclick="return confirm('Are you sure you want to delete?');" class="w-100 nostyle" type="submit"><img class="w-100 cursor-pointer" src="{{ asset('/images/icons/trashcan-dark.svg') }}" alt="Delete"></button>
|
||||
</form>
|
||||
</td>
|
||||
</tr>
|
||||
@endforeach
|
||||
</table>
|
||||
|
||||
{{ $news->links() }}
|
||||
@endsection
|
|
@ -0,0 +1,14 @@
|
|||
@extends("admin.layout.base")
|
||||
@extends("admin.layout.header")
|
||||
|
||||
@section("title")
|
||||
Vejledning - Opret
|
||||
@endsection
|
||||
|
||||
@section("path")
|
||||
<a href="{{ route('guides.create') }}" class="text-white">Opret vejledning</a> /
|
||||
@endsection
|
||||
|
||||
@section("content")
|
||||
vejledning blev (ikke) oprettet.
|
||||
@endsection
|
|
@ -0,0 +1,14 @@
|
|||
@extends("admin.layout.base")
|
||||
@extends("admin.layout.header")
|
||||
|
||||
@section("title")
|
||||
Vejledning - Rediger
|
||||
@endsection
|
||||
|
||||
@section("path")
|
||||
<a href="{{ route('guides.edit', ["guide" => $link]) }}" class="text-white">Vejledning</a> /
|
||||
@endsection
|
||||
|
||||
@section("content")
|
||||
Din vejledning blev (ikke) redigeret.
|
||||
@endsection
|
|
@ -55,3 +55,4 @@ Route::resource("resource-categories", "ResourceCategoryController");
|
|||
Route::resource("roles", "RolesController");
|
||||
Route::resource("guides", "GuideController");
|
||||
Route::resource("locations", "LocationController");
|
||||
Route::resource("news", "NewsController");
|
||||
|
|
Loading…
Reference in New Issue