mercredi 28 septembre 2016

Cannot retrieve data via checkbox in laravel

I have a project in which i want to retrieve value from database via checkbox. But i cannot do this. My controller code is

public function browseProfessionals() {
        $userRoles = UserRole::whereIn('role_id', [2,3])->get();
        $users = array();
        $showUsers = array();

        foreach ($userRoles as $userRole) {
            $users[] = User::find($userRole->user_id);
        }

        $valid_providers = array();
        $all_providers = array();
        $user_role_all_providers = UserRole::where('role_id', 2)->get();

        foreach ($user_role_all_providers as $user_role_all_provider) {
            $all_providers[] = User::where('id', $user_role_all_provider->user_id)->first();
        }

        foreach ($all_providers as $all_provider) {
            $user = User::where('id', $all_provider->id)->first();
            $user_detail = UserDetail::where('user_id', $all_provider->id)->first();
            $user_meeting = UserMeeting::where('user_id', $all_provider->id)->first();
            $user_time = UserTime::where('user_id', $all_provider->id)->first();

            if (!empty($user_detail->avatar) && !empty($user_meeting->meeting_id) && !empty($user_time->hour_rate) && $user->is_active == 1 && $user->is_deleted == 0) {
                $valid_providers[] = $all_provider;
            }
        }

        $data = [
            'valid_providers' => $showUsers,
            'industries' => Industry::where('is_active', 1)->where('is_deleted', 0)->get(),
            'degrees' => UserDegree::where('degree_id', $user->degree_id)->get(),
        ];
        return view('frontends.browse-professionals', $data);
    }

My Blade template is

