FAQ Database Discussion Community


How can I use an accessor to create a text field from a binary field?

php,laravel,accessor
In Laravel 5, I have a binary field called 'microchip,' which is a binary field. I would like to build an accessor function which outputs "yes," or "no," if the original field contains a 1 or 0 respectively. I have this: public function getMicrochipTextAttribute($input) { switch($input) { case 0: return...

Java: Accessing resources and the Law Of Demeter

java,android,resources,accessor,law-of-demeter
Overview In my (Android) Java game, I have a class called resources. As the name suggests, this class holds the resources for the game. All of my OpenGL objects (Sprites) are created here It's looks something like the following (obviously, this is a simplified version compared to that which appears...

Symfony2 / Doctrine2 : how to access an entity annotation mapping?

symfony2,doctrine2,annotations,mapping,accessor
In my Symfony2/doctrine2 application, I have two entities, Media and Recipe. They can be linked by a oneToMany or a ManyToMany association. In the case of a oneToMany relationship, I am using the following code to retrieve the Recipe linked to an instance of Media : $accessor = PropertyAccess::createPropertyAccessor(); $reflect...

Laravel 5 Model Accessor Methods not working

php,laravel,eloquent,laravel-5,accessor
I am attempting to write some accessor methods according to my best interpretation of the documentation and they do not seem to be working. I am attempting to decrypt an attribute that I am encrypting when it comes into the database via an API call that fires in a scheduled...

“More functional” “accessor” for collections in C#

c#,collections,setter,getter,accessor
Now I have a collection: Dictionary<string, List<string>> dictionary. For some reason, now I want to "project/map" a part of it to other collections, sort of like using it as backing field, and create different accessors for this collection. Like List<string> keys corresponds to the keys of this dictionary, or Dictionary<string,...

Accessor method for a static final double

java,methods,return,accessor
I have this variable: public static final double PRICE_COST = 100.00; in my accessor method for this, would it look like this? /** * @return the price cost as double */ public double getPRICE_COST(){ return PRICE_COST; } I'm just not sure the way capitalization should work since it's a final,...

Calling an Accessor with a Variable

java,oop,accessor
I'm practicing my Java skills by making some basic exercises for myself to try out, and I'm trying to make a stupid simple 'text based race game', I guess you could say. The only logic is that whichever car is more powerful wins, and the main point I'm trying to...

Laravel lists with relationship for a dropdown

laravel,eloquent,accessor
I have two tables: course id name season_id teacher_id dates_id description ... course_dates id course_id weekday start stop ... In the first table are the basic stuff for the course. In the second table i only store the dates of the course (i.e. weekday 1 for monday, start -> the...

In Swift, is there a better way to initialize a “get” only variable?

ios,swift,accessor
Say I have a class, MyClass, and it can be in either a valid or invalid state. So I keep track of this with a bool called isValid. I want this value initialized to false until the class's initialize function is called. The initialize (and a corresponding reset function) will...

Javascript beyond property accessors

javascript,arrays,json,accessor
I read a lot about JS accessors here and figure out this gonna be good for me: This is what I used for local fields: TYPE_DEFAULT_VALUE= { number: 0, string: "", array: [], object: {}, }; typeOf = function (object) { if (typeof object === "number" && isNaN(object)) return NaN;...

Proper way to set up Date class with validation

c#,class,conventions,accessor,mutators
I have a class as follows: class Date { // Field variables private int day; private int month; private int year; // Default constructor public Date() { year = 2015; day = 0; month = 0; } // Overloaded constructor public Date(int _day, int _month, int _year) { setDay(_day); setMonth(_month);...

Implicit Accessors in JavaScript?

javascript,ecmascript-6,accessor,ecmascript-harmony
In ColdFusion (a server-side language), it's possible to have CF generate any getters and setters in a class for you, like so: component output="false" accessors="true" { property string title; public any function init() output = false { setTitle(""); return this; } } Here, I never write the setTitle() setter, it's...

Laravel 5.0: Form::select() called twice Eloquent Accessor by select name

php,laravel,eloquent,laravel-5,accessor
Blade template: {!! Form::model($category) !!} {!! Form::select('drinks_id', [...full list...]) !!} {!! Form::close() !!} 'drinks_id' called by Eloquent Accessor: public function getDrinksIdAttribute() { var_dump('get'); return 123; } When Form::select('drinks_id') execute, getDrinksIdAttribute() called twice and print string(3) "get" string(3) "get" from var_dump(). If I write this: {!! Form::model($category) !!} {!! var_dump($category->drinks_id) !!}...

Java private modifier confusion [duplicate]

java,accessor,private-members
This question already has an answer here: Private Member Access Java 7 answers I've been writing Java for some years, but I still do not understand why this simple example class below actually passes compilation. In this situation, I would make a getter method for myInt, and use that...

encapsulation, accessor C# vs Java

java,c#,encapsulation,accessor
A quick question about encapsulation and accessor in C# vs Java. Is this code in C# equivalent to the one in Java bellow? //C# class MyClass{ public string var1 {get; private set;} public int var2 {get; private set;} public MyClass(string aString, int anInt){ this.var1= aString; this.var2=anInt; } } java //Java...