2020-06-23 09:59:26 +00:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace App\Http\Controllers;
|
|
|
|
|
2020-06-25 10:22:22 +00:00
|
|
|
use App\ExternalLink;
|
2020-06-25 08:34:10 +00:00
|
|
|
use App\MenuPlan;
|
2020-07-30 12:38:32 +00:00
|
|
|
use App\User;
|
2020-06-23 09:59:26 +00:00
|
|
|
use Illuminate\Http\Request;
|
2020-06-25 08:34:10 +00:00
|
|
|
use Illuminate\Http\Response;
|
2020-07-27 14:03:49 +00:00
|
|
|
use Illuminate\Support\Facades\DB;
|
2020-07-30 12:38:32 +00:00
|
|
|
use Spatie\Permission\Models\Permission;
|
|
|
|
use Spatie\Permission\Models\Role;
|
2020-06-25 08:34:10 +00:00
|
|
|
|
2020-06-23 09:59:26 +00:00
|
|
|
|
|
|
|
class MenuPlanController extends Controller
|
|
|
|
{
|
2020-06-30 07:21:21 +00:00
|
|
|
public function __construct()
|
|
|
|
{
|
|
|
|
$this->middleware([ "auth" ]);
|
2020-08-06 13:31:38 +00:00
|
|
|
$this->middleware([ "lang" ]);
|
2020-06-30 07:21:21 +00:00
|
|
|
|
|
|
|
$this->middleware([ "check.auth:menuplan.list" ])->only("index");
|
|
|
|
$this->middleware([ "check.auth:menuplan.show" ])->only("show");
|
|
|
|
$this->middleware([ "check.auth:menuplan.create" ])->only("create", "store");
|
|
|
|
$this->middleware([ "check.auth:menuplan.edit" ])->only("edit", "update");
|
|
|
|
$this->middleware([ "check.auth:menuplan.delete" ])->only("delete");
|
|
|
|
}
|
|
|
|
|
2020-06-23 09:59:26 +00:00
|
|
|
/**
|
|
|
|
* Display a listing of the resource.
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
2020-06-25 08:34:10 +00:00
|
|
|
public function index(Request $request)
|
2020-06-23 09:59:26 +00:00
|
|
|
{
|
2020-06-25 08:34:10 +00:00
|
|
|
$menuPlans = MenuPlan::query()->paginate($request->input("limit", 20));
|
|
|
|
|
2020-06-25 10:37:17 +00:00
|
|
|
return Response::detect("menuplans.index", [ "menuPlans" => $menuPlans]);
|
2020-06-23 09:59:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the form for creating a new resource.
|
|
|
|
*
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
2020-06-25 13:29:43 +00:00
|
|
|
public function create()
|
2020-06-23 09:59:26 +00:00
|
|
|
{
|
2020-06-25 10:37:17 +00:00
|
|
|
return Response::detect("menuplans.create");
|
2020-06-23 09:59:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Store a newly created resource in storage.
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
|
|
|
public function store(Request $request)
|
|
|
|
{
|
2020-06-25 10:22:22 +00:00
|
|
|
$requestMenuPlanCreate = $request->validate([
|
2020-06-30 10:38:02 +00:00
|
|
|
"week" => "required|max:2",
|
2020-06-26 11:11:24 +00:00
|
|
|
"monday" => "required|max:255",
|
|
|
|
"tuesday" => "required|max:255",
|
|
|
|
"wednesday" => "required|max:255",
|
2020-06-30 06:21:36 +00:00
|
|
|
"thursday" => "required|max:255"
|
2020-06-25 10:22:22 +00:00
|
|
|
]);
|
|
|
|
|
2020-06-25 16:43:46 +00:00
|
|
|
$menuPlans = new MenuPlan($requestMenuPlanCreate);
|
2020-06-25 10:22:22 +00:00
|
|
|
|
2020-08-04 08:11:18 +00:00
|
|
|
$allMenuPlans = MenuPlan::query()->where('week', '=', $request->week)->get();
|
|
|
|
|
|
|
|
if(count($allMenuPlans) > 0)
|
|
|
|
return redirect()->route("menu-plans.index")->with('WeekExists', '<p><b>Der findes allerede en menuplan for den uge!</b></p>');
|
|
|
|
else {
|
|
|
|
$menuPlans->save();
|
2020-07-01 07:16:53 +00:00
|
|
|
$menuPlans = MenuPlan::query()->paginate($request->input("limit", 20));
|
2020-08-04 08:11:18 +00:00
|
|
|
return redirect()->route("menu-plans.index", ['menuPlans' => $menuPlans]);
|
2020-07-01 07:16:53 +00:00
|
|
|
}
|
2020-06-23 09:59:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Display the specified resource.
|
|
|
|
*
|
|
|
|
* @param int $id
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
2020-06-26 11:55:04 +00:00
|
|
|
public function show(MenuPlan $id)
|
2020-06-23 09:59:26 +00:00
|
|
|
{
|
2020-06-26 11:55:04 +00:00
|
|
|
return Response::detect("menuplans.show", [ "menuplan" => $id]);
|
2020-06-23 09:59:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Show the form for editing the specified resource.
|
|
|
|
*
|
|
|
|
* @param int $id
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
|
|
|
public function edit($id)
|
|
|
|
{
|
2020-06-29 06:31:36 +00:00
|
|
|
$menuplan = MenuPlan::find($id);
|
|
|
|
return Response::detect("menuplans.edit", ["menuplan" => $menuplan]);
|
2020-06-23 09:59:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Update the specified resource in storage.
|
|
|
|
*
|
|
|
|
* @param \Illuminate\Http\Request $request
|
|
|
|
* @param int $id
|
|
|
|
* @return \Illuminate\Http\Response
|
|
|
|
*/
|
|
|
|
public function update(Request $request, $id)
|
|
|
|
{
|
2020-06-29 06:31:36 +00:00
|
|
|
$data = $request->all();
|
2020-06-29 07:08:49 +00:00
|
|
|
//FORCED UPDATE
|
2020-06-25 10:44:06 +00:00
|
|
|
|
2020-06-29 06:31:36 +00:00
|
|
|
$menuplan = MenuPlan::find($id);
|
2020-07-01 07:43:11 +00:00
|
|
|
|
2020-08-04 08:11:18 +00:00
|
|
|
$allMenuPlans = MenuPlan::query()->where('week', '=', $request->week)->where('id', '!=', $id)->get();
|
|
|
|
|
|
|
|
if(count($allMenuPlans) > 0){
|
|
|
|
return redirect()->route("menu-plans.index")->with('WeekExists', '<p><b>Der findes allerede en menuplan for den uge!</b></p>');
|
2020-07-01 07:43:11 +00:00
|
|
|
}else{
|
2020-08-04 08:11:18 +00:00
|
|
|
$menuplan->update($data);
|
|
|
|
$menuplan->save();
|
|
|
|
|
2020-07-01 07:43:11 +00:00
|
|
|
$menuPlans = MenuPlan::query()->paginate($request->input("limit", 20));
|
2020-08-04 08:11:18 +00:00
|
|
|
return redirect()->route("menu-plans.index", ['menuPlans' => $menuPlans]);
|
2020-07-01 07:43:11 +00:00
|
|
|
}
|
2020-06-25 10:44:06 +00:00
|
|
|
|
2020-06-23 09:59:26 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Remove the specified resource from storage.
|
2020-07-01 08:29:47 +00:00
|
|
|
* Test delete return index function.
|
2020-06-23 09:59:26 +00:00
|
|
|
* @param int $id
|
2020-06-30 08:04:06 +00:00
|
|
|
* @return \Illuminate\Http\RedirectResponse
|
2020-06-23 09:59:26 +00:00
|
|
|
*/
|
|
|
|
public function destroy($id)
|
|
|
|
{
|
2020-06-29 06:31:36 +00:00
|
|
|
$menuplan = MenuPlan::find($id);
|
|
|
|
$menuplan->delete();
|
|
|
|
return redirect()->route("menu-plans.index");
|
2020-06-23 09:59:26 +00:00
|
|
|
}
|
2020-07-27 14:03:49 +00:00
|
|
|
|
|
|
|
|
|
|
|
public function search(Request $request){
|
|
|
|
if($request->ajax()){
|
|
|
|
$output = "<tr>".
|
|
|
|
"<th>Uge</th>".
|
|
|
|
"<th>Mandag</th>".
|
|
|
|
"<th>Tirsdag</th>".
|
|
|
|
"<th>Onsdag</th>".
|
|
|
|
"<th>Torsdag</th>".
|
|
|
|
"<th style=\"width: 1em;\"><img class=\"w-100\" src=\"http://127.0.0.1:8000/images/icons/pencil.svg\" alt=\"Update\"></th>".
|
|
|
|
"<th style=\"width: 1em;\"><img class=\"w-100\" src=\"http://127.0.0.1:8000/images/icons/trashcan.svg\" alt=\"Delete\"></th>".
|
|
|
|
"</tr>";
|
|
|
|
$menuplans = DB::table('menu_plans')->where('week', 'LIKE',$request->search.'%')->get();
|
|
|
|
|
|
|
|
if(count($menuplans) !== 0){
|
|
|
|
foreach ($menuplans as $key => $menuplan){
|
|
|
|
$output.='<tr>'.
|
|
|
|
'<td>' . $menuplan->week . '</td>'.
|
|
|
|
'<td>' . $menuplan->monday . '</td>'.
|
|
|
|
'<td>' . $menuplan->tuesday . '</td>'.
|
|
|
|
'<td>' . $menuplan->wednesday .'</td>'.
|
|
|
|
'<td>' . $menuplan->thursday .'</td>'.
|
|
|
|
'<td><a href="'. route("menu-plans.edit", [ "menu_plan" => $menuplan->id ]) . '"><img class="w-100" src="'. asset('/images/icons/pencil-dark.svg') . '" alt="Update"></a></td>'.
|
|
|
|
'<td><form method="post" action="' .route("menu-plans.destroy", [ "menu_plan" => $menuplan->id ]). '" class="w-100 nostyle">'.
|
|
|
|
csrf_field().
|
|
|
|
method_field("delete").
|
|
|
|
|
|
|
|
'<button class="w-100 nostyle" onclick="return confirm(\'Are you sure you want to delete?\');" type="submit"><img class="w-100 cursor-pointer" src="'. asset('/images/icons/trashcan-dark.svg') . '" alt="Delete"></button>'.
|
|
|
|
'</form>'.
|
|
|
|
'</td>'.
|
|
|
|
'</tr>';
|
|
|
|
}
|
2020-07-28 12:23:54 +00:00
|
|
|
}else{
|
|
|
|
$output.='<tr>'.
|
|
|
|
'<td>Intet match</td>'.
|
|
|
|
'<td></td>'.
|
|
|
|
'<td></td>'.
|
|
|
|
'<td></td>'.
|
|
|
|
'<td></td>'.
|
|
|
|
'<td></td>'.
|
|
|
|
'<td></td>'.
|
|
|
|
'</tr>';
|
2020-07-27 14:03:49 +00:00
|
|
|
}
|
|
|
|
return Response($output);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2020-06-23 09:59:26 +00:00
|
|
|
}
|