Livewire? Vue? React? jQuery? Alpine? Vanilla javascript?
Do you have some code to show?
Hi i try to associated 3 models 1)Specialities 2)Surveys 3)Works
Each specialities have many surveys that can declaration . That mean that each surveys have many same specialities_id (how i do that without duplicated rows? )
After each surveys belong to specific work
Livewire? Vue? React? jQuery? Alpine? Vanilla javascript?
Do you have some code to show?
@sinnbeck //Route
Route::get('getCourse/{id}', function ($id) {
$survey = App\Models\Survey::where('specialties', $id)->get();
return response()->json($survey);
});
@Constantine_92 have you tried using ->distinct() in your query?
@Tray2 what is distinct method do ?
@Constantine_92 https://laravel.com/docs/8.x/queries#specifying-a-select-clause
The distinct method allows you to force the query to return distinct results:
@Constantine_92 No it just ensures that a query only returns unique rows (no duplicates)
Route::get('getCourse/{id}', function ($id) {
$survey = App\Models\Survey::where('specialties', $id)->distinct()->get();
return response()->json($survey);
@sinnbeck Blade
<div class="form-group">
<label for="speciality_id">{{ trans('cruds.experience.fields.speciality') }}</label>
<select class="form-control select2 {{ $errors->has('speciality') ? 'is-invalid' : '' }}" name="speciality_id" id="category">
@foreach($specialities as $id => $entry)
<option value="{{ $id }}" {{ old('speciality_id') == $id ? 'selected' : '' }}>{{ $entry }}</option>
@endforeach
</select>
@if($errors->has('speciality'))
<div class="invalid-feedback">
{{ $errors->first('speciality') }}
</div>
@endif
<span class="help-block">{{ trans('cruds.experience.fields.speciality_helper') }}</span>
</div>
<div class="mb-3">
<label for="survey" class="form-label">Survey</label>
<select class="form-control" name="survey_id" id="survey"></select>
</div>
//script
<script>
$(document).ready(function() {
$('#category').on('change', function() {
var categoryID = $(this).val();
if(categoryID) {
$.ajax({
url: '/admin/getCourse/'+categoryID,
type: "GET",
data : {"_token":"{{ csrf_token() }}"},
dataType: "json",
success:function(data)
{
if(data){
$('#survey').empty();
$('#survey').append('<option hidden>Κατηγορία Μελετών</option>');
$.each(data, function(key, survey){
$('select[name="survey_id"]').append('<option value="'+ survey.specialties +'">' + survey.name + '</option>');
});
}else{
$('#survey').empty();
}
}
});
}else{
$('#survey').empty();
}
});
});
The problem that i face is: i have 75 specialities and 27 surveys but 1 specialities have at least 3 surveys that declaration. I want in my database at surveys not have duplicated rows for example nameofsurvey= ex | specialities_id = 1. nameofsurvey= ex | specialities_id = 2. nameofsurvey= ex | specialities_id = 7.
On changing states drop-down values, the corresponding district dropdown values will be loaded dynamically using jQuery AJAX. https://www.garagebandapp.net/
Please or to participate in this conversation.