Laravel 4で特定のクエリのフィールドのみを変更するためにアクセサを使用する方法はありますか? それで、「Fanartist.php」というモデルがあります。別のテーブル「アーティスト」には、「説明」フィールドがあります。クエリ関数で結合して呼び出しています。これは機能です:
public static function fan_likes_json() {
$fan_likes = DB::table('fanartists')
->join('artists', 'fanartists.artist_id', '=', 'artists.id')
->where('fanartists.fan_id', '=', Auth::user()->id)
->select('artists.id', 'artists.stage_name', 'artists.city', 'artists.state', 'artists.image_path', 'artists.description')
->get();
}
次のようなものを使用して、この特定のクエリ関数の「説明」文字列を変更しようとしています。
public function getDescriptionAttribute($value) {
return substr($value, 0, 90);
}
これを Fanartist モデルまたは Artist モデルに追加しますか? また、このアクセサをこの特定のクエリ関数の説明フィールドにのみ影響させるにはどうすればよいですか? 他の目的やクエリのために説明を変更しないでください。ご協力ありがとうございました。