request method in laravel code example

Example 1: laravel create new request

$myRequest = new \Illuminate\Http\Request();
$myRequest->setMethod('POST'); //default METHOD
$myRequest->request->add(['foo' => 'bar']);
dd($request->foo);

Example 2: 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 3: check method in laravel

if ($request->isMethod('post')) {
        return ['user' => $user];
    }

Example 4: laravel add request

$request->all() + ['index' => 'value'];