PHP code example of kanagama / laravel-add-formrequest-accessor

1. Go to this page and download the library: Download kanagama/laravel-add-formrequest-accessor 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/ */

    

kanagama / laravel-add-formrequest-accessor example snippets


namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;
use Kanagama\FormRequestAccessor\FormRequestAccessor;

/**
 * @property-read string $full_name
 */
class BookingRequest extends FormRequest
{
    use FormRequestAccessor;

    /**
     * フルネームを取得
     *
     * @return string
     *
     * @author k.nagama <[email protected]>
     */
    public function getFullNameAttribute(): string
    {
        return $this->input('last_name') .' '. $this->input('first_name');
    }
}

namespace App\Http\Controllers;

use App\Http\Controllers\Controller;
use App\Http\Requests\BookingRequest;

class BookingController extends Controller
{
    /**
     * @param  BookingRequest  $request
     *
     * @author k.nagama <[email protected]>
     */
    public function reserve(BookingRequest $request)
    {
        dd($request->full_name);
    }

protected $guarded = [
    'first_name',
];

protected $fill = [
    'first_name',
];

protected $casts = [
    'id'        => 'int',
    'from_date' => 'string',
    'view_flg'  => 'bool',
];