0

I have sent data Angular side to laravel side if I use get method it's running without errors, but if I pick the post method, I get an error

Access-Control-Allow-Origin' header

Does anyone know about this? And this is should be header encrypt error

// Angular Code

import {Injectable} from '@angular/core';
import {HttpClient, HttpClientModule, HttpHeaders, HttpParams} from '@angular/common/http';
import {RequestOptions} from '@angular/http';
import {Observable} from 'rxjs';
import {BaseurlService} from '../BaseUrl/baseurl.service';

@Injectable({
  providedIn: 'root'
})
export class CompanyControlService {

  headers: Headers = new Headers();
  Options: any;

  constructor(private http: HttpClient, private configurl: BaseurlService) {

    this.headers.append('enctype', 'multipart/form-data');
    this.headers.append('Content-Type', 'application/json');
    this.headers.append('X-Requested-With', 'XMLHttpRequest');

    // @ts-ignore
    this.Options = new RequestOptions({headers: this.headers});

  }

  addEmployer(newRecode) {
    return this.http.post<any>(this.configurl.configUrlLoard() + 'employer/add', newRecode);
  }

}

// Laravel Code

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class EmployerController extends Controller
{
    function addEmployer()
    {
        error_log('Incoming request');
//        errorlog(request('companyNo'));
    }
}

//laravel route

Route::post('employer/add','EmployerController@addEmployer');
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459

1 Answers1

0

two solutions for ur problem: 1 first solution (the most easy solution ) u should enable cors from the backend side u can read it here

2nd solution in ur front end side ,try to use proxy config in ur angular app by adding proxy.config.json under ur src app the full solution is here

dont forget to rserve ur angular app with npm run start