Made Live search is done
This commit is contained in:
@@ -6,6 +6,7 @@ use App\ExternalLink;
|
||||
use App\MenuPlan;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
|
||||
|
||||
class MenuPlanController extends Controller
|
||||
@@ -130,4 +131,43 @@ class MenuPlanController extends Controller
|
||||
$menuplan->delete();
|
||||
return redirect()->route("menu-plans.index");
|
||||
}
|
||||
|
||||
|
||||
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>';
|
||||
}
|
||||
}
|
||||
return Response($output);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user