How to send mail multiple selected users - html

I have a meetings table where I am storing meeting information and where I can select a meeting between 2 types of user visitor type user and host type user. I have a many to many relationships between users and meeting that's why I have a pivot table meeting_user. I need to send mail all of the selected users for one meeting.
I am trying to send email using this but it's storing the meeting_id into notifiable_id column of db. so how can I store users_id in the notifiable_id column of db.
$meetings->save();
$meetings->users()->attach($request->user_id);
$users = Meeting::with('users')->get();
\Mail::to($user->send(New NewMeeting($meetings('id')));

There are two scenarios in which you can send an email to users to the meeting:
When the user has been added to the meeting
When alerting all users (in bulk) of a meeting which they have been added to.
When emailing the user which has just been added
In the event where you would like to email the users once added, you can do the following:
...
$meeting = Meeting::find($meeting_id);
$user = User::find($request->user_id);
$meeting->users()->attach($user->id);
\Notification::send($user, new NewMeetingNotification($user));
This is to be added within code which only adds a user to a meeting, not multiple users.
When emailing all users within a meeting at once
In the event where you would like to email users, in bulk, once you've added all users, you can do the following.
...
$meeting = Meeting::with('users')->where('id', $meeting_id)->first();
$meeting->users()->each(function ($user, $key) {
\Notification::send($user, new NewMeetingNotification($user));
});
$meeting_id being the meeting in question.
Notify User (Optional)
If the user model has the notifiable trait, you can change the code to:
...
$meeting = Meeting::with('users')->where('id', $meeting_id)->first();
$meeting->users()->each(function ($user, $key) {
$user->notify(new NewMeetingNotification($user));
});
I hope this helps.

Related

How to check field comp_status from table companies while login in laravel?

I have two tables users (child-table) and companies (parent-table) whose id is defined as foreign key into users. How to do it using join in laravel? While a user of a company logins into the system first company-status must be checked whether the company is active or not; if it is not active the users should not be able to login - status if 0 and 1. I tried a lot and searched in google but could not manage to solve.
Please help me thank you in advance dear developers.
You could override the authenticated method in your Auth/LoginController.php:
protected function authenticated(Request $request, $user)
{
if ($user->company()->where('status', 0)->exists()) {
Auth::logout();
return back()->withErrors(['common' => trans('auth.blocked')]);
}
}
This function gets executed automatically after the user has been successfully logged in your application from the LoginController.
If the logged in user has a company whose status is 0, then the user is logged out and you will sent to the previous page with an error

Laravel - One to Many on the same table as parent

This is the scenario.
Im filling in a form and this form has Name, Email , Country and Skills (which is a dropdown with a number of skills which is populated from a database table skills prefilled). When the person is filling the form he can select multiple skills he possess. This means the user has many skills.(One to many). After the user fills the form and click submit. I want the UserTable saved and also the UserSkills also save related to the user.
The problem is dont have the user saved yet so cant fetch theid to save the skill on. Both has to be saved the same time when save is pressed.
How best can I do this in Laravel
I assume the skill ids are formatted as an array. You have a pivot table named UserSkills. Create a belongsToMany with User class as this will be a many to many relationship (one user can have multiple skills and one skill can belong to multiple users). So in your App\User class
public function skills(){
return $this->belongsToMany('\App\UserSkills','table_name','user_id','skill_id');
}
Detailed info on pivot table creation
After that, when you create an user
$user = new User();
$user->username = $request->input('username');
// other inputs or use a `create` method
$user->save();
after that attach the skill ids to the newly created user.
$user->skills()->attach($request->input('skill_ids'));
You can assign a var to the newly created user like so:
$user = User::create([
'username' => 'user'
]);
You can then use that $user anywhere below
UserSkills::create([
'user_id' => $user->id,
]);

Wordpress - Create custom shortcodes for emails

I use a custom emailer that alerts me whenever a new user signs up to my wordpress members site. The shortcodes that i am currently able to include within my emails are:
[name] = Displays user name.
[username] = Displays user username.
[password] = Displays user password.
[first_name] = Displays user first name.
[last_name] = Displays user last name.
[email] = Displays the user email.
[admin_email] = Displays the admin email.
[blogname] = Displays the blog anme.
[siteurl] = Displays site url.
[loginurl] = Displayslogin url.
[login_url] = Displays login url.
[passwordlink] = Displays password reset link.
[reason] = Displays the reason.
[expire_date] = Displays user expire date.
[post_title] = Displays the purchase post title.
[purchase_cost] = Displays the purchase post cost.
[amount] = Displays the membership amount.
[currency_sign] = Displays the currency symbol.
[membership_type] = Displays the membership type.
I would like to include the following wp_usermeta info within the emails to so want to setup another custom shortcode for these emails:
_mgm_cf_show_details_in_member_directory
How would i tell wordpress to echo this information in a new shortcode, something like [member-directory].
Upon registration, user's enter yes or no for this question so i want the email alert to tell me whether they have chosen Yes or No.
I hope that all makes sense, thanks again guys.
Without looking at the code, I can't give you a definitive answer, but;
It should be as simple as adding in a new array key to the outputting array.
There will be something somewhere that sends the short codes to the the emails, and that will be an object, something like:
$return['name'] = $user->name;
and you just need to add something like:
$return['member-directory'] = $user->_mgm_cf_show_details_in_member_directory
something along those lines should get you there

Appointment.Bind() and Mailbox

I retrieve an appointment by its unique ID. Now I want to find out which mailbox it is in.
I tried using appointment.Organizer, but this does not work for meetings, or for normal appointments - since appointments can be moved around between mailboxes, the Organizer can be different from the user that has the appointment in his calendar.
Is there a function to get a folder, given only an appointment and an ExchangeService?
If you want to get the SMTP address of the mailbox associated with a particular EWSId one way that should work is using convertId to convert the EWSId to a StoreId and just use generic mailbox address in the Mailbox field then the results you get back (if that ID is good) should contain the Mailbox its associated with eg
String EWSId = "AQMkADY4ZDQ4M2UyLTRhYjItNDhkYy1hMG...";
AlternateId aiRequest = new AlternateId();
aiRequest.UniqueId = EWSId;
aiRequest.Mailbox = "user#mailbox.com";
aiRequest.Format = IdFormat.EwsId;
AlternateId aiResultsStore = (AlternateId)service.ConvertId(aiRequest, IdFormat.StoreId);
Console.WriteLine(aiResultsStore.Mailbox);
Cheers
Glen

How to create Google Contact using Google API

I am trying to create Google Contact using Google Contacts API.
According to Google doc(as below), I have already implement the create function.
Google Docs Creating contacts
To create a new contact, send an authorized POST request to the user's contacts feed URL with contact data in the body.
The URL is of the form:
https://www.google.com/m8/feeds/contacts/{userEmail}/full
I use this query to create a contact:
www.google.com/m8/feeds/contacts/{userEmail}/full
However, the new contact is created in the group "Other Contact" by default.
How can I directly create in the group "My Contact"?
Do I need to modify the query?
From the doc (https://developers.google.com/google-apps/contacts/v3/?csw=1#authorizing_requests_to_the_api_name_service):
Contact Group Entry
Contacts can be placed into user-defined groups. You can create,
retrieve, update, and delete these groups using the Contacts Data API,
and you can add contacts to a group or remove contacts from a group.
For details, see the following sections.
The Contacts Data API also provides access to four predefined "system
groups" for each user:
My Contacts Friends Family Coworkers System groups appear in a groups
feed just like user-defined groups do. In fact, system groups are
mostly treated just like other groups. The differences are:
Each system group entry contains a subelement.
The id attribute of that subelement indicates which system group the
group is: Contacts, Friends, Family, or Coworkers. Note that the My
Contacts ID value is simply Contacts, without the "My". Also note
that this system group ID value is different from the group ID given
in the group entry's element. You can't add new system groups,
change the name of a system group, add extended properties to a system
group, or delete a system group. * The contact-group entry
representing a system group doesn't contain a rel="edit" link.
def get_group_id(label_name):
feed = gd_client.GetGroups()
for entry in feed.entry:
if entry.title.text.lower() == label_name:
return entry.id.text
contact_entry = gdata.contacts.data.ContactEntry() #contact_entry
group = get_group_id("My Contact") #group id
membership = gdata.contacts.data.GroupMembershipInfo(href=group) #group membership
contact_entry.group_membership_info.append(membership) # adding group membership to contact_entry
Its not true that contacts can only be placed into user-defined groups. I just experimented with Google Contact V3 API and was able to put a contact under system defined group (My contacts):
ContactEntry contact = new ContactEntry();
Name name = new Name();
final String NO_YOMI = null;
name.setFullName(new FullName("Elizabeth Bennet", NO_YOMI));
name.setGivenName(new GivenName("Elizabeth", NO_YOMI));
name.setFamilyName(new FamilyName("Bennet", NO_YOMI));
contact.setName(name);
GroupMembershipInfo groupInfo = new GroupMembershipInfo();
//You can fetch the following link from GroupEntry#getId()
groupInfo.setHref("http://www.google.com/m8/feeds/groups/{EmailId}/base/{groupId}");
groupInfo.setDeleted(false);
contact.getGroupMembershipInfos().add(groupInfo);
ContactEntry createdContact = myService.insert(new URL(
"https://www.google.com/m8/feeds/contacts/{EmailId}/full"), contact);