Desarrollo de una API Rest Básica con el Framework Laravel generando una salida de datos en formado JSON
El objetivo de ésta lección es generar JSON a partir de una base de datos; para lograr ello debemos realizar los siguientes pasos:
INSTALACIÓN DE LARAVEL
CREACIÓN Y CONFIGURACIÓN BASE DE DATOS
MODELOS y MIGRACIONES EN LARAVEL
Modelo Noticias
protected $table = "noticias";
protected $fillable = [
'titulo',
'descripcion',
'urlfoto',
'visitas',
];
Migración Noticias
Schema::create('noticias', function (Blueprint $table) {
$table->increments('id');
$table->string('titulo')->unique();
$table->text('descripcion');
$table->string('urlfoto')->default("foto.jpg");
$table->integer('visitas');
$table->timestamps();
});
Modelo Equipos:
protected $table = "equipos";
public $timestamps = false;
protected $fillable =[
'nombre',
'descripcion',
'urlfoto',
'visitas',
'votos',
'pj',
'pg',
'pe',
'pp',
'gf',
'gc',
'gd',
'pts',
'grupo'
];
Migración Equipos:
Schema::create('equipos', function (Blueprint $table) {
$table->increments('id');
$table->string('nombre')->unique();
$table->text('descripcion')->nullable();
$table->string('urlfoto')->default("foto.jpg");
$table->integer('votos')->default(1);
$table->integer('pj')->nullable();
$table->integer('pg')->nullable();
$table->integer('pe')->nullable();
$table->integer('pp')->nullable();
$table->integer('gf')->nullable();
$table->integer('gc')->nullable();
$table->integer('pts')->nullable();
$table->integer('gd')->nullable();
$table->string('grupo')->nullable();
});
Modelo Calendarios
protected $table = "calendarios";
protected $fillable =[
'fecha',
'mes',
'dia',
'hora',
'equipo_a',
'urllogo_a',
'equipo_b',
'urllogo_b',
'descripcion',
'orden'];
Migración Calendarios
Schema::create('calendarios', function (Blueprint $table) {
$table->increments('id');
$table->string('fecha');
$table->string('mes');
$table->string('dia');
$table->string('hora');
$table->string('equipo_a');
$table->string('urllogo_a');
$table->string('equipo_b');
$table->string('urllogo_b');
$table->string('descripcion');
$table->integer('orden');
});
3648 visitas
© Todos los derechos reservados Codea App | Cursos de programación | 2020 - 2022