Skip to content

Commit

Permalink
feat: add form request validation
Browse files Browse the repository at this point in the history
  • Loading branch information
dewanakl committed Feb 10, 2024
1 parent a99b7bf commit 697c634
Show file tree
Hide file tree
Showing 2 changed files with 50 additions and 0 deletions.
12 changes: 12 additions & 0 deletions src/Core/Model/Query.php
Original file line number Diff line number Diff line change
Expand Up @@ -339,6 +339,18 @@ public function dd(): void
);
}

public function getQuery(): string
{
$this->checkQuery();

$replace = $this->query;

foreach ($this->param as $key => $value) {
$replace = str_replace(':' . $key, $value, $replace);
}
return $replace;
}

/**
* Set fillable.
*
Expand Down
38 changes: 38 additions & 0 deletions src/Core/Valid/Form.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
<?php

namespace Core\Valid;

use Core\Http\Request;

abstract class Form extends Request
{
/**
* Validate request.
*
* @return Validator
*/
public function validated(): Validator
{
return Validator::make($this->all(), $this->authorize() ? $this->rules() : []);
}

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

/**
* Get the validation rules that apply to the request.
*
* @return array
*/
public function rules(): array
{
return [];
}
}

0 comments on commit 697c634

Please sign in to comment.