0

According to my scenario when I select a doctor whose id is #slmc, I want to retrieve data relevant to the doctor I have chosen..

This is my blade File -> Admin/channel.blade

  <label id="lslmc" for="slmc" class="control-label">Choose a Doctor </label><br />
  <select class="form-control" id="slmc" name="slmc" onchange=" getPatient()" >
    <option value="">----Select the Doctor----</option>
    @foreach($Doctors as $Doctor)
      <option value ="{{$Doctor-> slmc}}">{{$Doctor->fname}} {{$Doctor->sname}}  </option>
    @endforeach
  </select>
</div>

<div id ="dd"></div>

Then this is my getPatient() function in the controller

public function getPatient($slmc){
        $patients = DB::table('channel')->where('slmc', $slmc)->get();
        return $patients;
}

This is the Ajax call in the script function.

function getPatient() {

    var patient = $("#slmc").val();

    $.ajax(
        {
            type: 'get',
            url: ('/Admin/channel/getPatient'),
            data: {'patients': patient},
            success: function (data) {
                $('#dd').html("");
                $('#dd').html(data);
            }
        }
    );
}

This is web.php

Route::get('/Admin/channel/getPatient{slmc}', 'channelController@getPatient' );

Is there something wrong with my Ajax call. I'm new to it.

2 Answers 2

1

Route :

Route::get('/Admin/channel/getPatient', 'channelController@getPatient' );

Controller :

ChannelController.php :

use Illuminate\Http\Request;
class ChannelController extends Controller
{

    public function getPatient(Request $request){
        $patients = \DB::table('channel')->where('slmc', $request->patients)->get();
        return $patients;
    }
}  
Sign up to request clarification or add additional context in comments.

Comments

0

I was able to do it The ajax function goes like this

function getPatient() {
    var patient = $("#slmc").val();

    $.ajax({
        type: 'get',
        url: ('/Admin/channel/getPatient'),
        data: {'slmc': patient},
        success: function (data) {
            $('#dd').html("");
            var divHtml = "";
            divHtml += "<table class='table table-bordered table-hover'>";
            divHtml += "<tr>";
            divHtml += "<td>" + data[0].pname + "</td>";
            divHtml += "<td>" + data[0].address + "</td>";
            divHtml += "</tr>";
            divHtml += "</table>";
            $('#dd').html(divHtml);
            console.info(data);
        },
        error: function (data) {
            console.error(data);
        }
    });
}

And my controller function is

public function getPatient(Request $request) {
    $slmc = $request->get('slmc');
    $patients = \DB::table('channel')->where('slmc', $slmc)->get();
    return $patients;
}

web.php

Route::get('/Admin/channel/{slmc}', 'channelController@getPatient' );

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.