Skip to content

Commit

Permalink
reproduce bug from issue #50083
Browse files Browse the repository at this point in the history
  • Loading branch information
lakkes-ra committed Feb 14, 2024
1 parent 9d9bd59 commit 1c8fe06
Show file tree
Hide file tree
Showing 4 changed files with 83 additions and 1 deletion.
14 changes: 14 additions & 0 deletions app/Http/Controllers/AvailabilityController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
<?php

namespace App\Http\Controllers;

use App\Http\Requests\AvailabilityRequest;
use Illuminate\Http\Request;

class AvailabilityController extends Controller
{
public function store(AvailabilityRequest $request)
{
dd($request->all());
}
}
36 changes: 36 additions & 0 deletions app/Http/Requests/AvailabilityRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?php

namespace App\Http\Requests;

use Illuminate\Foundation\Http\FormRequest;

class AvailabilityRequest extends FormRequest
{
/**
* Determine if the user is authorized to make this request.
*/
public function authorize(): bool
{
return true;
}

/**
* Get the validation rules that apply to the request.
*
* @return array<string, \Illuminate\Contracts\Validation\ValidationRule|array<mixed>|string>
*/
public function rules(): array
{
$dateRange = explode(' - ', $this->date_range);

$this->merge([
'start_date' => $dateRange[0],
'end_date' => $dateRange[1],
]);

return [
'start_date' => ['required', 'date'],
'end_date' => ['required', 'date', 'after_or_equal:start_date'],
];
}
}
31 changes: 30 additions & 1 deletion resources/views/welcome.blade.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,36 @@

<title>Laravel Bug Report #50083</title>
</head>
<body class="antialiased">
<body style="font-family: sans-serif">
<h1>Bug Report Laravel Issue #50083</h1>

<h2>Explanation</h2>
<p>
On Submit, you should get a dump from the Availibility controller. But with the current laravel version, you only get a redirect and validation errors.
When adding <code style="background-color: black; color: white;">$rules = method_exists($this, 'rules') ? $this->container->call([$this, 'rules']) : [];</code> back to laravel/framework/src/Illuminate/Foundation/Http/FormRequest.php Line 118 it works as expected.
</p>

<form method="POST" action="{{ route('availability.store') }}">
@csrf
<input
required
type="text"
id="date-range"
name="date_range"
value="01.03.2024 - 08.03.2024"
placeholder="Pick date range"
>

<button type="submit">Submit</button>
</form>

<h2>Errors</h2>
<ul>
@foreach ($errors->all() as $error)
<li>{{ $error }}</li>
@endforeach
</ul>


</body>
</html>
3 changes: 3 additions & 0 deletions routes/web.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php

use App\Http\Controllers\AvailabilityController;
use Illuminate\Support\Facades\Route;

/*
Expand All @@ -16,3 +17,5 @@
Route::get('/', function () {
return view('welcome');
});

Route::post('availability', [AvailabilityController::class, 'store'])->name('availability.store');

0 comments on commit 1c8fe06

Please sign in to comment.