PHP code example of sehrgut / eloquent-computed-attributes

1. Go to this page and download the library: Download sehrgut/eloquent-computed-attributes 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/ */

    

sehrgut / eloquent-computed-attributes example snippets




namespace App\Models;

use Illuminate\Database\Eloquent\Model;
use SehrGut\EloquentComputedAttributes\HasComputedAttributes;

class Post extends Model
{
    use HasComputedAttributes;

    /** @inheritDoc */
    protected $fillable = ['title', 'text'];

    /**
     * Recompute the `text_excerpt` attribute when `text` changes.
     *
     * @param  string $text
     * @return string
     */
    public function computeTextExcerptAttribute(string $text): string
    {
        return substr($text, 0, 255) . '…';
    }
}