2025年5月30日 星期五

laravel 12 route 路由

路由是應用程序的入口點,用於定義客戶端請求特定URI 時的響應邏輯。路由將URL 映射到對應的處理代碼,通常包含HTTP 方法、URI 和動作(閉包或控制器方法)。

測試指令:
php artisan serve

檔名:routes/web.php
內容:
Route::get('/',function(){
    return "Hello! World";
});
Route::get('about',function(){
    return "about us";
});

Route::prefix('details')->group(function(){
    Route::get('students',function(){
        return "this is student";
    })->name('student-Details');
    Route::get('teachers',function(){
        return "this is teacher";
    })->name('teacher-Details');
});

Route::get('student/{id}/{reg}',function($id,$reg){
    return 'student number '.$id. ' registration number '.$reg;
});

Route::fallback(function(){
    return "This page is no found please try again";
});

顯示所有可用路由指令:
php artisan route:list


此時,在瀏覽器網址列輸入http://127.0.0.1:8000/up






資料來源:

沒有留言:

張貼留言

Laravel 12 Model 資料庫中的資料表,並提供與資料庫互動的介面

相關系列文章: 1. 在 windows 10 安裝 laravel 12 studentManagement環境與設定 2. laravel 12 route 路由 3. laravel 12 Blade Templates 網頁模版 4. laravel 12 Control...