Laravel 5.5 Ajax problem

Posted 8 months ago by AlenV


The problem is that I want to sort CarFeatures by name, but when I change listing from A-Z to Z-A nothing happens, I see the request in developer tools, but no changes.


    Route::get('/carfeature/{sortBy}', ['uses' => '[email protected]']);


public function listCarFeatures(Request $request, $sortBy) {
            $sortBy = $request->input('sortBy');

        if($sortBy == 'az') {
            // Get car features from Database
            $carFeatures = DB::table('car_features')->orderBy('car_feature_name', 'asc')->paginate(5);
        } else {
            $carFeatures = DB::table('car_features')->orderBy('car_feature_name', 'desc')->paginate(5);

        // Return view with CarFeatures
        return view('private.carfeature.carfeature_show')
        ->with(['carFeatures' => $carFeatures]);


function sortCarFeatures() {
    x = document.getElementById('carFeatureSort').value;

        url: 'carfeature',
        type: 'GET',
        data: { sortBy: x },
        success: function(response){
            console.log('Success: ' + response);
        error: function(response){
            console.log('Error: ' + response);



<!-- Sort By -->
    <div class="col-md-6 d-flex justify-content-right">

        <div class="col-md-5 mt-3">
            <h4 class="text-center">Sort by</h4>

        <div class="col-md-7 mt-3">
            <select id="carFeatureSort" class="form-control" onchange="sortCarFeatures()">
                <option selected value="az">
                    Name A-Z
                <option value="za">
                    Name Z-A

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

Laracasts Mascot

Hi, Have We Met Yet?

Did you know that, in addition to the forum, Laracasts includes well over 1000 lessons on modern web development? All for the price of one lunch out per month.

Sign Me Up


Reply to

Use Markdown with GitHub-flavored code blocks.