@extends ('frontends.layouts.app')
@section ('main')
    <div id="content-block" class="margin-top-140">
        <div class="container-fluid block custom-container">
            <h3 class="block-title">Browse Professionals</h3>
            <div class="block-subtitle"><span>Connect</span> <span>Learn</span> <span>Inspire</span> <span>Thrive</span> </div>
            <div class="row">
                
                    <div class="col-md-2 left-feild">
                        <div class="margin-bottom-30">
                            <h3>Search Filters</h3>
                        </div>
                        @if(Auth::check() && Auth::user()->user_role->role_id == 1000000)
                            <div class="be-vidget">
                                <h3 class="letf-menu-article"> Looking To </h3>
                                <div class="creative_filds_block">
                                    <div class="radio">
                                        <label><input type="radio" name="lookingTo" onclick="lookingTo(2)"> Seek Advice</label>
                                    </div>
                                    <div class="radio">
                                        <label><input type="radio" name="lookingTo" onclick="lookingTo(3)"> Share Advice</label>
                                    </div>
                                </div>
                            </div>
                            <script>
                                function lookingTo(e) {
                                    $.ajax({
                                        type: 'POST',
                                        url: '/' + e,
                                        success: function (result) {
                                            $('#browse_professionals').html(result);
                                        }
                                    });
                                }
                            </script>
                        @endif
                        <div class="be-vidget">
                            <h3 class="letf-menu-article">Professionals</h3>
                            <div class="-creative_filds_block">
                                <div class="fp-panel-wrap">
                                    <a class="toggle-btn active" onclick="open_industry()" href="#" data-target="#ul_industry" id="a_industry">Industry</a>
                                    <ul id="ul_industry" class="fp-panel open" style="overflow:scroll; height:200px;">
                                        @if(!empty($industries))
                                            @foreach($industries as $industry)
                                                <li value=""><a href="javascript:void(0)" onclick="industry_search()"></a> </li>
                                            @endforeach
                                        @endif
                                    </ul>
                                    <script>
                                        function industry_search(e) {
                                            $.ajax({
                                                type: 'POST',
                                                url: '/' + e,
                                                success: function (result) {
                                                    $('#education_experience').html(result);
                                                    $('#a_industry').attr('class', 'toggle-btn');
                                                    $('#ul_industry').css('display', 'none');
                                                    $('#education_experience').css('display', 'block');
                                                    $('#eduLevel').css('display', 'block');
                                                    $('#areaExperience').css('display', 'block');

                                                }
                                            });
                                        }
                                        function open_industry() {
                                            $('#education_experience').css('display', 'block'); // display none hobe na. collapse hoye jabe
//                                        $('#a_industry').attr('class', 'toggle-btn active');
//                                        $('#ul_industry').css('display', 'block');
                                            $('#education_experience').css('display', 'block');
                                            $('#eduLevel').css('display', 'none');
                                            $('#areaExperience').css('display', 'none');
                                        }
                                    </script>
                                    <div id="education_experience" style="">
                                        <a id="a_education" class="toggle-btn" href="#" data-target="#eduLevel">Education Level</a>
                                        <ul id="eduLevel" class="no-link fp-panel" style="overflow:scroll; height:200px;">


                                            @if(!empty($degrees))
                                                @foreach($degrees as $degree)
                                                    <li value=""></a> </li>
                                                @endforeach
                                            @endif

                                        </ul>
                                        <a id="a_experience" class="toggle-btn" href="#" data-target="#areaExperience">Areas of Experience</a>
                                        <ul id="areaExperience" class="no-link fp-panel" style="overflow:scroll; height:200px;">

                                        </ul>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="be-vidget">
                            <h3 class="letf-menu-article">Meeting Preferences</h3>
                            <label>Price</label>
                            <br> <br>
                            <input type="hidden" id="price_ranger" class="range-slider" value="23"/>


                            <label style="margin-top: 30px;">Type</label>
                            <div class="form-group">
                                <select class="form-input" id="meeting_type">
                                    <option value="3">All</option>
                                    <option value="1">Phone Meeting</option>
                                    <option value="2">Web Meeting</option>
                                </select>
                            </div>
                        </div>

                        <button id="search_professionals" type="button" class="btn color-2 size-2 btn-block hover-1">Apply Filter</button>
                        @if(Session::has('remove_filter'))
                            <button type="button" class="btn btn-danger size-2 btn-block hover-1">Remove Filter</button>
                        @endif

                        <script>
                            var industry = '';
                            $('#ul_industry li').click(function() {
                                industry = $(this).attr('value');
                            });

                            $("#search_professionals").click(function () {
                                var degrees = new Array();
                                $('input[name="degrees_checkbox"]:checked').each(function() {
                                    degrees.push(this.value);
                                });

                                var experiences = new Array();
                                $('input[name="experiences_checkbox"]:checked').each(function() {
                                    experiences.push(this.value);
                                });

                                var price_ranger = $("#price_ranger").val();
                                var price_ranger_array = price_ranger.split(",");
                                var start_price = price_ranger_array[0];
                                var end_price = price_ranger_array[1];

                                var meeting_type = $("#meeting_type").val();

                                $.ajax({
                                    'type' : 'post',
                                    'url' : '',
                                    'data' : {
                                        'industry' : industry,
                                        'educationLevels' : degrees,
                                        'areasOfExperiences' : experiences,
                                        'start_price' : start_price,
                                        'end_price' : end_price,
                                        'meeting_type' : meeting_type
                                    },
                                    'success' : function (result) {
                                        console.log(result);
                                        $('#browse_professionals').html(result);
                                    }
                                });
                            });
                        </script>
                    </div>
                

                <div class="col-md-10">
                    <div id="browse_professionals" class="row _post-container_">
                        @if (!empty($valid_providers))
                            @foreach ($valid_providers as $provider)

                                <div class="category-1 custom-column-5">
                                    <div class="be-post">
                                        <figure class="ratio-4-3 be-img-block-alt">
                                            <div class="ratio-inner" style="background-image: url('')">
                                                <img src="" alt="">
                                            </div>
                                        </figure>
                                        <div class="be-post-title"></div>
                                        <div class="author-post">
                                            <span><a href=""> </a></span>
                                        </div>
                                        <span></span>
                                        <div data-value="4" class="static-rating"></div>
                                        <div class="info-block clearfix">
                                            <a class="btn color-1 size-2 hover-1 pull-right" href="">Contact</a>
                                            <h3 class="rate"> $ /hr</h3>
                                        </div>
                                    </div>
                                </div>
                            @endforeach
                        @endif
                    </div>
                </div>
            </div>
        </div>
    </div>
@endsection

Please help me how can i show value via checkbox. Please help me solving this.




Aucun commentaire:

Enregistrer un commentaire