1. Go to this page and download the library: Download ponich/eloquent-traits 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/ */
ponich / eloquent-traits example snippets
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Post extends Model
{
use \Ponich\Eloquent\Traits\VirtualAttribute;
protected $table = 'posts';
protected $guarded = ['id'];
public $virtalAttributes = ['tags', 'og_tags'];
}
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Post extends Model
{
use \Ponich\Eloquent\Traits\HasAttachment;
protected $table = 'posts';
protected $guarded = ['id'];
}
$post = Post::findOrFail(1);
// by path
$post->attach('/path/to/file');
// by request
$post->attach(
$request->file('photo')
);