'Taylor']);
define('WEB_URL','/');
Route::get(WEB_URL, function () { # Route::view('/', 'welcome');
return view('welcome');
});
// Route::any('/', function () { # this router rule is higher than ::get('/')
// echo'Handling all HTTP methods at "/"';
// });
Route::get('/test', function () { # this router rule is higher than ::get('/{var}')
echo 'xxxx';
});
Route::get(WEB_URL.'hello', 'HelloController@index');
Route::get(WEB_URL.'service', 'ServiceController@index');
Route::post(WEB_URL.'service', 'ServiceController@store');
Route::get(WEB_URL.'about', 'HelloController@about');
#Route::view('/about', 'about'); # if no php variables
#Route::view('/service', 'service'); # if no php variables
Route::get('/customers', 'CustomerController@index');
// Route::get('/{var}', function ($name) {
// echo '{var} -> '.$name;
// });
/* first second are `class`
Route::middleware(['first', 'second'])->group(function () {
Route::get('use_middleware', function () {
echo 'use_middleware';
});
Route::get('use_middleware2', function () {
echo 'use_middleware2';
});
});
*/
// Route::namespace('Admin')->group(function () {
// // Controllers Within The "App\Http\Controllers\Admin" Namespace
// });
Route::name(PROFILE_ROUTE_NAME)->get('user/profile', function () {
echo'user profile here:';
echo route(PROFILE_ROUTE_NAME);
echo '
';
echo route(ADMIN_USERS_ROUTE_NAME);
});
Route::name(ADMIN_ROUTE_NAME_PREFIX)->group(function () {
Route::get('users', function () {
// Route assigned name "admin.users"...
echo 'Route assigned name "admin.users"...';
echo '
';
echo route('admin.users');
})->name(USER_LIST_ROUTE_NAME);
});
function ajax_json_response($code, $msg, $data){
return ["code"=>$code, "msg"=>$msg, "data"=>$data];
}
Route::fallback(function () {
return ajax_json_response(0, '', ['404 page here.',1,2, ["a"=>"a1", "b"=>"b2"]]);
#return response(['404 page here.',1,2, ["a"=>"a1", "b"=>"b2"]], 200)->header('Content-Type', 'text/plain');
});
Route::get('/jsonptest', function (Request $request) {
return response()
->json(['name' => 'Abigail', 'state' => 'CA'])
->withCallback($request->input('callback'));
});
// ======= useful official document part ==========
# Route::get('/user', 'UserController@index');
/*
#Implicit Binding
Route::get('api/users/{user}', function (App\User $user) {
return $user->email;
});
*/
// Route::get($uri, $callback);
// Route::post($uri, $callback);
// Route::put($uri, $callback);
// Route::patch($uri, $callback);
// Route::delete($uri, $callback);
// Route::options($uri, $callback);
// Route::match(['get', 'post'], '/', function () {
// //
// });
// Route::redirect('/here', '/there', 301);
// Route::permanentRedirect('/here', '/there');
/*
Route::get('user/{id}', function ($id) {
return 'User '.$id;
});
Route::get('posts/{post}/comments/{comment}', function ($postId, $commentId) {
//
});
*/
/*
Route::get('user/{name?}', function ($name = null) {
return $name;
});
Route::get('user/{name?}', function ($name = 'John') {
return $name;
});
*/
/*
Route::get('user/{name}', function ($name) {
//
})->where('name', '[A-Za-z]+');
Route::get('user/{id}', function ($id) {
//
})->where('id', '[0-9]+');
Route::get('user/{id}/{name}', function ($id, $name) {
//
})->where(['id' => '[0-9]+', 'name' => '[a-z]+']);
*/
/*
// Generating URLs...
$url = route('profile');
// Generating Redirects...
return redirect()->route('profile');
$url = route('profile', ['id' => 1]);
*/