Made Live search is done

This commit is contained in:
2020-07-27 16:03:49 +02:00
parent f1fb73beec
commit b9633d36a9
12 changed files with 296 additions and 5 deletions
@@ -6,6 +6,7 @@ use App\Event;
use App\User;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
use Illuminate\Support\Facades\DB;
class EventController extends Controller
@@ -130,4 +131,44 @@ class EventController extends Controller
$event->delete();
return redirect()->route("events.index");
}
public function search(Request $request){
if($request->ajax()){
$output = "<tr>".
"<th>Event Navn</th>".
"<th>Event Beskrivelse</th>".
"<th>Event Dato</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>";
$events = DB::table('events')->where('name', 'LIKE',$request->search.'%')
->orWhere('date','LIKE', $request->search.'%')
->get();
if(count($events) !== 0){
foreach ($events as $key => $event){
$output.='<tr>'.
'<td>' . $event->name . '</td>'.
'<td>' . $event->description .'</td>'.
'<td>' . $event->date .'</td>'.
'<td><a href="'. route("events.edit", [ "event" => $event->id ]) . '"><img class="w-100" src="'. asset('/images/icons/pencil-dark.svg') . '" alt="Update"></a></td>'.
'<td><form method="post" action="' .route("events.destroy", [ "event" => $event->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);
}
}
}