how to create request in laravel code example

Example 1: php artisan make:request

php artisan make:request User\CreateUserRequest

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: laravel add request

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

Example 4: laravel get all request parameters

$request->input('name');
$request->input('user.name'); // fetch from user object

Example 5: laravel request has

if ($request->has('name')) {
    //
}

Example 6: laravel get data from request

dd($request->all());
//print an array of the input name and the input value

Tags: