What is the prefered way of writing methods in Laravel? [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 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.

Related

How can I search for a specific word inside all my blade views in Laravel 5.5 or else [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 5 years ago.
Improve this question
I want to know how can I show pages that contain a specific word written by random user in input text, because some contents are static.
P.S : If what I'm talking about is deprecated, can you propose to me a best solution for doing such functionality?
The best option is to keep your data in database. It will allow you to search and display content dynamically. Also in case you have some static pages, you can put them in database just for searching purposes if it's solution in your case.

Passing a variable through href - is it a good approach? [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'm currently working on my school project and I started wondering if it's a good approach to pass some variable through href so it can been seen in the URL.
Is it good or a bad way and why?
Or are there any better ways?
If it's not information that should be private I don't see why you couldn't do it. Especially if you need to reference something on a new page, it would make things easier.
It is good practice to use GET parameters for navigation purposes.
For user data input you can better use forms with POST.

Require email registered to be from specific domain(s) [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
All,
I'm curious what the best approach to this would be. In case the tags weren't noticed, I'm using PHP and Laravel 4.
My application requires that users register with an email address that is from specific domain names. Currently there is only one domain, however, I can see it being a requirement to white list others.
I would assume it would be best to put the domains into an array. Would I run a regex from $rules array against that array? I'm somewhat green to regex. I don't use it often enough to commit anything advanced to memory so feel free to talk to me like a 2 year old.
You can create a custom validator for this. See http://laravel.com/docs/validation#custom-validation-rules for reference.

Where to put a method? [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 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.

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