Requests
Getting input
The primary way of getting input would be from injecting the Illuminate\Http\Request
into your controller, after that there are numerous ways of accessing the data, 4 of which are in the example below.
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class UserController extends Controller
{
public function store(Request $request)
{
// Returns the username value
$name = $request->input('username');
// Returns the username value
$name = $request->username;
// Returns the username value
$name = request('username');
// Returns the username value again
$name = request()->username;
}
}
When using the input
function it is also possible to add a default value for when the request input is not available
$name = $request->input('username', 'John Doe');