Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 6 years ago.
Improve this question
Ok, I am trying to make a record and send an email notification/acknowledgement that the record has been recorded. I have a many to many relationship between a Players model and a Lessonhours model. The User model has a one to many with the Players model.
I have run my 'store' method with several different modifications and I finally get my email to send. The problem is that I can't get the array of players that exist and send each an email. The multiple selections from my form are being properly inserted in their respective tables. When it comes to collecting the email data, I have come closest with the following code. The problem with THIS is that I only get one player instead of two or more when they exist. I hope this makes sense. Screenshots below.
Code and screenshot of $request array:
Players Model:
I am not very experienced with this and I am finding it difficult to pinpoint which documentation example to use. How can I get all of the emails addresses for sending after the insertion of record? I appreciate all help offered.
Lessonhours Model:
Store Lessonhours form
User Model
I'm not sure why you're putting an array inside an array for whereIn clause but if request players is already coming through as an array then your should just be able to do:
whereIn('id', $request->players)
Next you're only ever going to be sending one email because you're returning from inside the loop so it's going to send the first player one email and then return a response. To save have a temporary variable that you're not using again you could do:
Players::with('users')->whereIn('id', $request->players)->get()
->each(function ($player) use ($lesshours) {
Mail::to($player->users)->send(new ThankYouForLessonPackagePurchase($lesshours));
});
return back()->with(['success' => 'Player is enrolled in new Lesson Package.']);
You don't have to do the above it's just another way to write it.
Lastly, if you're always going to require player ids to be sent then you might as well add it to the validation array:
'players => 'required',
'players.*' => 'exists:players,id',
Hope this helps!
Related
Closed. This question needs debugging details. It is not currently accepting answers.
Edit the question to include desired behavior, a specific problem or error, and the shortest code necessary to reproduce the problem. This will help others answer the question.
Closed 1 year ago.
Improve this question
How can I check if an id it's inside my firebase collection?
I need to check if item.id it's inside the collection "favorites" that contains multiple ids.
I need to assign to a value true if it's inside or false if there is not a value with the same id.
As far as I know, there is no way to "check" if a document exists inside a collection without actually fetching it. When you attempt to get the document, it returns a doc - with a exists variable.
So you can check if a document exists or not like this (using Promises):
const doesDocExist = (docID) => {
return firestore().collection("cities").doc(docID).get().then((doc) => {
return doc.exists
})
}
//Call the function to check if doc exists:
let doesSanFranciscoExist = await doesDocExist("SF")
Note that in the above function, you are attempting to fetch the document with the ID.
Alternatively, if you want to check the existence of multiple documents with just one read, you can maintain a list of document ids elsewhere in your database using Cloud Functions.
Get a document in Firestore
I'm new to Alexa Skills but meanwhile I've read tons of information and tutorials.
Fortunately, I'm currently able to create my own custom skill (based on PHP) on my own server and it already works using different intents, utterances, slots etc..
Now, I want Alexa to read a list of items (I send via JSON) in PlainText but I can't find any information how to do this.
I assume there are two options (please correct me if I'm wrong):
Sending a JSON answer including one item - Alexa reads this item - the user says e.g. "next" - Alexa requests my server for the next item - my server sends the next JSON answer ... and so on.
Sending a JSON answer including all items in an array - Alexa reads each item one after another.
I'm not sure which solution is possible and how it can be solved.
So, can anyone help me on this or point me to some information?
Both ways are possible and which one to choose depends on what you are listing.
Using AMAZON.NextIntent
If a single list item include item name and some details about it, then reading out it in one go won't be a good user experience. In this case you can use AMAZON.NextIntent to handle users "next" request.
When the user asks for the list, give the first item in your response and keep a track of the item index in response sessionAttributes. You can also set a STATE attribute too, so that you can check this state in AMAZON.NextIntent handler before you give the next item.
"sessionAttributes": {
"index": 1,
"STATE": "LIST_ITEMS"
}
When the user say "next"
check whether the state is LIST_ITEMS and based on the index give the next item from your list. And in sessionAttributes increment the index
More on sessionAttributes and Response Parameters here
Now, if your items are just names then you can read it one after the other.
In both these solutions it is always good to use SSML rather than just PlainText. SSML gives you more control on how your response is spoken.
More on SSML here
I am a beginner at web development and using AngularJS so I am begging for any feedback.
I have a list of survey questions and I have a pop up modal where the user can give their response. Over 500 survey questions are pulled from one table and put into an array to display in the view. When the user responds to each question, those responses are put into a separate table. I have over 200 people taking this survey and no one can see the other people's responses. My question is, how can I mark/hide the questions that they have already answered? My beginner's go to solution was to do a for loop and iterate over the first list with the questions and then another for loop to iterate over the responses. If there the question Id was found in the second table, put into a new array where it will indicate that the question was answered. But because there are so many responses and questions, the system crashed. If anyone can help me figure out a solution for this, please let me know. Thank you in advance.
You can use ng-repeat to display questions and in that use ng-if with condition, for example:
<div ng-repeat="q in question" ng-if="!q.answer">
//all the stuff to display question
</div>
I've been trying for the past 2 days, how to embed a view from a different controller.
I have two tables (hotels, hotelQuotes), related to each other. The hotels table is linked with a hasmany to the hotelQuotes table, and hotelQuotes with a belongsTo hotels table. Both are linked and working, they both show their related content with no problem.
The hotelQuotes it's pretty much a form, where users fill it out, and then it sends an Email with what the user filled out. Everything is working fine up to this point.
What I want is, when I show the information about the hotel, is to also show that form, I dont want the user to go to another page to fill out the form. So I pretty much want to embed the view of hotelQuotes/Add to the hotel/view.
I doing that using elements, as recommended last night in #cakephp IRC channel, and also here in StackOverFlow at: Embedding view in another view with CakePHP
The problem is that when I do that, the association between the two models gets broken. I mean, the users fill out the form, but I have nowhere to know where that form is coming from, what hotel is referring to. It just doesn't show that piece of vital information for me.
I've been reading about passing variables when using elements at: http://book.cakephp.org/2.0/en/views.html#passing-variables-into-an-element but I don't know how to pass a variable to a form select box. I am using CakePHP 2.5.2.
I hope I explain myself clear here, any input it would be appreciated. See picture below for more info:
http://i.stack.imgur.com/wcG64.jpg
Edit> I just realized that the form is not even submitting when I using elements. Why would that be?
Ok, I just figured out.
The form wasn't even submitting when calling it from elements. So I just passed the action myself like so:
echo $this->Form->create('Hotelquote', array(
'action' => 'add'
));
And now is working.
I am new in extjs4 .I am using MVC structure.and I am going to save associated data to server side.I am getting stuck at this point.
I have two tables
1)
Question
========
qid
question
2)
Option
========
oid
option
qid
I am going to displayQuestion answer page. There are 10 questions diplays on the page at a time with their 4 options for each question.
I know how to save single instance of model in to database.
var check = Ext.ModelManager.create(
{
question:que,
}, 'Bal.model.sn.QuestionModel');
check.save();
I am getting all the selected questions with there options.but I dont know how to save associated data to database.And how to create instance of particular models to instantiate model with data..
Here is my other model
'Bal.model.sn.optionModel'
How can i solve this issue...
This functionality is not provided out of box. Please take a look at this thread for some implementations of similar functionality: http://www.sencha.com/forum/showthread.php?141957-Saving-objects-that-are-linked-hasMany-relation-with-a-single-Store/page4