src/AttachableTrait.php
public function addAttach($filename, $title=null, $alt=null, $desc=null)
    {
        $path='attaches/'.date ('Y-m-d').'/';

        $attach = $this->createAttachesModel()->firstOrNew([
            'filename'      => $filename,
            'namespace' => $this->getEntityClassName(),
            'alt' => $alt,
            'desc' => $desc,
            'title' => $title,
        ]);

        if (! $attach->exists) {
            $info = pathinfo($filename);
            if(! $alt) {
                $cleanName = basename($filename,'.'.$info['extension']);
                $attach->alt = $cleanName;
            }

            $newFileName = md5(date('Y-m-d-s').$filename).'.'.$info['extension'];
            $attach->filename = $path.$newFileName;
                Storage::put(
                $path.$newFileName,
                file_get_contents(public_path($filename))
            );
            $attach->save();
            unlink(public_path($filename));
        }

        if (! $this->attaches->contains($attach->id)) {
            $this->attaches()->attach($attach);
        }
    }
public function addAttach($filename, $title=null, $alt=null, $desc=null)
    {
        $path='attaches/'.date ('Y-m-d').'/';

        $attach = $this->createAttachesModel()->firstOrNew([
            'filename'      => $filename,
            'namespace' => $this->getEntityClassName(),
            'alt' => $alt,
            'desc' => $desc,
            'title' => $title,
        ]);

        if (! $attach->exists) {
            $info = pathinfo($filename);
            if(! $alt) {
                $cleanName = basename($filename,'.'.$info['extension']);
                $attach->alt = $cleanName;
            }

            $newFileName = md5(date('Y-m-d-s').$filename).'.'.$info['extension'];
            $attach->filename = $path.$newFileName;
                Storage::put(
                $path.$newFileName,
                file_get_contents(public_path($filename))
            );
            $attach->save();
            unlink(public_path($filename));
        }

        if (! $this->attaches->contains($attach->id)) {
            $this->attaches()->attach($attach);
        }
    }
{@inheritdoc}