Route::get('test/test2','App\Http\Controllers\Test2Controller');// http://laravel8/test/test2// single action controller 参数接收 对于请求参数的接收来说,在控制器中和在路由的回调函数中接收参数没有什么区别。都可以通过依赖注入的方式获取到指定的参数。 代码语言:javascript 代码运行次数:0 运行 AI代...
Route::get('test/test2','App\Http\Controllers\Test2Controller'); // http://laravel8/test/test2 // single action controller 1. 2. 3. 参数接收 对于请求参数的接收来说,在控制器中和在路由的回调函数中接收参数没有什么区别。都可以通过依赖注入的方式获取到指定的参数。 // 控制器 publicfunctiontest2...
If a controller action is particularly complex, you might find it convenient to dedicate an entire controller class to that single action. To accomplish this, you may define a single __invoke method within the controller:1<?php 2 3namespace App\Http\Controllers; 4 5use App\Models\User;...
If you would like to define a controller that only handles a single action, you may place a single __invoke method on the controller:1<?php 2 3namespace App\Http\Controllers; 4 5use App\User; 6use App\Http\Controllers\Controller; 7 8class ShowProfile extends Controller 9{ 10 /*...
When registering routes for single action controllers, you do not need to specify a method:1Route::get('user/{id}', 'ShowProfile');You may generate an invokable controller by using the --invokable option of the make:controller Artisan command:1php artisan make:controller ShowProfile --...
If a controller action is particularly complex, you might find it convenient to dedicate an entire controller class to that single action. To accomplish this, you may define a single __invoke method within the controller:1<?php 2 3namespace App\Http\Controllers; 4 5class ProvisionServer ...
When registering routes for single action controllers, you do not need to specify a controller method. Instead, you may simply pass the name of the controller to the router:1use App\Http\Controllers\ProvisionServer; 2 3Route::post('/server', ProvisionServer::class);You may generate an ...
1Route::get('foo','Photos\AdminController@method'); Single Action Controllers If you would like to define a controller that only handles a single action, you may place a single__invokemethod on the controller: 1<?php 2 3namespaceApp\Http\Controllers; ...
Once the class has been defined, we can type-hint it on our controller action:1public function register(RegisterRequest $request) 2{ 3 var_dump($request->input()); 4}When the Laravel service container identifies that the class it is injecting is a FormRequest instance, the request will ...
Now we can register a resourceful route to the controller: 代码语言:javascript 代码运行次数:0 运行 AI代码解释 Route::resource('photo', 'PhotoController'); This single route declaration creates multiple routes to handle a variety of RESTful actions on the photo resource. Likewise, the generated...