laravel request code example
Example 1: laravel get input from request
public function store(Request $request)
{
$name = $request->input('name');
}
Example 2: get request uri from request laravel 7
Try to use the following:
\Request::getRequestUri()
Example 3: laravel if request has
if ($request->has('name')) {
}
Example 4: laravel create new request
$myRequest = new \Illuminate\Http\Request();
$myRequest->setMethod('POST');
$myRequest->request->add(['foo' => 'bar']);
dd($request->foo);
Example 5: public function store(Request $request)
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class UserController extends Controller
{
public function store(Request $request)
{
$name = $request->input('name');
}
}
Example 6: laravel 6 make http request
$client = new GuzzleHttp\Client();
$res = $client->get('https://api.github.com/user', ['auth' => ['user', 'pass']]);
echo $res->getStatusCode();
echo $res->getBody();