v0.5.10 - Added support for menuplan as news creation

This commit is contained in:
frederikpyt 2020-08-07 10:58:50 +02:00
parent c02c1aacd3
commit b0eda7f8e7
4 changed files with 53 additions and 5 deletions

View File

@ -4,6 +4,7 @@ namespace App\Http\Controllers;
use App\ExternalLink; use App\ExternalLink;
use App\MenuPlan; use App\MenuPlan;
use App\News;
use App\User; use App\User;
use Illuminate\Http\Request; use Illuminate\Http\Request;
use Illuminate\Http\Response; use Illuminate\Http\Response;
@ -64,15 +65,25 @@ class MenuPlanController extends Controller
"thursday" => "required|max:255" "thursday" => "required|max:255"
]); ]);
$menuPlans = new MenuPlan($requestMenuPlanCreate); $menuPlan = new MenuPlan($requestMenuPlanCreate);
$allMenuPlans = MenuPlan::query()->where('week', '=', $request->week)->get(); $allMenuPlans = MenuPlan::query()->where('week', '=', $request->week)->get();
if(count($allMenuPlans) > 0) if(count($allMenuPlans) > 0)
return redirect()->route("menu-plans.index")->with('WeekExists', '<p><b>Der findes allerede en menuplan for den uge!</b></p>'); return redirect()->route("menu-plans.index")->with('WeekExists', '<p><b>Der findes allerede en menuplan for den uge!</b></p>');
else { else {
$menuPlans->save(); $menuPlan->save();
$menuPlans = MenuPlan::query()->paginate($request->input("limit", 20)); $menuPlans = MenuPlan::query()->paginate($request->input("limit", 20));
if($request->newsoption == true){
$news = new News();
$news->name = "Ny menuplan Uge " . $menuPlan->week;
$news->content = "";
$news->save();
}
return redirect()->route("menu-plans.index", ['menuPlans' => $menuPlans]); return redirect()->route("menu-plans.index", ['menuPlans' => $menuPlans]);
} }
} }
@ -123,6 +134,16 @@ class MenuPlanController extends Controller
$menuplan->save(); $menuplan->save();
$menuPlans = MenuPlan::query()->paginate($request->input("limit", 20)); $menuPlans = MenuPlan::query()->paginate($request->input("limit", 20));
if($request->newsoption == true){
$news = new News();
$news->name = "Opdateret menuplan Uge " . $menuplan->week;
$news->content = "";
$news->save();
}
return redirect()->route("menu-plans.index", ['menuPlans' => $menuPlans]); return redirect()->route("menu-plans.index", ['menuPlans' => $menuPlans]);
} }

View File

@ -10,6 +10,14 @@
@endsection @endsection
@section("content") @section("content")
<style>
.toggle__label::before, .toggle__label::after {
border-color: black;
}
.toggle__text::before {
border-color: black;
}
</style>
<script src="https://cdn.ckeditor.com/ckeditor5/21.0.0/classic/ckeditor.js"></script> <script src="https://cdn.ckeditor.com/ckeditor5/21.0.0/classic/ckeditor.js"></script>
<h1>Opret Menuplan:</h1> <h1>Opret Menuplan:</h1>
<form action="{{ action('MenuPlanController@store') }}" method="post"> <form action="{{ action('MenuPlanController@store') }}" method="post">
@ -17,6 +25,12 @@
<label for="week">Uge nr.</label> <label for="week">Uge nr.</label>
<input type="number" name="week" id="week" min="1" max="53" placeholder="1" required> <input type="number" name="week" id="week" min="1" max="53" placeholder="1" required>
<textarea name="menuPlan" id="editor"></textarea> <textarea name="menuPlan" id="editor"></textarea>
<label class="toggle">
<input class="toggle__input" type="checkbox" name="newsoption">
<span class="toggle__label">
<span class="toggle__text">Opret som nyhed</span>
</span>
</label>
<input type="submit" class="btn btn-dark text-white" value="Opret Menuplan"> <input type="submit" class="btn btn-dark text-white" value="Opret Menuplan">
</form> </form>

View File

@ -10,6 +10,14 @@
@endsection @endsection
@section("content") @section("content")
<style>
.toggle__label::before, .toggle__label::after {
border-color: black;
}
.toggle__text::before {
border-color: black;
}
</style>
<h1>Rediger Menuplan:</h1> <h1>Rediger Menuplan:</h1>
<form method="post" action="{{ route("menu-plans.update", [ "menu_plan" => $menuplan ]) }}"> <form method="post" action="{{ route("menu-plans.update", [ "menu_plan" => $menuplan ]) }}">
@csrf @csrf
@ -24,7 +32,12 @@
<input type="text" name="wednesday" id="onsdag" value="{{ $menuplan->wednesday }}" required> <input type="text" name="wednesday" id="onsdag" value="{{ $menuplan->wednesday }}" required>
<label for="torsdag">Torsdag:</label> <label for="torsdag">Torsdag:</label>
<input type="text" name="thursday" id="torsdag" value="{{ $menuplan->thursday }}" required> <input type="text" name="thursday" id="torsdag" value="{{ $menuplan->thursday }}" required>
<label class="toggle">
<input class="toggle__input" type="checkbox" name="newsoption">
<span class="toggle__label">
<span class="toggle__text">Opret som nyhed</span>
</span>
</label>
<input type="submit" class="btn btn-dark text-white" value="Rediger Menuplan"> <input type="submit" class="btn btn-dark text-white" value="Rediger Menuplan">
</form> </form>
@endsection @endsection

View File

@ -59,8 +59,8 @@
<main> <main>
@foreach(\App\News::query()->orderBy("created_at", "desc")->get() as $new) @foreach(\App\News::query()->orderBy("created_at", "desc")->get() as $new)
<div style="border: 4px solid rgba(0,0,0, 0.4); padding: 4px; margin-top: 1rem"> <div style="border: 4px solid rgba(0,0,0, 0.2); border-radius: 4px; padding: 4px; margin-top: 1.5rem">
<h2 class="sde-blue mt-0 text-center">{{ $new->name }}</h2> <h2 class="sde-blue mt-0 mb-0 text-center" style="margin-bottom: 8px; ">{{ $new->name }}</h2>
{!! $new->content !!} {!! $new->content !!}
</div> </div>
@endforeach @endforeach