I am just building my first Laravel App and have the following question:
Simplified Table Structure:
Table CORPORATE
- id pk
- name
- checkbox “isSupplier”
- checkbox “isManufacturer”
Table COMPONENT
- id pk
- name
- if_corporate fk (where isManufacturer=true)
So my question is, where do I need to put hands on the code to get this “selector” implemented?
Thanks
edit:
resources/views/admin/components/create.blade.php
<select class="form-control select2 {{ $errors->has('corp') ? 'is-invalid' : '' }}" name="corp_id" id="corp_id" required> @foreach($corps as $id => $corp) <option value="{{ $id }}" {{ old('corp_id') == $id ? 'selected' : '' }}>{{ $corp }}</option> @endforeach </select>
is this the correct place to modify?
Advertisement
Answer
You are already too late in the code you have shared. That is the view, which comes after the controller in this instance.
The controller is probably called something like ComponentsController
there will be a line of code that says
$corps = Corporates::all();
Or something like that. That is where you need to update it. Probably something like this:
$corps = Corporates::where(["isManufacturer" => true)->get();
Now $corps
will be a collection of only ones that are manufacturers.