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






資料來源:

沒有留言:

張貼留言

在LAMP + laravel 12 的虛擬機 ,輸入YT URL,就可下載YT 影片

          請參考 1. Ubuntu 24.04 安裝 laravel 12 的過程記錄 ,完成Ubuntu 24.04 + Apache2 + PHP 8.4 + Mariadb + Laravel 12 的相關設定。          一、 在 Ubuntu 24....