Eloquent 커스텀 속성 붙이기

Jmnote bot (토론 | 기여)님의 2020년 11월 2일 (월) 02:58 판 (봇: 자동으로 텍스트 교체 (-</source> +</syntaxhighlight>, -<source +<syntaxhighlight ))
(차이) ← 이전 판 | 최신판 (차이) | 다음 판 → (차이)

1 개요[ | ]

Eloquent 커스텀 속성 붙이기 $appends
방법
	protected $appends = ['속성명'];
	public function get속성명Attribute() {
		return 속성값;  
	}
예시
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;

class FirewallRule extends Model
{
	protected $appends = ['expired'];
	public function getExpiredAttribute() {
		return $this->end_date < date('Y-m-d');  
	}
}

2 같이 보기[ | ]

3 참고[ | ]

문서 댓글 ({{ doc_comments.length }})
{{ comment.name }} {{ comment.created | snstime }}