獲取 HTTP 請求的例項
要獲取 HTTP 請求的例項,類 Illuminate\Http\Request
需要在建構函式或控制器的方法中鍵入提示。
示例程式碼:
<?php
namespace App\Http\Controllers;
/* Here how we illuminate the request class in controller */
use Illuminate\Http\Request;
use Illuminate\Routing\Controller;
class PostController extends Controller
{
/**
* Store a new post.
*
* @param Request $request
* @return Response
*/
public function store(Request $request)
{
$name = $request->input('post_title');
/*
* so typecasting Request class in our method like above avails the
* HTTP GET/POST/PUT etc method params in the controller to use and
* manipulate
*/
}
}