Created
April 21, 2023 23:25
-
-
Save cesjam7/b5add703bf498704d0ca06bb3267f750 to your computer and use it in GitHub Desktop.
Tarea de entregar 5 controladores
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
use Illuminate\Http\Request; | |
use Illuminate\Support\Facades\Route; | |
use App\Http\Controllers\HolaController; | |
use App\Http\Controllers\PersonaController; | |
/* | |
|-------------------------------------------------------------------------- | |
| API Routes | |
|-------------------------------------------------------------------------- | |
| | |
| Here is where you can register API routes for your application. These | |
| routes are loaded by the RouteServiceProvider and all of them will | |
| be assigned to the "api" middleware group. Make something great! | |
| | |
*/ | |
Route::middleware('auth:sanctum')->get('/user', function (Request $request) { | |
return $request->user(); | |
}); | |
Route::get('/hola', function (Request $request) { | |
return 'hola mundo'; | |
}); | |
Route::get('/chau', function () { | |
return 'chau mundo'; | |
}); | |
Route::get('/saludar', | |
[HolaController::class, 'saludar']); | |
Route::get('/persona', | |
[PersonaController::class, 'persona']); | |
Route::get('/paises', | |
[PersonaController::class, 'paises']); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
namespace App\Http\Controllers; | |
use App\Http\Controllers\Controller; | |
use Illuminate\Http\Request; | |
class PersonaController extends Controller | |
{ | |
function persona() { | |
$data = [ | |
'nombre' => 'Juan', | |
'apellido' => 'Perez', | |
"edad" => 30, | |
"talla" => 30, | |
"peso" => 30, | |
'hijos' => [ | |
[ | |
"nombre" => "Juanito", | |
"apellido" => "Perez", | |
], | |
[ | |
"nombre" => "Juanita", | |
"apellido" => "Perez", | |
] | |
], | |
'hermanos' => [ | |
[ | |
"nombre" => "Juanito", | |
"apellido" => "Perez", | |
'hijos' => [ | |
[ | |
"nombre" => "Juanito", | |
"apellido" => "Perez", | |
], | |
[ | |
"nombre" => "Juanita", | |
"apellido" => "Perez", | |
] | |
], | |
], | |
[ | |
"nombre" => "Juanita", | |
"apellido" => "Perez", | |
'hijos' => [ | |
[ | |
"nombre" => "Juanito", | |
"apellido" => "Perez", | |
], | |
[ | |
"nombre" => "Juanita", | |
"apellido" => "Perez", | |
] | |
], | |
], | |
[ | |
"nombre" => "Juanita", | |
"apellido" => "Perez", | |
'hijos' => [ | |
[ | |
"nombre" => "Juanito", | |
"apellido" => "Perez", | |
], | |
[ | |
"nombre" => "Juanita", | |
"apellido" => "Perez", | |
] | |
], | |
] | |
] | |
]; | |
$json = json_encode($data); | |
echo $json; | |
} | |
function paises() { | |
$data = [ | |
[ | |
'nombre' => 'Peru', | |
'moneda' => 'soles' | |
], | |
[ | |
'nombre' => 'Brasil', | |
'moneda' => 'reales' | |
], | |
]; | |
echo json_encode($data); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment