oktatas:web:back-end_framework:leaf:utvalasztas
Tartalomjegyzék
Leaf útválasztás
- Szerző: Sallai András
- Copyright © 2024, Sallai András
- Licenc: CC BY-SA 4.0
- Web: https://szit.hu
Első útvonal
- app/routes/_app.php
//... app()->get('/', function () { response()->json(['msg' => 'műkszik']); });
HTTP kliensbe:
- localhost:5500
- app/routes/_app.php
app()->get('/msg', function() { response()->json(['msg' => 'üdv']); });
HTTP kliensbe:
- localhost:5500/msg
Tesztelés HTTPie klienssel:
http localhost:5500/msg
POST metódus
- app/routes/_app.php
app()->post('/msg', function() { response()->json(['msg' => 'üdv']); });
Tesztelés HTTPie klienssel:
http post localhost:5500/msg
- app/routes/_app.php
app()->post('employees', function() { $name = request()->get('name'); response()->json(['name' => $name]); });
Tesztelés HTTPie klienssel:
http post localhost:5500/employees name="Béla"
A PUT metódus
- app/routes/_app.php
app()->put('employees/{id}', function() { $name = request()->get('name'); response()->json(['name' => $name]); });
Tesztelés HTTPie klienssel:
http put localhost:5500/employees/23 name="Béla"
A DELETE metódus
- app/routes/_app.php
app()->delete('employees/{id}', function($id) { response()->json(['for_delete' => $id]); });
Tesztelés HTTPie klienssel:
http delete localhost:5500/employees/23
Erőforrásútvonalak
app()->resource('/employees', 'EmployeeController'); app()->run();
Olyan mintha ezt írtam volna:
app()->match('GET|HEAD', '/employees', "$controller@index"); app()->post('/employees', "$controller@store"); app()->match('GET|HEAD', '/employees/create', "$controller@create"); app()->match('POST|DELETE', '/employees/{id}/delete', "$controller@destroy"); app()->match('POST|PUT|PATCH', '/employees/{id}/edit', "$controller@update"); app()->match('GET|HEAD', '/employees/{id}/edit', "$controller@edit"); app()->match('GET|HEAD', '/employees/{id}', "$controller@show"); app()->run();
Dokumentáció:
oktatas/web/back-end_framework/leaf/utvalasztas.txt · Utolsó módosítás: 2024/03/18 11:32 szerkesztette: admin