1

This is My View code When i am executing the application it only returns me NULL value, basically my $office_category is not being passed, i need the office category to query the database

 <div class="box-body">
                {{ Form::open(['route' => 'office.index','class' => 'form-horizontal office-form']) }}    
                <div class="form-body">
                    <div class="form-group">

                <div class="col-md-3">
                {{ Form::select('office_category', [
                            null=>'Please Select',
                            'Software' => 'Software',
                            'Computer Hardware' => 'Computer Hardware',
                            'Survey Instruments' => 'Survey Instruments',
                            'Office Equipments' => 'Office Equipments'
                            ], isset($office_category) ? $office_category : '', ['class' => 'form-control input-xlarge select2me', 'placeholder' => 'Project Type', 'id' => 'office_category'] ) }}
                        </div>
                        {{ Form::hidden('office_category', $office_category) }}
                            {{ Form::submit('Search Equipment',['class' => 'btn green']) }}
                    </div>
                </div>
                {{ Form::close() }}

My Controller Code: I want the Office category thats it

Class OfficeController extends BaseController{

public function index(){

    $office_category = Input::get('office_category');
    if($office_category=='')
        $offices = Office::orderBy('office_category', 'asc')
    ->get();
    else
        $offices = Office::where('office_category','=',$office_category)
                    ->get();

    $assets = ['table','datepicker'];
    $users = User::where('client_id','=','')
        ->orderBy('name','asc')
        ->lists('name','username');

    return View::make('office.index',[
            'office_category' => $office_category,
            'offices' => $offices,
            'users' => $users,
            'assets' => $assets

            ]);
}

Where am i going wrong please help.

3 Answers 3

1

You have a hidden field directly after your select that has the same name as the select. The value of this hidden field (empty) is what is getting sent to the server.

Delete this line:

{{ Form::hidden('office_category', $office_category) }}

Or rename this hidden field.

Sign up to request clarification or add additional context in comments.

Comments

0

By default Form::open creates a POST request and your index method on Controller are expecting a GET request.

You need to add a new route on routes.php to match this POST request.

Route::post('index', 'OfficeController@index');

Or if you don't mind, you can set index to listen any kind of request:

Route::any('index', 'OfficeController@index');

1 Comment

The OP did not mention a 404 for MethodNotAllowedHttpException. I don't imagine the routes are the issue.
0

In most of the case, above answer will solve your problem. If not, you can inspect your web request from browser and confirm value in $office_category variable.

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.