Last active
March 27, 2020 13:42
-
-
Save bosz/e29f7909cd0b2c4791ed5cd9dfbbcc93 to your computer and use it in GitHub Desktop.
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; | |
/* | |
|-------------------------------------------------------------------------- | |
| API Routes | |
|-------------------------------------------------------------------------- | |
| | |
| Here is where you can register API routes for your application. These | |
| routes are loaded by the RouteServiceProvider within a group which | |
| is assigned the "api" middleware group. Enjoy building your API! | |
| | |
*/ | |
Route::middleware('auth:api')->get('/user', function (Request $request) { | |
return $request->user(); | |
}); | |
// View all classes | |
/*Route::get('/classes', function(){ | |
return response()->json( | |
['maths', 'physics', 'english', 'Chinese'] | |
); | |
})->middleware('api');*/ | |
Route::get('/classes', 'ClassController@allClasses')->middleware('api'); | |
Route::get('/students', 'StudentController@getAllStudents')->middleware('api'); | |
Route::get('/students/{id}', function($id){ | |
return response()->json('You asked for student with id ' . $id); | |
})->middleware('api'); | |
// Refactor | |
/*Route::get('/students/{id}', 'StudentController@getSingleStudent');*/ | |
Route::delete('/students/{id}', function($id){ | |
return response()->json('We are about to delete student with id ' . $id); | |
})->middleware('api'); | |
Route::post('/students/new', function(Request $request){ | |
echo 'User name is ' . $request->input('name'); | |
})->middleware('api'); | |
Route::put('/students/{id}/update', function(Request $request, $id){ | |
})->middleware('api'); | |
// get | post | delete | put | patch | |
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 Illuminate\Http\Request; | |
class ClassController extends Controller | |
{ | |
public function allClasses() { | |
return response()->json( | |
['maths', 'physics', 'english', 'Chinese'] | |
); | |
} | |
} |
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 Illuminate\Http\Request; | |
class StudentController extends Controller | |
{ | |
public function getAllStudents(){ | |
return response()->json( | |
['Goerge', 'Martin', 'yu', 'nandoa', 'nancy', 'Yie'] | |
); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment