PHP code example of waavi / model

1. Go to this page and download the library: Download waavi/model library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

waavi / model example snippets


use Waavi\Model\WaaviModel;

class Post extends WaaviModel {

	protected $table = 'posts';

	/**
   * Validation rules
   *
   * @var array
   */
  public $rules = array(
  	'title'	=> 'ribute field is 

	$input = Input::all();
	$success = Post::fill($input)->save();
	if ($success) {
		return Redirect::route('...');
	} else {
		return Redirect::route('...')->withErrors($article->errors());
	}

$rules = array('title'	=> '                           // Returns the model's validation rules.
$model->setRules($rules);                           // Switches the model's validation rules
$model->setRule('slug', '

$messages = array('Messages();                                    // Returns the model's custom messages.
$model->setCustomMessages($messages);                           // Switches the model's custom messages.
$model->setCustomMessage('

class User extends WaaviModel {
	public function posts() {
		return $this->hasMany('Post');
	}
}

class Post extends WaaviModel {
	public function author() {
		return $this->belongsTo('User');
	}
	public function comments() {
		return $this->hasMany('Comment');
	}
	public function tags() {
		return $this->hasMany('Comment');
	}
}

class Tag extends WaaviModel {
	public function posts() {
		return $this->hasMany('Post');
	}
}

class Comment extends WaaviModel {
	public function post() {
		return $this->belongsTo('User');
	}
}

$posts = Post::whereRelated('tags', 'value', '=', 'News')
  ->whereRelated(function($query)
  {
    $query->whereRelated('author', 'name', '=', 'John')
      ->orWhereRelated('author', 'name', '=', 'Jane');
	})
  ->get();

$posts = Post::whereNotRelated('author', 'name', '=', 'John')->get()

$comments = Comment::whereRelated('post.author', 'name', '=', 'John')->get()

WaaviModel::whereRelated($relationshipName, $column, $operator, $value);

WaaviModel::orWhereRelated($relationshipName, $column, $operator, $value);

WaaviModel::whereNotRelated($relationshipName, $column, $operator, $value);

WaaviModel::orWhereNotRelated($relationshipName, $column, $operator, $value);