1. Go to this page and download the library: Download stahiralijan/request-caster 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/ */
stahiralijan / request-caster example snippets
public function store(UserFormRequest $request)
{
...
$first_name = ucfirst($request->first_name); // or ucfirst($request->get('first_name')
$last_name = ucfirst($request->last_name); // or ucfirst($request->get('last_name')
...
$user = User::create([
...
'first_name' => $first_name,
'last_name' => $last_name,
...
]);
...
// after handling model stuff
return redirect(route('users.index'))
->with('message'=>"User ({$user->first_name} {$user->last_name}) created!");
}
...
use Stahiralijan\RequestCaster\Traits\RequestCasterTrait;
...
class UserFormRequest extends FormRequest
{
use RequestCasterTrait;
...
}
class UserFormRequest extends FormRequest
{
use RequestCasterTrait;
protected $toUCFirstWords = ['first_name','last_name'];
// More about this is explained below
protected $joinStrings = ['fullname'=>' |first_name,last_name'];
...
}
public function store(UserFormRequest $request)
{
// first_name and last_name
$user = User::create($request->all());
...
// after handling model stuff
return redirect(route('users.index'))
->with('message'=>"User ({$request->full_name}) created!");
}
public function store(UserFormReques $request)
{
$request->collection()->filter(function($item){
...
});
// or
$request->collection()->map(function($item){
...
});
}
// Convert the defined attributes to Upper-case
$toUpperCaseWords = ['product_code'];
// Upper-case the first letter of the words defined below
$toUCFirstWords = ['display_name'];
// Convert the following attributes into slugs
$toSlugs = ['product_name'];