<commit_before><?php namespace Conner\PlusPlus;

trait OwnedTrait {

	/**
	 * Save user_id when new records are created
	 */
	public static function bootOwnedTrait() {
		static::registerModelEvent('creating', function($model){
			if(empty($model->user_id)) {
				$model->user_id = user('id');
			}
		});
	}

	/**
	 * Build query to only find records owned by currently logged in user
	 */
	public function scopeOwned($query) {
		return $query->where('user_id', user('id'));
	}
	
	/**
	 * Is the currently logged in user the owner
	 */
	public function getAmOwnerAttribute() {
		$userId = user('id');
		if(empty($userId)) { return false; }
		
		return $userId == $this->attributes['user_id'];
	}
	
}<commit_msg>[Lazy Commit]<commit_after><?php namespace Conner\PlusPlus;

trait OwnedTrait {

	/**
	 * Save user_id when new records are created
	 */
	public static function bootOwnedTrait() {
		static::registerModelEvent('creating', function($model){
			if(empty($model->user_id)) {
				$model->user_id = user('id');
			}
		});
	}

	/**
	 * Build query to only find records owned by currently logged in user
	 */
	public function scopeOwned($query) {
		return $query->where('user_id', user('id'));
	}
	
	/**
	 * Build query to only find records owned by currently logged in user
	 */
	public function scopeNotOwned($query) {
		return $query->where('user_id', '<>', user('id'));
	}
	
	/**
	 * Is the currently logged in user the owner
	 */
	public function getAmOwnerAttribute() {
		$userId = user('id');
		if(empty($userId)) { return false; }
		
		return $userId == $this->attributes['user_id'];
	}
	
}
{'fraction_non_alphanumeric': 0.156875, 'fraction_numerical': 0.0, 'mean_word_length': 3.822289156626506, 'pattern_counts': {'":': 0, '<': 6, '<?xml version=': 0, '>': 13, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6700213', 'n_tokens_mistral': 553, 'n_tokens_neox': 502, 'n_words': 135}