-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor!: observer should imply implementation of validationRules() …
…method ValidateModel observer now requires observed models to implement the SelfValidatingModel interface. BREAKING CHANGE: models without validationRules() method will cause fatal error. Resolves #14
- Loading branch information
1 parent
8bcf168
commit 1bfc5f2
Showing
6 changed files
with
72 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,36 +15,36 @@ | |
// You should have received a copy of the GNU General Public License along with | ||
// package spoorsny/laravel-model-validating-observer. If not, see <https://www.gnu.org/licenses/>. | ||
|
||
use Illuminate\Database\Migrations\Migration; | ||
use Illuminate\Database\Schema\Blueprint; | ||
use Illuminate\Support\Facades\Schema; | ||
namespace Spoorsny\Laravel\Contracts; | ||
|
||
/** | ||
* Create database table used during testing. | ||
* Specifies the methods that an \Illuminate\Database\Eloquent\Model subclass | ||
* must implement in order to be validated by the | ||
* \Spoorsny\Laravel\Observers\ValidateModel observer. | ||
* | ||
* @author Geoffrey Bernardo van Wyk <[email protected]> | ||
* @copyright 2024 Geoffrey Bernardo van Wyk {@link https://geoffreyvanwyk.dev} | ||
* @license {@link http://www.gnu.org/copyleft/gpl.html} GNU GPL v3 or later | ||
*/ | ||
return new class () extends Migration { | ||
interface SelfValidatingModel | ||
{ | ||
/** | ||
* Run the migrations. | ||
* Rules for validating the model's attributes. | ||
* | ||
* An example of an array that must be return by this method: | ||
* | ||
* [ | ||
* 'rules' => [ | ||
* 'make' => 'required|string', | ||
* 'model' => 'required|string', | ||
* ], | ||
* 'messages' => [ | ||
* 'make.required' => 'We need to know the make of the car.', | ||
* ], | ||
* ] | ||
* | ||
* @see {@link https://laravel.com/docs/11.x/validation#available-validation-rules} | ||
* @return array<string,array<string,mixed>> | ||
*/ | ||
public function up(): void | ||
{ | ||
Schema::create('without_validation_rules', function (Blueprint $table) { | ||
$table->id(); | ||
$table->string('make'); | ||
$table->string('model'); | ||
$table->timestamps(); | ||
}); | ||
} | ||
|
||
/** | ||
* Reverse the migrations. | ||
*/ | ||
public function down(): void | ||
{ | ||
Schema::dropIfExists('without_validation_rules'); | ||
} | ||
}; | ||
public static function validationRules(): array; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters