<?php namespace Builder\Users;

use Exception;
use Cartalyst\Sentry\Users\Eloquent\User as SentryUser;

class UserModel extends SentryUser {

	protected $table = 'users';

 	public function projects()
    {
        return $this->belongsToMany('Builder\Projects\ProjectModel', 'users_projects', 'user_id', 'project_id');
    }

    /**
     * Allow multiple PCs to be logged in to same account.
     * 
     * @return string
     */
    public function getPersistCode()
    {
        if ( ! $this->persist_code)
        {
            $this->persist_code = $this->getRandomString();

            // Our code got hashed
            $persistCode = $this->persist_code;

            $this->save();

            return $persistCode;            
        } 

        return $this->persist_code;
    }

}