'Autocomplete cannot search in table with two foreign key Laravel

and i want make autosearch from local database, but in other case with table in detail cannot be get, but in just manual search is successfully:

Image of table with two foreign key

code in my controller for method index is (this is just manual search) :

public function index(Request $request)
{
    $filterKeyword = $request->get('keyword');
    $data['course'] = Course::paginate(5);
    if ($filterKeyword) {
        $data['course'] = Course::where('title', 'LIKE', "%$filterKeyword%")->paginate(5);
    }
    return view('course.index', $data);
}

code in my routes/web is

Route::get('course.search', function (Request $request) {
$query = $request->get('query');
$filterResult = Course::where('title', 'LIKE', '%' . $query . '%')->get();
return response()->json($filterResult);
});

my code in view(interface) is :

<div class="col-8">
<input type="search" class="typeahead form-control" value="{{ Request::get('keyword') }}"id="keyword" name="keyword">
</div>


<div class="col-2">
   <button type="submit" class="btn btn-outline-info"><span class="fas fa-search"></span></button> 
</div>

my javascript for get query when input :

<script src="https://cdnjs.cloudflare.com/ajax/libs/bootstrap-3-typeahead/4.0.2/bootstrap3-typeahead.min.js"></script>
<script type="text/javascript">
    var route = "{{ url('course.search') }}";

    $('#keyword').typeahead({
        source: function(query, process) {
            return $.get(route, {
                query: query
            }, function(data) {
                return process(data);
            });
        }
    });
</script>

is there a certain way to anticipate from foreign field?



Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source