PHP code example of lphilippo / laravel-castable-form-request
1. Go to this page and download the library: Download lphilippo/laravel-castable-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/ */
lphilippo / laravel-castable-form-request example snippets
$app->register(LPhilippo\CastableFormRequest\ServiceProvider::class);
/**
* Allow default values through filtering before validation.
*
* @return array
*/
public function prepareForValidation()
{
return $this->replace(
array_merge(
$this->defaults(),
$this->all()
)
);
}
use LPhilippo\CastableFormRequest\Http\Requests\FormRequest;
class ProductRequest extends FormRequest
{
/**
* @inheritdoc
*/
public function defaults()
{
return [
'id' => 1,
];
}
/**
* @inheritdoc
*/
public function rules()
{
return [
'created_at' => '
$request->validated();
$request->sanitised();
/**
* @inheritdoc
*/
public function casts()
{
return [
'products' => 'array',
'products.*' => 'array',
'products.*.id' => 'int',
'products.*.category_id' => 'array',
'products.*.category_id.*' => 'int',
}
/**
* @inheritdoc
*/
public function casts()
{
return [
'products.*.id' => 'int',
'products.*.category_id.*' => 'int',
}
/**
* @inheritdoc
*/
public function casts()
{
return [
'status' => 'pending',
'products.*.status' => 'available',
'provider.country.currency' => 'EUR',
}
/**
* @inheritdoc
*/
public function withValidator($validator)
{
$entityId = $this->route('id');
if ($entityId === 1) {
$validator->addRules([
'key' => '