1

I'm trying to pass three parameters to the controller using Laravel's post method on dropdown select list. I can't figure it out how to pass the third one. It depends on the other two parameters under the following MySQL:

SELECT id 
FROM maintable 
WHERE profileId='ValueOfTheFirstSelection' 
      AND departmentId='ValueOfTheSecondSelection';

My form:

<form action="/admin/postmaps" name="form" method="post">
                <div class="input-group">
                    <span class="input-group-addon">Profile ID</span>
                    <select class="form-control" name="select1" id="select1">
                        <?php use App\Department; $ids = DB::table('departments')->select('profileId')->get();$a = array();?>
                        @foreach ($ids as $id )
                            <?php  $a[] = $id->profileId; ?>                                
                        @endforeach
                        <?php $a = array_unique($a); ?> 
                        <option disabled selected value>  </option>
                        @foreach ($a as $element )
                            <option value="<?php echo $element; ?>">{{ $element }}</option>

                        @endforeach

                    </select>
                </div>

                <div class="input-group">
                    <span class="input-group-addon">Department ID</span>
                    <select class="form-control" name="select2" id="select2">
                      <?php $ids = DB::table('departments')->select( 'id')->get();$b = array();?>
                        @foreach ($ids as $id )
                            <?php  $b[] = $id->id; ?>                               
                        @endforeach
                        <option disabled selected value>  </option>
                        <?php for ($i = 0; $i < count($b); ++$i) {
                            echo "<option value='$b[$i]'>".$b[$i]."</option>";

                        }
                        ?>

                    </select>
                </div>
                <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal">Cancel</button>
            <button type="submit" class="btn btn-primary" id="updateTerminalInfo">Save</button>
            <input type="hidden" value="{{ Session::token() }}" name="_token">
        </div>
</form>
2
  • If you want to write queries in the view you don't need Laravel. You're not paying any attention to the MVC paradigm and Laravel is built around it... Commented Sep 8, 2016 at 17:32
  • 1
    As what Jonathan says, you really should be loading data in your controller and using it in the view. Cluttering up your view with database calls is bad form. Commented Sep 8, 2016 at 17:43

2 Answers 2

2

In your controller:

use DB;

and in your function : After you submit

$r = DB::table('Maintable')->select('id')->where('profileId', $request->profileId)
             ->where('departmentId', $request->departmentId)->get();

for more

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

Comments

1

Never exectute DB queries in a template, it's a terrible practice. After you submit the form, use Eloquent to get info (I assume you want an array of IDs):

public function submitForm(Request $request)
{

    Maintable::where('profileId', $request->profileId)
             ->where('departmentId', $request->departmentId)
             ->pluck('id');

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.