PHP code example of colorgreen / laravel-model-generator
1. Go to this page and download the library: Download colorgreen/laravel-model-generator 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/ */
colorgreen / laravel-model-generator example snippets
$model = new Model();
$model->email = "xxx";
if( !$model->save() )
print_r( $model->getErrors() );
// if validation will fail, e.g. output:
// {"id":["The id field is
public function store(Request $request)
{
$model = new Model();
$model->fill($request->all());
$model->getValidator()->validate();
$model->save();
return response()->json( [ 'message' => __('Success'), 'redirect' => route('model.edit', [$model] ) ] );
}
namespace App\Models\Base;
use Colorgreen\Generator\Models\BaseModel;
/**
* Class BasePage
* @property int id
* @property string image
* @property boolean active
* @property int count
* @property string email
* @property int related_model_id
* @property \App\Models\RelatedModel related_model
*/
class BasePage extends BaseModel
{
protected $attributes = [
'email' => 'default_email',
'active' => 1,
'count' => 0
];
protected static $rules = [
'id' => '}
protected $table = 'pages';
protected $fillable = ['image', 'active', 'count', 'email'];
protected $hidden = [];
protected $casts = [ 'active' => 'boolean', 'count' => 'integer', 'related_model_id' => 'integer' ];
protected $dates = ['created_at', 'updated_at'];
// set in to 'false' if model shouldn't be validated during save.
// you can turn off validation on specific model using $model->setValidation(false)
protected $validation = true;
}