PHP code example of robertbaelde / laravel_read_only_fields

1. Go to this page and download the library: Download robertbaelde/laravel_read_only_fields 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/ */

    

robertbaelde / laravel_read_only_fields example snippets

 
use Illuminate\Database\Eloquent\Model;
use Temperworks\ReadOnlyFields\HasReadOnlyFields;

class YourModel extends Model
{
    use HasReadOnlyFields;

    protected array $readOnlyFields = [
        'read_only_field'
    ];
}


$model = YourModel::find(1);
$model->writable(['read_only_field'])->update(['read_only_field' => 'foo']);

// this will throw an exception since we already updated the model. 
$model->update(['read_only_field' => 'foobar']);