• Stars
    star
    276
  • Rank 149,319 (Top 3 %)
  • Language
    PHP
  • Created over 11 years ago
  • Updated about 8 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

This Laravel package auto-validates a model on save.

Auto-Validate On Save

This package takes care of the model validation process for you. Rather than manually going through the tedious Validator::make(...) process, just save the model, and this package will handle the rest.

Usage

Install the package through Composer.

{
    "require": {
        "laravel/framework": "4.0.*",
        "way/database": "dev-master"
    }
}

Then, rather than extending Eloquent from your model, extend Way\Database\Model, like so:

<?php

class Dog extends Way\Database\Model {

}

Alternatively, edit app/config/app.php, and add a new item to the aliases array:

'Model' => 'Way\Database\Model'

Now, your models can simply extend Model.

<?php

class Dog extends Model {

}

Validation

This package hooks into Eloquent's save event, and automatically validates the model's current attributes against the rules that you have set for your model.

Here's an example of setting validation rules for the model:

<?php

class Dog extends Model {
    protected static $rules = [
        'name' => 'required'
    ];

    //Use this for custom messages
    protected static $messages = [
        'name.required' => 'My custom message for :attribute required'
    ];
}

Now, simply save the model as you normally would, and let the package worry about the validation. If it fails, then the model's save method will return false.

Here's an example of storing a new dog.

public function store()
{
    $dog = new Dog(Input::all());

    if ($dog->save())
    {
        return Redirect::route('dogs.index');
    }

    return Redirect::back()->withInput()->withErrors($dog->getErrors());
}

If using Eloquent's static create method, you can use the hasErrors() methods to determine if validation errors exist.

$dog = Dog::create(Input::all());

if ($dog->hasErrors()) ...

That's it! Have fun.

More Repositories

1

council

An open source forum built on Laravel.
PHP
619
star
2

Laravel-From-Scratch-Blog-Project

The completed blog demo project from Laravel 8 From Scratch.
PHP
502
star
3

laravel-mix-tailwind

mix.tailwind()
JavaScript
352
star
4

Vagrant-Setup

My Vagrant install script
Shell
253
star
5

Laravel-Test-Helpers

Easier testing in Laravel.
PHP
220
star
6

laravel-elixir-vueify

This is a very thin wrapper for Laravel Elixir and the Browserify Vueify plugin.
JavaScript
158
star
7

laravel-elixir-webpack-official

JavaScript
88
star
8

Build-Modern-Laravel-Apps-With-Inertia

PHP
86
star
9

laravel-elixir-stylus

Elixir Wrapper Around Stylus
JavaScript
77
star
10

laravel-mix-example

JavaScript
55
star
11

PHPUnit-Wrappers

Use Assert and Should in your PHPUnit tests.
PHP
45
star
12

laravel-elixir-vue

Laravel Elixir Vue integration.
JavaScript
40
star
13

MessageBox

Your standard jQuery plugin for fancy message box confirmations, notifications, etc.
JavaScript
39
star
14

Laravel-Testing-Decoded

This project is exclusively for reporting typos and errors in the book, "Laravel Testing Decoded."
35
star
15

laravel-webpacker

More Details Coming Soon.
JavaScript
33
star
16

Laravel-Selenium-Extension

PHP
29
star
17

Laravel-Elixir-Rollup

Official Rollup extension for Laravel Elixir. (Includes support for .vue files).
JavaScript
29
star
18

Laravel-Elixir-v6-Vue-example

JavaScript
25
star
19

laravel-elixir-browsersync-official

Laravel Elixir Browsersync Integration
JavaScript
24
star
20

Laravel-4-Generators

Rapidly speed up your Laravel workflow with generators
PHP
23
star
21

vimfiles

Vim Script
20
star
22

laravel-elixir-codeception

Laravel Elixir wrapper for Codeception
JavaScript
17
star
23

laravel-elixir-browserify

Laravel Elixir Browserify Integration
JavaScript
16
star
24

Wordle-Workshop

Source code for the "Wordle Workshop" Laracasts series.
PHP
15
star
25

Email-Notifications-With-Mailchimp

PHP
12
star
26

Laracasts-Bugs

Exclusively for user-submitted bugs and errors at laracasts.com
9
star
27

Elixir-webpack-non-laravel-example

npm install && gulp
JavaScript
8
star
28

laracasts-window-size-raycast-extension

Raycast extension for Laracasts instructors.
AppleScript
7
star
29

laravel-elixir-coffeescript

Laravel Elixir CoffeeScript Support
JavaScript
6
star
30

jeffreyway.github.com

JavaScript
6
star
31

example

PHP
4
star
32

5-6-issue

PHP
3
star
33

issue

PHP
2
star
34

Codeception-issue

Codeception json_encode issue
PHP
1
star