php artisan make:controller UserController
生成User控制器
<?php
namespace App\Http\Controllers;//命名空间
use Illuminate\Http\Request;//请求类
class UserController extends Controller
{
//
public function Test()//方法
{
return 666;
}
}
<?php
use Illuminate\Support\Facades\Route;
use App\Http\Controllers\UserController;//路由文件里面引入控制器,不然无法实现哦
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/
Route::get('/', function () {
return view('welcome');
});
Route::get('Controller',[UserController::class,'Test']);
//意思就是在浏览器上面写Controller代表userController控制器的Test方法
routes/web.php路由那块:要操作的是哪一个控制器得引入use哦.