vendredi 24 juin 2016

Laravel 5.2 Select control dynamically loading another select control

I am new to Laravel.

I need to populate one select control based on the previous select option that a user selects.

Here is my blade/html(first select is hard coded for now, but the values are what will come from database)

<select id="company_type" name="company_type"class="form-control">
    <option value="2">Dealer</option>
    <option value="3">Customer</option>
    <option value="4">Partner</option>
</select>

<select id="organization_type_id" name="organization_type_id"class="form-control">
     @foreach($belongsto as $org)
     <option></option>
     @endforeach
</select>

Here is my javascript

        $('#company_type').on('change', function(e){
        console.log(e);
        var company_type = e.target.value;

        $.get("?company_type=" + company_type, function(data) {
            console.log(data);
            $('#organization_type_id').empty();
            $.each(data, function(index,subCatObj){
                $('#organization_type_id').append('subCatObj.name');
            });
        });
    });

Here is my Controller (This code is part of a function call that I making within the controller I would be returning a view once I get the data I need)

$companyType = '3';// Input::get('comapny_type');
$orgs =  Organization::where('organization_type_id','=',$companyType)->get();
return $orgs;

In my controller, I have hard coded an option that I expect to get from Input::get('company_type') However, the Input call returns null.

The parameters are not showing up in my URL so I am assuming that is the reason it is not working. However, I am not sure how to append ?company_type=3 to the URL, if that is how its supposed to be.



from Newest questions tagged laravel-5 - Stack Overflow http://ift.tt/28UiKjd
via IFTTT

Aucun commentaire:

Enregistrer un commentaire