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'); //default METHOD
$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
{
    /**
     * Store a new user.
     *
     * @param  Request  $request
     * @return Response
     */
    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(); // 200
echo $res->getBody(); // { "type": "User", ....