#Scribe custom rule problem

2 messages · Page 1 of 1 (latest)

sly field
#

Hi i just install the scribe.knuckles.wtf package and i follow the docs and i get this error for mine custom rule

 TypeError 

  App\Rules\ExtendRentReturnDate::__construct(): Argument #1 ($carId) must be of type int, null given, called in C:\laravelAps\rentcar\app\Http\Requests\ExtendRentRequest.php on line 22

  at app\Rules\ExtendRentReturnDate.php:13
      9▕
     10▕ class ExtendRentReturnDate implements ValidationRule
     11▕ {
     12▕     protected int $carId;
  ➜  13▕     public function __construct(int $carId)
     14▕     {
     15▕         $this->carId = $carId;
     16▕     }
     17▕

  1   app\Http\Requests\ExtendRentRequest.php:22
      App\Rules\ExtendRentReturnDate::__construct()

  2   vendor\laravel\framework\src\Illuminate\Container\BoundMethod.php:36
      App\Http\Requests\ExtendRentRequest::rules()

PS C:\laravelAps\rentcar>
``` this is how mine custom rule looks like ```
<?php

namespace App\Rules;

use App\Models\RentedCar;
use Carbon\Carbon;
use Closure;
use Illuminate\Contracts\Validation\ValidationRule;

class ExtendRentReturnDate implements ValidationRule
{
    protected int $carId;
    public function __construct(int $carId)
    {
        $this->carId = $carId;
    }

    public function validate(string $attribute, mixed $value, Closure $fail): void
    {
        $car = RentedCar::with('inStatistics')
            ->where("car_id", $this->carId)
            ->firstOrFail();

        $userReturnDate = Carbon::createFromFormat("Y-m-d", $value);

        if ($userReturnDate->isBefore($car->return_date)){
            $fail("Return date must be after ex return date");
        }
    }
}
#

when i remove the rule mine docs are generated