62 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
			
		
		
	
	
			62 lines
		
	
	
		
			1.3 KiB
		
	
	
	
		
			PHP
		
	
	
	
	
	
<?php
 | 
						|
 | 
						|
namespace App;
 | 
						|
 | 
						|
use Illuminate\Contracts\Auth\MustVerifyEmail;
 | 
						|
use Illuminate\Foundation\Auth\User as Authenticatable;
 | 
						|
use Illuminate\Notifications\Notifiable;
 | 
						|
 | 
						|
class User extends Authenticatable
 | 
						|
{
 | 
						|
    use Notifiable;
 | 
						|
 | 
						|
    /**
 | 
						|
     * The attributes that are mass assignable.
 | 
						|
     *
 | 
						|
     * @var array
 | 
						|
     */
 | 
						|
    protected $fillable = [
 | 
						|
        'name', 'email', 'password',
 | 
						|
    ];
 | 
						|
 | 
						|
    /**
 | 
						|
     * The attributes that should be hidden for arrays.
 | 
						|
     *
 | 
						|
     * @var array
 | 
						|
     */
 | 
						|
    protected $hidden = [
 | 
						|
        'password', 'remember_token',
 | 
						|
    ];
 | 
						|
 | 
						|
    /**
 | 
						|
     * The attributes that should be cast to native types.
 | 
						|
     *
 | 
						|
     * @var array
 | 
						|
     */
 | 
						|
    protected $casts = [
 | 
						|
        'email_verified_at' => 'datetime',
 | 
						|
    ];
 | 
						|
 | 
						|
    public function getFolder()
 | 
						|
    {
 | 
						|
        $arrayHash = str_split(strtolower(md5($this->id)));
 | 
						|
        return sprintf('%s/%s', $arrayHash[0], $arrayHash[1]);
 | 
						|
    }
 | 
						|
 | 
						|
    public function getImageData(Post $post)
 | 
						|
    {
 | 
						|
        if (empty($post->image)) {
 | 
						|
            return '';
 | 
						|
        }
 | 
						|
 | 
						|
        $path = sprintf('%s/%s/%s', storage_path('app'), $this->getFolder(), $post->image);
 | 
						|
 | 
						|
        if (!is_readable($path)) {
 | 
						|
            return '';
 | 
						|
        }
 | 
						|
        $type = pathinfo($path, PATHINFO_EXTENSION);
 | 
						|
        $data = file_get_contents($path);
 | 
						|
        return sprintf('data:image/%s;base64,%s', $type, base64_encode($data));
 | 
						|
    }
 | 
						|
}
 |