v1.2.1 - Fixed Category for guides
This commit is contained in:
parent
cab8ad604c
commit
580c38e940
skolehjem
app/Http/Controllers
resources/views/admin
|
@ -3,6 +3,7 @@
|
|||
namespace App\Http\Controllers;
|
||||
|
||||
use App\GuidesCategory;
|
||||
use App\Guide;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
|
||||
|
@ -24,7 +25,7 @@ class GuidesCategoryController extends Controller
|
|||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
* @return Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
|
@ -60,7 +61,7 @@ class GuidesCategoryController extends Controller
|
|||
if(!$saved) {
|
||||
return redirect()->route("guides-category.store");
|
||||
} else {
|
||||
$guides = GuidesCategory::query()->paginate(20);
|
||||
$guides = Guide::query()->paginate(20);
|
||||
|
||||
return redirect()->route("guides.index", ['guides' => $guides]);
|
||||
}
|
||||
|
@ -69,64 +70,64 @@ class GuidesCategoryController extends Controller
|
|||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param \App\GuidesCategory $guidesCategory
|
||||
* @return \Illuminate\Http\Response
|
||||
* @param int $id
|
||||
*/
|
||||
public function show(GuidesCategory $guidesCategory)
|
||||
public function show($id)
|
||||
{
|
||||
return Response::detect("guides-category.show", [ "guideCategory" => $guidesCategory]);
|
||||
return Response::detect("guides-category.show", $id);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param \App\GuidesCategory $guidesCategory
|
||||
* @return \Illuminate\Http\Response
|
||||
* @param int $id
|
||||
* @return Response
|
||||
*/
|
||||
public function edit(GuidesCategory $guidesCategory)
|
||||
public function edit($id)
|
||||
{
|
||||
$guideCate = GuidesCategory::query()->where("id", "=", $guidesCategory->id)->first();
|
||||
dd($guideCate);
|
||||
return redirect()->route("guides-category.edit", ["guideCategory" => $guideCate]);
|
||||
$guideCate = GuidesCategory::query()->where("id", "=", $id)->first();
|
||||
return Response::detect("guides-category.edit", [ "guideCategory" => $guideCate]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param \App\GuidesCategory $guidesCategory
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(Request $request, GuidesCategory $guidesCategory)
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
$data = $request->validate([
|
||||
"guidesCategoryName" => "required|max:255",
|
||||
]);
|
||||
|
||||
$guideCate = Guide::query()->where("id", "=", $guidesCategory->id)->first();
|
||||
$guideCate = GuidesCategory::query()->where("id", "=", $id)->first();
|
||||
$guideCate->update($data);
|
||||
$saved = $guideCate->save();
|
||||
|
||||
if(!$saved){
|
||||
return redirect()->route("guides-category.update", [ "guideCategory" => $guide ]);
|
||||
return redirect()->route("guides-category.edit", $id);
|
||||
}else{
|
||||
$guides = Guide::query()->paginate(20);
|
||||
|
||||
return redirect()->route("guides.index", ['guidesCategory' => $guides]);
|
||||
return redirect()->route("guides.index", ['guides' => $guides]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param \App\GuidesCategory $guidesCategory
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy(GuidesCategory $guidesCategory)
|
||||
public function destroy($id)
|
||||
{
|
||||
$guide = Guide::find($guidesCategory); //$guidesCategory = $id
|
||||
$guide->delete();
|
||||
$guideCategory = GuidesCategory::find($id);
|
||||
$guides = Guide::query()->where('guide_category_id', '=', $id);
|
||||
|
||||
$guides->delete();
|
||||
$guideCategory->delete();
|
||||
|
||||
return redirect()->route("guides.index");
|
||||
}
|
||||
|
|
|
@ -6,17 +6,17 @@
|
|||
@endsection
|
||||
|
||||
@section("path")
|
||||
<a href="{{route('guides-category.edit', ['guidesCategory' => $guideCategory ])}}" class="text-white">Rediger kategori</a> /
|
||||
<a href="{{route('guides-category.edit', $guideCategory )}}" class="text-white">Rediger kategori</a> /
|
||||
@endsection
|
||||
|
||||
@section("content")
|
||||
<h1>Rediger vejlednings kategori</h1>
|
||||
<form method="post" action="{{ route("guides-category.update", ['guidesCategory' => $guideCategory ]) }}">
|
||||
<form method="post" action="{{ route("guides-category.update", $guideCategory) }}">
|
||||
@csrf
|
||||
@method("put")
|
||||
<label for="name">Kategori navn:</label>
|
||||
<label hidden id="error" for="errormesseages">kategorien findes allerede</label>
|
||||
<input type="text" name="name" id="name" value="{{ $guideCategory->name }}" required>
|
||||
<label hidden id="error" for="errormesseages">Kategorien findes allerede</label>
|
||||
<input type="text" name="guidesCategoryName" id="guidesCategoryName" value="{{ $guideCategory->guidesCategoryName }}" required>
|
||||
<input type="submit" id="disable" class="btn btn-dark text-white" value="Rediger">
|
||||
</form>
|
||||
@endsection
|
||||
|
@ -33,7 +33,7 @@
|
|||
|
||||
//Dont delete me, if the user reloads the pages with text in the text-box this code runs.
|
||||
$(document).ready(function () {
|
||||
$value = $('#name').val();
|
||||
$value = $('#guidesCategoryName').val();
|
||||
$.ajax({
|
||||
type: 'get',
|
||||
url: '{{route('guides-category.nameCheckUpdate')}}',
|
||||
|
@ -57,7 +57,7 @@
|
|||
});
|
||||
});
|
||||
|
||||
$('#name').on('keyup', function () {
|
||||
$('#guidesCategoryName').on('keyup', function () {
|
||||
$value = $(this).val();
|
||||
$.ajax({
|
||||
type: 'get',
|
||||
|
|
|
@ -65,6 +65,18 @@
|
|||
@foreach(\App\GuidesCategory::query()->get() as $guideCategory)
|
||||
<tr>
|
||||
<td>{{$guideCategory->guidesCategoryName}}</td>
|
||||
@if(auth()->user()->can('guides.edit'))
|
||||
<td><a href="{{ route("guides-category.edit", $guideCategory) }}"><img class="w-100" src="{{ asset('/images/icons/pencil-dark.svg') }}" alt="Update2"></a></td>
|
||||
@endif
|
||||
@if(auth()->user()->can('guides.delete'))
|
||||
<td><form method="post" action="{{ route("guides-category.destroy", $guideCategory) }}" class="w-100 nostyle">
|
||||
@csrf
|
||||
@method("delete")
|
||||
|
||||
<button onclick="return confirm('Are you sure you want to delete? You will also delete all guides with this category!');" class="w-100 nostyle" type="submit"><img class="w-100 cursor-pointer" src="{{ asset('/images/icons/trashcan-dark.svg') }}" alt="Delete"></button>
|
||||
</form>
|
||||
</td>
|
||||
@endif
|
||||
</tr>
|
||||
@endforeach
|
||||
</table>
|
||||
|
|
Loading…
Reference in New Issue