1. Go to this page and download the library: Download chhw/form-request library. Choose the download type require.
2. Extract the ZIP file and open the index.php.
3. Add this code to the index.php.
<?php
require_once('vendor/autoload.php');
/* Start to develop here. Best regards https://php-download.com/ */
chhw / form-request example snippets
namespace App\Http\Requests;
use CHHW\FormRequest\FormRequest;
class CreatePost extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*
* @return bool
*/
public function authorize()
{
return true;
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
"title" => "
use App\Http\Requests\CreatePost;
class ExampleController extends Controller
{
public function test(CreatePost $request)
{
dd($request->all());
// ...
}
}
use App\Rules\Uppercase;
use Illuminate\Http\Request;
class ExampleController extends Controller
{
public function create(Request $request)
{
$request->validate(["author" => ["
namespace App\Rules;
use Illuminate\Contracts\Validation\Rule;
class Uppercase implements Rule
{
/**
* Determine if the validation rule passes.
*
* @param string $attribute
* @param mixed $value
* @return bool
*/
public function passes($attribute, $value)
{
return strtoupper($value) === $value;
}
/**
* Get the validation error message.
*
* @return string
*/
public function message()
{
return 'The :attribute must be uppercase.';
}
}