DISPLAY DATA FROM DATBASE UPON FORM ENTRY IN SAME PAGE

Posted 4 months ago by Arunava007

Basically my goal is to make a form and display data in same page just below the form according to values of form by fetching it from database. Guide with me the routes. Need help in how to fetch values from database in separate route(GET) by using values from previous route(POST)

My View:

<form method="post"  action="{{ route('CRD') }}">
    {{ csrf_field() }}




    Domain Name: &nbsp; <select name="domain" id="domain">
        <option value="" selected="selected">--- Please select ---</option>
        <option value="Robotics">Robotics</option>
        <option value="Coding">Coding</option>
        <option value="Gaming">Gaming</option>
        <option value="Electrical">Electrical</option>
        <option value="Civil">Civil</option>
        <option value="General Events">General</option>
    </select>




    <input type="button" name="submit" class="button" value="CHECK EVENT LIST" onclick="validate()"><br><br>

    Event Name: &nbsp; <select name="event" id ="event">

        <!-- ROBOTICS -->

        <option value="" selected="selected">--- Please select ---</option>
        <option id="R1" value="Infinity War">Infinity War</option>
        <option id="R2" value="Terrestrial Terrain">Terrestrial Terrain</option>
        <option id="R3" value="Robo Rugby">Robo Rugby</option>
        <option id="R4" value="Sputnik">Sputnik</option>
        <option id="RC" value="Robo Combo">Robo Combo</option>

        <!-- CODING -->

        <option id="C1" value="Code Nova">Code Nova</option>
        <option id="C2" value="Code Xtreme">Code Xtreme</option>
        <option id="C4" value="Code Red">Code Red</option>
        <option id="C5" value="Web-o-Philia">Web-o-Philia</option>
        <option id="C6" value="Design-O-Static">Design-O-Static</option>
        <option id="CC" value="Coding Combo">Coding Combo</option>


        <!-- GAMING -->

        <option id="G1" value="COD MW 4">COD MW 4</option>
        <option id="G2" value="CS 1.6">CS 1.6</option>
        <option id="G3" value="FIFA 11">FIFA 11</option>
        <option id="G4" value="NFS MW">NFS MW</option>
        <option id="GC" value="Gaming Combo">Gaming Combo</option>


        <!-- Electrical -->

        <option id="E1" value="Circuitrix">Circuitrix</option>
        <!-- <option id="E2" value="Electroblitz">Electroblitz</option> -->


        <!-- CIVIL -->

        <option id="CE1" value="Setu Bandhan">Setu Bandhan</option>
        <option id="CE2" value="Mega Arch">Mega Arch</option>
        <option id="CE3" value="Track O Treasure">Track O Treasure</option>
        <option id="CEC" value="Civil Combo">Civil Combo</option>

        <!-- GENERAL -->

        <!-- <option id="GE1" value="Pubg">Pubg</option>
       <option id="GE2" value="8 Ball Pool">8 Ball Pool</option>
       <option id="GE3" value="Mini Militia">Mini Militia</option>
       <option id="GE4" value="Darts">Darts</option> -->
        <option id="GE5" value="Carrom">Carrom</option>
        <option id="GE6" value="Chess">Chess</option>
        <option id="GE7" value="B-Plan">B-Plan</option>
        <option id="GE8" value="Table Tennis">Table Tennis</option>
        <option id="GE9" value="Photography">Photography</option>
        <option id="GE10" value="Videography">Videography</option>
        <option id="GEC" value="Photography+Videography Combo">Photography+Videography Combo</option>

    </select><br><br>
    <div class="form-group">
        <div class="col-md-6 col-md-offset-4">
            <button type="submit" class="btn btn-primary" onclick="window.location='{{ route("display") }}'>
                SUBMIT
            </button>

        </div>
    </div>






    @foreach($users as $row)
        <tr>
            <td>{{$row->TID}}</td>

        </tr>
    @endforeach




</form>

My controller:

class CRDController extends Controller
{
    public function index()
    {
        $users = DB::table('rd1')->where([
            ['domain', '=', "bc"],
            ['event', '=', "bc"],

        ])->get();
        return view("CRD")->with('users',$users);
    }
    public function fetch(Request $request)
    {
        $users = DB::table('rd1')->where([
            ['domain', '=', $request->domain],
            ['event', '=', $request->event],

        ])->get();
        return view("CRD")->with('users',$users);
    }
}

My route:


Route::get('/CRD',['as'=>'CRD','uses'=> '[email protected]']);
Route::get('/CRD',['as'=>'display','uses'=> '[email protected]']);

Please sign in or create an account to participate in this conversation.