Hocam çok pardon evet yanlış okumuşum,
Form
` <form method="post" enctype="multipart/form-data">
@csrf
<div class="form-group">
<label for="exampleInputEmail1">Servis Adı</label>
<input type="text" name="name" id="serviceName" class="form-control" placeholder="">
@ERROR('name') <p class="text-danger">{{$message}}</p> @enderror
</div>
<div class="form-group">
<label for="">Poliklink</label>
<select name="clinic_id" id="clinicId" class="form-control">
@foreach($clinics as $clinic)
<option value="">Seçiniz</option>
<option value="{{$clinic->id}}" >{{$clinic->name}}</option>
@endforeach
</select>
</div>
@ERROR('clinic_id') <p class="text-danger">{{$message}}</p> @enderror
<label for="">Servis Küçük Resim</label>
<div class="input-group mb-3">
<input type="file" name="image" id="image" class="form-control" >
</div>
@ERROR('image') <p class="text-danger">{{$message}}</p> @enderror
<button id="addService" type="submit" class="btn btn-success float-end">Ekle</button>
</form>`
Jquery Ajax
` $('#addService').click(function (event){
event.preventDefault();
var serviceName = $('#serviceName').val();
var clinicId = $('#clinicId').val();
var image = $('#image').val();
$.ajax({
type:'post',
url:'{{route('service.store')}}',
headers:{
'X-CSRF-TOKEN': $('meta[name="csrf-token"]').attr('content')
},
data:{
name:serviceName,
clinicId:clinicId,
image:image,
},
success:function (service){
console.log(service);
},
error:function (XMLHttpRequest){
console.log(XMLHttpRequest);
}
})
})`
Controller
` public function store(Request $request)
{
$validated = $request->validate([
'name' => 'required|string|max:100',
'clinic_id' => 'required',
'image'=>'required|mimes:jpg,bmp,png'
]);
try {
$service = new Service();
$service->name = $request->name;
$service->slug = Str::slug($request->name);
$service->clinic_id = $request->clinic_id;
if ($request->file('image')){
$path = $request->file('image')->store('images/services','public');
$service->image = $path;
}
$service->save();
return response()->json($service);
}
catch (\Throwable $th)
{
return redirect()->back()->with('alert','İşlem Başarısız');
}
}`
ne var ne yok hepsini ekledim ama acemiyim biraz idare edin, kusura bakmayın.