PHP code example of fourfortymedia / eloquent-model-guard

1. Go to this page and download the library: Download fourfortymedia/eloquent-model-guard 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/ */

    

fourfortymedia / eloquent-model-guard example snippets


class User extends Model {
     use \FourFortyMedia\EloquentModelGuard\Concerns\HasEloquentModelGuard;
}

   use Illuminate\Database\Eloquent\Validations\OnCreateRules;

   #[OnCreateRules(['name' => 'ate array $roles = [];
   }
   

   use Illuminate\Database\Eloquent\Validations\OnUpdateRules;

   #[OnUpdateRules(['email' => '

   use Illuminate\Database\Eloquent\Validations\OnUpdateRules;

   #[OnUpdateRules(['email' => 'Model {
       // ...
   }
   

   use Illuminate\Database\Eloquent\Validations\OnUpdateRules;

   #[OnUpdateRules(['email' => 'Model {
       #[OnUpdateRules(['mail')]
       protected string $email;
   }
   

   $product = Product::validateUsing(function ($rules) {
       $rules['price'] = 'numeric|min:0';
       return $rules;
   })->create($data);
   

   protected static function booted()
   {
       static::creating(function (self $model) {
           $model->getModelRules(useOnCreateRules: false);
           $model->getPropertyRules(useOnCreateRules: false);
           $model->validate();
       });
       static::updating(function (self $model) {
           $model->getModelRules();
           $model->getPropertyRules();
           $model->validate();
       });
   }