v1.4.0 - Added category search on the app

Added comments
Fixed code
Fixed pagination still being there without using it
This commit is contained in:
Anders
2020-09-22 10:45:27 +02:00
parent 505ed3710b
commit f95318a8f2
24 changed files with 157 additions and 63 deletions
@@ -30,7 +30,7 @@ class GuideController extends Controller
*/
public function index(Request $request)
{
$guides = Guide::query()->orderBy("created_at", "desc")->paginate(20);
$guides = Guide::query()->orderBy("created_at", "desc")->get();
return Response::detect("guides.index", [ "guides" => $guides]);
}
@@ -53,8 +53,6 @@ class GuideController extends Controller
*/
public function store(Request $request)
{
//Me no sure what to store mester big smoke :)
$requestGuide = $request->validate([
"name" => "required|max:255",
"guide_articles" => "required",
@@ -73,7 +71,7 @@ class GuideController extends Controller
if(!$saved) {
return redirect()->route("guides.store");
} else {
$guides = Guide::query()->paginate(20);
$guides = Guide::query()->get();
if($request->newsoption == true){
$news = new News();
@@ -140,7 +138,7 @@ class GuideController extends Controller
if(!$saved){
return redirect()->route("guides.update", [ "guide" => $guide ]);
}else{
$guides = Guide::query()->paginate(20);
$guides = Guide::query()->get();
if($request->newsoption == true){
$news = new News();
@@ -217,5 +215,57 @@ class GuideController extends Controller
}
}
// Runs the ajax call when changing the select field in guides.index (app)
public function showCategory(Request $request){
if($request->ajax()) {
// Get all guides where the category is what you want
if ($request->category != 'All')
$guides = Guide::query()->orderBy("created_at", "desc")->where('guide_category_id', '=', $request->category)->get();
else
$guides = Guide::query()->orderBy("created_at", "desc")->get();
$output = '';
// Begin showing all guides with the given category
if(!$guides->isEmpty()) {
foreach ($guides as $guide) {
$output .= '<div class="card">';
if ($guide->resource_id !== null) {
$output .= '<div class="header" style="background-size: cover; background-position: center; background-image: url(' . asset(\App\Resource::query()->where("id", "=", $guide->resource_id)->first()->filename) . ');">' .
'<h3 style="text-shadow: 2px 2px 2px #00788A;">' . $guide->name . '</h3>' .
'</div>';
} else {
$output .= '<div class="header">' .
'<h3>' . $guide->name . '</h3>' .
'</div>';
}
$output .= '<div class="container">';
$tags = ['<p>', '<b>', '<em>', '<a>', '<u>', '<s>', '<sub>', '<ul>', '<li>', '<sup>', '<div>', '<blockquote>', '<ol>', '<strong>', '<br>', '<h1>', '<h2>', '<h3>', '<h4>', '<h5>', '<h6>', '<h7>', '<span>'];
$output .= '' . \App\Helpers::closetags(substr(strip_tags($guide->guide_articles, $tags), 0, 300)) . '' .
'<div class="row" style="justify-content: center;">';
if (request()->cookie('languagesSetting') == "dk")
$output .= '<a style="margin: 0; padding: 0; text-align: center; font-weight: 700;" class="sde-blue" href="'. route("guides.show", ["guide" => $guide->id ]) .'">Læs mere</a>';
elseif (request()->cookie('languagesSetting') == "en")
$output .= '<a style="margin: 0; padding: 0; text-align: center; font-weight: 700;" class="sde-blue" href="'. route("guides.show", ["guide" => $guide->id ]) .'">Read more</a>';
else
$output .= '<a style="margin: 0; padding: 0; text-align: center; font-weight: 700;" class="sde-blue" href="'. route("guides.show", ["guide" => $guide->id ]) .'">Læs mere</a>';
$output .= '</div>'.
'</div>'.
'</div>';
}
} else { // If there are no guides with the given category, then display error message
if (request()->cookie('languagesSetting') == "dk")
$output .= '<p style="margin-bottom: auto; text-align: center">Der er ingen vejledninger af denne kategori</p>';
elseif (request()->cookie('languagesSetting') == "en")
$output .= '<p style="margin-bottom: auto; text-align: center">There are no guides of this category</p>';
else
$output .= '<p style="margin-bottom: auto; text-align: center">Der er ingen vejledninger af denne kategori</p>';
}
return Response($output);
}
}
}