how to update a table in a mysql database with Angular and Laravel

0

I am developing an application with Laravel and angular, I am bringing the data with Laravel and I show them with Angular.

Controller in laravel:

public function ListadoDimensiones(){
    $dimensiones = Dimension::with(['categorias' => function($q){
        $q->with(['propiedades'=>function($r){
            $r->with(['variables'=>function($s){
                $s->with('intervalostec');
            }]);
        }]);
    }])->get();
    return $dimensiones;
}

This is how I bring the data with javascript:

    var app = angular.module('myApp', []);
app.controller('dimensionesCtrl', function($scope, $http) {
  $scope.variables = [];
  $http.get("/listadoDimensiones")
  .then(function(response) {
      $scope.dimensiones = response.data;
  });

All the above is the way to bring the data with laravel and angular, I would like to know how I could create a function either in the laravel driver or in javascript to Angular to update the data displayed in the database.

Thanks for your time.

    
asked by Talked 25.04.2018 в 00:36
source

1 answer

0

When you want to create the communication between Laravel and Angular it is necessary to add an access middleware and place it inside the kernel

namespace App\Http\Middleware;

use Closure;

class addHeadersCors
{
    /**
     * Handle an incoming request.
     *
     * @param  \Illuminate\Http\Request  $request
     * @param  \Closure  $next
     * @return mixed
     */
    public function handle($request, Closure $next)
    {
        return $next($request)
            ->header('Access-Control-Allow-Origin', '*')
            ->header('Access-Control-Allow-Methods', 'GET, POST, PATCH, PUT, DELETE, OPTIONS')
            ->header('Access-Control-Allow-Headers', 'Origin, Content-Type, X-Auth-Token, Authorization, X-Requested-With');
    }
}

inside the Kernel

protected $middleware = [
        ...
        \App\Http\Middleware\addHeadersCors::class,
    ];

and in the Angular service in this way

configUrl = 'http://localhost:8000/api/';

constructor(private http: HttpClient) {

  }

this.http.get(this.configUrl + 'listadoDimensiones/[id]').subscribe(data => {
      console.log(data);
    });
    
answered by 12.10.2018 в 00:24