Laravel PHP使用下拉列表更新HTML表格视图

时间:2017-10-27 13:09:26

标签: php jquery mysql httprequest

我已经阅读了很多内容,我正在尝试在我的视图中找到一种刷新HTML表格的方法。

我想使用一些下拉菜单来选择随后插入查询的变量。

在我的控制器中,我有填充下拉列表的查询,以及填充表并对其进行分页的查询,但我需要了解如何在下拉列表更改时更改表中的条目列表

我已经阅读了相当多的内容,很多人在onchange中使用javascript,但是我无法弄清楚如何通过多次下拉更改来完成工作,如果可能的话,有兴趣更改视图不更改网址,但如果不需要一些指针或指导,如果有多个过滤器,如何跟踪网址中的变量。

编辑:

查看:

@extends('layouts.master')

@section('title', 'Vulnerabilities')

@section('sidebar')
  @parent
@endsection

@section('content')
  <div class="container">
    <div class="left">
      <div class="form-group"{{ $errors->has('vulns') ? ' has-error' : '' }}>
        <label for="vulnerability" class="col-sm-1 control-label">Vulnerability</label>
        <select class="form-control" name="cve_id" id="cve_id" onchange="javascript:location.href = this.value;">
          <option value="" selected>{{ $vuln }}</option>
          @foreach ($vulns as $vn)
            <option value="{{ $vn->cve }}">{{ $vn->cve }}</option>
          @endforeach
        </select>
        @if ($errors->has('vulns'))
          <span class="help-block">
            <strong>{{ $errors->first('vulns') }}</strong>
          </span>
          @endif
      </div>
      Vulnerable Hosts:<br/>
      @foreach ($vhost as $object)
        {{ $object->host }}<br/>
      @endforeach
    </div>
    <div class="right">
      Description:<br/>
      @foreach ($desc as $object)
        <p>{{ $object->description }}</p>
        <br/>
      @endforeach
      Solution:<br/>
      @foreach ($sltn as $object)
      <p>{{ $object->solution }}</p>
      <br/>
      @endforeach
    </div>
  </div>
@endsection

控制器:

<?php

namespace App\Http\Controllers;

use Illuminate\Support\Facades\DB;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use App\Item;

class VulnerabilityController extends Controller {
  /**
     * Return View file
     *
     * @var array
     */
  public function Vulnerability() {
    return redirect('vulnerability/CVE');
  }

  public function listHosts(Request $request) {

    $vuln = $request->vuln;   

    $vhost = DB::table('items')
              ->select('host')
              ->where('cve', 'like', $vuln)
              ->groupBY('host')
              ->get();

    $vulns = DB::table('items')
             ->select('cve')
             ->groupBY('cve')
             ->get();

    $desc = DB::table('items')
            ->select('description')
            ->where('cve', 'like', $vuln)
            ->groupBy('description')
            ->get();

    $sltn = DB::table('items')
            ->select('solution')
            ->where('cve', 'like', $vuln)
            ->groupBy('solution')
            ->get();

    return view('vulnerability', compact('vhost', 'vulns', 'vuln', 'desc', 'sltn'));
  }
}

路线:

Route::get('vulnerability', 'VulnerabilityController@vulnerability');
Route::get('vulnerability/{vuln}', 'VulnerabilityController@listHosts');

0 个答案:

没有答案