1. Go to this page and download the library: Download lionix/castable-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/ */
lionix / castable-request example snippets
namespace App\Http\Requests;
use Illuminate\Foundation\Http\FormRequest;
use Lionix\CastableRequest\Contracts\CastableRequestInterface;
class PostsIndexRequest extends FormRequest implements CastableRequestInterface
{
/**
* Get request casts.
*
* @return array
*/
public function casts(): array
{
return [
'created_after' => 'date',
];
}
/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules()
{
return [
'created_after' => 'date',
];
}
}
namespace App\Http\Controllers;
use App\Http\Requests\PostsIndexRequest;
class PostsController extends Controller
{
public function index(PostsIndexRequest $request)
{
$createdAfterDiff = $request->input('created_after')->diffForHumans();
// Example value: 1 month from now
}
}
namespace App\Providers;
use Illuminate\Support\ServiceProvider;
use Lionix\CastableRequest\Contracts\CastsRegistryInterface;
class AppServiceProvider extends ServiceProvider
{
/**
* Bootstrap any application services.
*
* @param \Lionix\CastableRequest\Contracts\CastsRegistryInterface $castRegistry
*
* @return void
*/
public function boot(CastsRegistryInterface $castRegistry)
{
$castRegistry->register('created_after', 'date');
}
}
Loading please wait ...
Before you can download the PHP files, the dependencies should be resolved. This can take some minutes. Please be patient.