selam arkadaşlar şöle bir sorunum var ajax ile inputtan bir sayı girdiğimde 3 tane tabloya birden veri girilmesini istiyorum fakat sadece record tablosuna kayıt yapıyor bu aşağıdaki attığım kodda hata nerde var bi yardım ederseniz sevinirim
public function Searchnumber(Request $request){
// burası arama yeri
// Bu, sunucuya gelen veriyi gösterir
$one_search=Onebox::where('box_id','LIKE','%'.$request->input('query').'%')
->first();
if ($one_search) {
# code...
$control_db=Onebox::where('box_id',$request->input('query'))->first();
$control_db_two=Twobox::where('box_id',$request->input('query'))->first();
$control_db_three=Threebox::where('box_id',$request->input('query'))->first();
if ($control_db) {
# code...
if ($control_db->box_id == $control_db->box_one ||
$control_db->box_id == $control_db->box_two ||
$control_db->box_id == $control_db->box_three ||
$control_db->box_id == $control_db->box_four ||
$control_db->box_id == $control_db->box_five ||
$control_db->box_id == $control_db->box_six ||
$control_db->box_id == $control_db->box_seven ) {
$yellow = Color::where('color_id', $one_search->box_id)->first();
$insert_yellow=Record::insert([
'color_one' => $yellow->color_one,
'color_two' => $yellow->color_two,
'user_email' => Auth::user()->email,
'color_name' => 'yellow',
]);
}
else{
$blue = Color::where('color_id', $one_search->box_id)->first();
$insert_blue=Record::insert([
'color_one' => $blue->color_one,
'color_two' => $blue->color_two,
'user_email' => Auth::user()->email,
'color_name' => 'blue',
]);
}
}
elseif($control_db_two){
if($control_db_two->box_id == $control_db_two->box_one ||
$control_db_two->box_id == $control_db_two->box_two ||
$control_db_two->box_id == $control_db_two->box_three ||
$control_db_two->box_id == $control_db_two->box_four ||
$control_db_two->box_id == $control_db_two->box_five ||
$control_db_two->box_id == $control_db_two->box_six ||
$control_db_two->box_id == $control_db_two->box_seven) {
$green = Color::where('color_id', $one_search->box_id)->first();
$insert_green=Twocolor::insert([
'color_one' => $green->color_one,
'color_two' => $green->color_two,
'user_email' => Auth::user()->email,
'color_name' => 'green',
]);
}
else{
$red = Color::where('color_id', $one_search->box_id)->first();
$insert_red=Twocolor::insert([
'color_one' => $red->color_one,
'color_two' => $red->color_two,
'user_email' => Auth::user()->email,
'color_name' => 'red',
]);
}
}
elseif($control_db_three){
if($control_db_three->box_id == $control_db_three->box_one ||
$control_db_three->box_id == $control_db_three->box_two ||
$control_db_three->box_id == $control_db_three->box_three ||
$control_db_three->box_id == $control_db_three->box_four ||
$control_db_three->box_id == $control_db_three->box_five ||
$control_db_three->box_id == $control_db_three->box_six ||
$control_db_three->box_id == $control_db_three->box_seven){
$grey = Color::where('color_id', $one_search->box_id)->first();
$insert_grey=Twocolor::insert([
'color_one' => $grey->color_one,
'color_two' => $grey->color_two,
'user_email' => Auth::user()->email,
'color_name' => 'grey',
]);
}
else{
$orange = Color::where('color_id', $one_search->box_id)->first();
$insert_orange=Threecolor::insert([
'color_one' => $orange->color_one,
'color_two' => $orange->color_two,
'user_email' => Auth::user()->email,
'color_name' => 'orange',
]);
}
}
}
}
ajax kodları:
@extends('backend.dashboard')
@section('title', 'Anasayfa')
@section('sidebar')
@endsection
@section('content')
<div class="card">
<h5 class="card-header">Anasayfa bölümü</h5>
<div class="table-responsive text-nowrap">
<table class="table table-dark">
<thead>
<tr>
<td>Number</td>
<td>Number-2</td>
<td>Number-3</td>
<td>Number-4</td>
<td>Number-5</td>
<td>Number-6</td>
</tr>
</thead>
<tbody class="table-border-bottom-0">
<!-- İçerik buraya eklenecek -->
</tbody>
</table>
</div>
<div id="results"></div>
<div id="result"></div>
</div>
<div class="col-sm-6 offset-sm-3 mt-4">
<form id="searchForm" method="get" action="{{ route('Searchnumber') }}">
@csrf
<input class="form-control bg-primary text-light" type="text" placeholder="Bir sayı giriniz" aria-label="default input example" id="searchInput" name="query">
</form>
</div>
<script>
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
$(document).ready(function() {
$('#searchInput').on('keyup', function() {
let query = $(this).val(); // input alanındaki değeri al
if (query.length > 0) {
$.ajax({
url: "{{ route('Searchnumber') }}",
type: 'GET',
data: {
query: query
},
success: function(response) {
$('#results').html(response.html); // JSON'dan gelen HTML'i ekle
},
error: function(xhr) {
console.log(xhr.responseText); // Hata mesajını konsola yazdır
$('#results').html('<p>Bir hata oluştu</p>');
}
});
} else {
$('#results').html('');
}
});
});
</script>
<script>
/*
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
*/
var d= setInterval(function(){
$.ajaxSetup({
headers: {
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
}
});
$(document).ready(function() {
$.ajax({
url: "{{ route('Searchrecord') }}",
type: 'GET',
success: function(response) {
$('#result').html(response.yellow_html + response.blue_html); // JSON'dan gelen HTML'i ekle
},
error: function(xhr) {
console.log(xhr.responseText); // Hata mesajını konsola yazdır
$('#result').html('<p>Bir hata oluştu</p>');
}
});
});
},2000);
</script>
@endsection