Skip to content

Commit

Permalink
feat: use route facade in routes
Browse files Browse the repository at this point in the history
  • Loading branch information
albertcht committed Aug 18, 2024
1 parent cf714a9 commit fab26aa
Show file tree
Hide file tree
Showing 5 changed files with 10 additions and 9 deletions.
4 changes: 2 additions & 2 deletions app/Http/Controllers/IndexController.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,11 +11,11 @@
*/
namespace App\Http\Controllers;

use App\Http\Requests\DemoRequest;
use Hyperf\HttpServer\Request;

class IndexController extends AbstractController
{
public function index(DemoRequest $request)
public function index(Request $request)
{
$user = $request->input('user', 'Hyperf');
$method = $request->getMethod();
Expand Down
6 changes: 3 additions & 3 deletions app/Providers/RouteServiceProvider.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,8 @@

namespace App\Providers;

use Hyperf\HttpServer\Router\Router;
use SwooleTW\Hyperf\Foundation\Support\Providers\RouteServiceProvider as BaseServiceProvider;
use SwooleTW\Hyperf\Support\Facades\Route;

class RouteServiceProvider extends BaseServiceProvider
{
Expand All @@ -23,13 +23,13 @@ public function register(): void

protected function registerRoutes(): void
{
Router::group(
Route::group(
'/',
$this->registerRouteFile(base_path('routes/web.php')),
['middleware' => 'web']
);

Router::group(
Route::group(
'/api',
$this->registerRouteFile(base_path('routes/api.php')),
['middleware' => 'api']
Expand Down
1 change: 1 addition & 0 deletions config/app.php
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@
'Log' => SwooleTW\Hyperf\Support\Facades\Log::class,
'Request' => SwooleTW\Hyperf\Support\Facades\Request::class,
'Response' => SwooleTW\Hyperf\Support\Facades\Response::class,
'Route' => SwooleTW\Hyperf\Support\Facades\Route::class,
'Translator' => SwooleTW\Hyperf\Support\Facades\Translator::class,
'Validator' => SwooleTW\Hyperf\Support\Facades\Validator::class,
'JWT' => SwooleTW\Hyperf\Support\Facades\JWT::class,
Expand Down
4 changes: 2 additions & 2 deletions routes/api.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
declare(strict_types=1);

use App\Http\Controllers\IndexController;
use Hyperf\HttpServer\Router\Router;
use SwooleTW\Hyperf\Support\Facades\Route;

Router::any('/', [IndexController::class, 'index']);
Route::any('/', [IndexController::class, 'index']);
4 changes: 2 additions & 2 deletions routes/web.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

declare(strict_types=1);

use Hyperf\HttpServer\Router\Router;
use SwooleTW\Hyperf\Support\Facades\Route;

Router::get('/', function () {
Route::get('/', function () {
return view('welcome');
});

0 comments on commit fab26aa

Please sign in to comment.