Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/248.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 拉威尔问题中通过复选框获取数据_Php_Mysql_Laravel - Fatal编程技术网

Php 拉威尔问题中通过复选框获取数据

Php 拉威尔问题中通过复选框获取数据,php,mysql,laravel,Php,Mysql,Laravel,我试图使用Laravel中的两个独立查询从两个不同的表中获取数据。但我想用两个不同的复选框显示这两个表数据,例如,如果我想查看出版物详细信息或教育详细信息或两者,请帮助我如何处理视图 我的代码如下所示: 控制器代码是ExampleController.php <?php namespace App\Http\Controllers; use Illuminate\Http\Request; use DB; use Auth; class ExampleController exte

我试图使用Laravel中的两个独立查询从两个不同的表中获取数据。但我想用两个不同的复选框显示这两个表数据,例如,如果我想查看出版物详细信息或教育详细信息或两者,请帮助我如何处理视图

我的代码如下所示:

控制器代码是ExampleController.php

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use DB;
use Auth;


class ExampleController extends Controller
{

    public function index()
    {

         $result = DB::table('education')->get();
         $data = DB::table('publications')->get();

         return view('triel',compact('result','data'));
    }

}

请修改我的视图,通过复选框分别获取这两个结果。

有许多方法可以实现您正在尝试的目标。我展示的示例是使用Jquery

  • 在表中添加一个Id,例如

    
    

  • 将单击时的事件
    添加到您的复选框中。当其中一个复选框被点击时,比如说发布,然后隐藏你的研究细节表。e、 g

    $(.checkbox publication”)。单击(函数(){
    $(“#研究细节”).css('display','none');
    $(“#出版物详细信息”).css('display','block');
    });

  • 反之亦然。如果两者都单击,则显示两个表

    如果您想使用更高级、更高效的工具,请尝试Ajax

  • @extends('layouts.app')
    @section('content')
    <div class="container"><br>
        <h1>Irfan Khan Triel Page</h1>
    
        <div class="text text-success text-center">
            PHD Research
        </div>
        <table class="table">
            <tr>
                <th>
                    PHD Research Area
                </th>
                <th>University</th>
                <th>Country</th>
            </tr>
    
         @foreach($result as $value)
            <tr>
                <td>{{$value->research_area}}</td>
    
                <td>{{$value->univ}}</td>
    
                <td>{{$value->country}}</td>
            </tr>
            @endforeach
           </table>
    
            <div class="text text-success text-center">
           Publications Detail
        </div>
        <table class="table">
            <tr>
                <th>
                    Title
                </th>
                <th>Status</th>
                <th>Year</th>
            </tr>
    
         @foreach($data as $value)
            <tr>
                <td>{{$value->title}}</td>
    
                <td>{{$value->status}}</td>
    
                <td>{{$value->year}}</td>
            </tr>
            @endforeach
    
        </table>
    
        @endsection
    
    Route::get('triel','ExampleController@index');