Laravel如何创建一个控制器并配置路由呢?
控制器创建
1 |
php artisan make:controller ProductController |
并填入下面方法:
app\Http\Controllers\ProductController.php
1 2 3 4 5 6 7 8 9 10 11 12 |
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; class ProductController extends Controller { public function index($name){ return $name; } } |
添加路由
routes\api.php
1 |
Route::get('/product/{name}', "ProductController@index"); |
因为写在了api.php中所以访问浏览器要加上api路径