I am getting this error in my browser when I am trying to make post or put or delete request I tried to edit the response header in the controller and to have middleware but still getting the error
in one of the controllers it works for me for (get,post,delete) requests but still having the problem with the put request however here is the code of the working controller(just the post delete get)
   <?php

namespace App\Http\Controllers;

use App\Models\locations;
use Illuminate\Http\Request;

class locationController extends Controller
{
    public function store(Request $request){
        $data = $request->validate([
            'name'=>'required|min:3'
        ]);
        $response = [
            'returnCode'=>200,
            "errorMsg"=>"",
            "result"=>locations::create($data)
        ];
         return response()->json($response,200)->header('Access-Control-Allow-Origin', '*')
        ->header('Access-Control-Allow-Methods', 'POST, GET, OPTIONS, PUT, DELETE')
        ->header('Access-Control-Allow-Headers', 'Content-Type, Authorization');
        
       }
       
public function delete($id){
        $location = locations::destroy($id);
      
        $response = [
            'returnCode'=>200,
            "errorMsg"=>"",
            "result"=>$location
        ];
        return response($response,200)->header('Access-Control-Allow-Origin', '*')
        ->header('Access-Control-Allow-Methods', 'POST, GET, OPTIONS, PUT, DELETE')
        ->header('Access-Control-Allow-Headers', 'Content-Type, Authorization');  
    }
     public function update(locations $location,Request $request){
        $data = $request->validate([
            'name'=>'required',
            
        ]);
        $location->update($data);
        $location->save();
        $response = [
            'returnCode'=>200,
            "errorMsg"=>"",
            "result"=>$location
        ];
        return response($response,200)->header('Access-Control-Allow-Origin', '*')
        ->header('Access-Control-Allow-Methods', 'POST, GET, OPTIONS, PUT, DELETE')
        ->header('Access-Control-Allow-Headers', 'Content-Type, Authorization');  
    }

    public function getById($id){
        $response = [
            'returnCode'=>200,
            "errorMsg"=>"",
            "result"=>locations::find($id)`your text`
        ];
        return response($response,200);
    }
    public function index(){
        $response = [
            'returnCode'=>200,
            "errorMsg"=>"",
            "result"=>locations::all()
        ];
        return response($response,200);
    }
    


}

and here is the routes for the same controller

Route::get('/location/getall',[locationController::class,'index']);
Route::get('/location/getbyid/{id}',[locationController::class,'getById']);
Route::post('/location/add',[locationController::class,'store']);
Route::put('/location/update/{location}',[locationController::class,'update']);
Route::delete('/location/delete/{id}',[locationController::class,'delete']);
Route::options('/location/update/{location}', function () {
    return response()->json(null, 200)
        ->header('Access-Control-Allow-Origin', '*')
        ->header('Access-Control-Allow-Methods', 'PUT,GET,DELETE,POST')
        ->header('Access-Control-Allow-Headers', 'Content-Type, Authorization');
});

here is the controller code that's not working for any(put, delete,post)
namespace App\Http\Controllers;

use App\Models\Lands;
use App\Models\locations;
use Illuminate\Http\RedirectResponse;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Spatie\QueryBuilder\QueryBuilder;

use function PHPSTORM_META\map;

class landController extends Controller
{
   public function store(Request $request){
    
    $data = $request->validate([
        'ownerName'=>'required',
        'size'=>'required',
        'price'=>'required',
        'phoneNumber'=>'required',
        'locations_id'=>'required',
        'aquariumNumber'=>'required',
        'partNumber'=>'required',
        'streetNumber'=>'required',
        'streetWide'=>'required'
    ]);
    
    $land = Lands::create($data);
    $response = [
        'returnCode'=>200,
        "errorMsg"=>"",
        "result"=>$land
    ];
    return response($response, 200)
        ->header('Access-Control-Allow-Origin', '*')
        ->header('Access-Control-Allow-Methods', 'POST, GET, OPTIONS, PUT, DELETE')
        ->header('Access-Control-Allow-Headers', 'Content-Type, Authorization');
   
   }
//    public function search(Request $request){
//     //return locations::where('','LIKE',"%$request->name%")->get();
// }
    public function index(Request $request){
        $lands = lands::with(['locations'])->get();
      
        $response = [
            'returnCode'=>200,
            "errorMsg"=>"",
            "result"=>$lands
        ];
        return response($response,200);
    }
    public function getById($id){
        $lands = lands::with(['locations'])->find($id);
      
        $response = [
            'returnCode'=>200,
            "errorMsg"=>"",
            "result"=>$lands
        ];
        return response($response,200); 
    }
    
    public function handleCorsPreflight()
{
    return response(null,200)
        ->header('Access-Control-Allow-Origin', '*')
        ->header('Access-Control-Allow-Methods', 'POST, GET, OPTIONS, PUT, DELETE')
        ->header('Access-Control-Allow-Headers', 'Content-Type, Authorization');
}
    
    public function delete($id){
        $lands = lands::destroy($id);
      
        $response = [
            'returnCode'=>200,
            "errorMsg"=>"",
            "result"=>$lands
        ];
        return response($response,200);  
    }
    public function update(Lands $land,Request $request){
        $data = $request->validate([
            'ownerName'=>'required',
            'size'=>'required',
            'price'=>'required',
            'phoneNumber'=>'required',
            'locations_id'=>'required',
            'aquariumNumber'=>'required',
            'partNumber'=>'required',
            'streetNumber'=>'required',
            'streetWide'=>'required'
        ]);
        $land->update($data);
        $land->save();
        $response = [
            'returnCode'=>200,
            "errorMsg"=>"",
            "result"=>$land
        ];
        return response($response,200);  
    }


and here is the routing for the same controller
`
`Route::options('/land/add', [landController::class,'handleCorsPreflight']);
Route::get('/land/getall', [landController::class,'index']);
Route::get('/land/getbyid/{id}', [landController::class,'getById']);
Route::post('/land/add', [landController::class,'store']);
Route::put('/land/update/{land}', [landController::class,'update']);
Route::delete('/land/delete/{id}', [landController::class,'delete']);``

finnaly here is the error code
Access to XMLHttpRequest at 'https://swift-serv.com/api/land/add/' from origin 'https://house-land-asem.000webhostapp.com' has been blocked by CORS policy: Response to preflight request doesn't pass access control check: Redirect is not allowed for a preflight request.
***some note
I am using hostinger for laravel and 000webhost for the angular
thank you for your help and sorry if I wrote too much