Where to put a method? [closed] - php

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 9 years ago.
Improve this question
I've one question.
I'm currently having two classes:
A class called RoomFactory, which builds Room Objects and a class called User.
A User can own Rooms.
Now I wanted to get the Rooms of a User. But where do I put the method?
I could put the method in RoomFactory and call it GetRoomsOfUser($UserObject), I could put the method in the User Object and call it GetRooms() or I could put it in both.
What would be the best practice for this?

It should live on the User object. The job of the RoomFactory is to build Room objects, not to fetch User-related objects.

Related

Relation between one table records [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 5 years ago.
Improve this question
I have a User table.Some Users have a manager which is a user too.
I need one to many relationship between users, but I don't want to create a new table for that.
I can use manager_id to relate users to their manager.
Now my question
Is it a right way to do some thing like that? If no, so what's the best way?
I'm using laravel and sqlite, relation is one to many
In the User table, you can add manager_id. This will create parent to child relationship. It will also support multiple hierarchies where managers can also have managers.
I have used this same model on categories which have sub categories.
This will work

In PHP 7, what's the use of stdClass with the availability of anonymous classes? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 6 years ago.
Improve this question
As of PHP 7 we have access to anonymous classes. This means we could ditch stdClass when we need generic object as a return value... But which one would be cleaner?
What other differences are between those two guys?
Is there any performance drawback on creating an anonymous class? i.e. as each one has a different "class name", is there any additional impact?
Do both work "the same way" from the developer point of view, or are they actually two different beasts in some cases?

What this sentence means? [closed]

Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 years ago.
Improve this question
i have read this sentence in the object oriented paradigm approach.
A class can never have property values or state. Only objects can.
Can anybody elaborate this ?
Think of a class as a definition of a new data type. As such, it cannot have a state - it's just a definition. Consider this analogy - the concept of integer can't have a value, but a specific variable of integer type may have the value of 7.

What is the prefered way of writing methods in Laravel? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
Which one of these styles are prefered when retrieving data to display in a view?
Straight forward laravel with no custom methods in the model:
$guest->bookings->first()->id;
$guest->bookings->first()->bed;
$guest->bookings->first()->date;
or a method to get the latest booking model:
$guest->getLatestBooking()->id;
$guest->getLatestBooking()->bed;
$guest->getLatestBooking()->date;
or seperate methods for each value like this:
$guest->getLatestBookingId();
$guest->getLatestBookingBed();
$guest->getLatestBookingDate();
It depends if you need to attach other queries (like 'where', or 'select'). This doesn't mean that you always have to use the second option, third is excellent too. For the first one, try to avoid it.

How to do a sharing field for mutiple people? [closed]

Closed. This question is opinion-based. It is not currently accepting answers.
Want to improve this question? Update the question so it can be answered with facts and citations by editing this post.
Closed 8 years ago.
Improve this question
Similar to Facebook, I want to do a sharing feature where a user can choose to keep something private or share with 1 or more people. I know how to do a drop down but that limits my ability to be able to do it only for one person. How do i do it so i can allow people to select more than 1 person in a way that its user friendly and not confusing.
I was thinking of using AJAX or if HTML5 had something but i am new to that area so i don't know.
What is the best way to do it?
You could use a <select multiple>, but that's not very user-friendly. I'd use something like this: http://jqueryui.com/demos/autocomplete/#multiple.

Categories