本文整理汇总了PHP中app\Message::processIds方法的典型用法代码示例。如果您正苦于以下问题:PHP Message::processIds方法的具体用法?PHP Message::processIds怎么用?PHP Message::processIds使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类app\Message
的用法示例。
在下文中一共展示了Message::processIds方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: create
public function create(Request $request)
{
$schools = $this->school->lists('school_name', 'id')->all();
$all_contacts = $this->contact->allStudents();
$contacts = array();
foreach ($all_contacts as $contact) {
$contacts[$contact->id] = $contact->name . ' ' . $contact->surname;
}
$students = new Collection();
if ($request->input('message_id')) {
$messages = Message::processIds($request->input('message_id'));
foreach ($messages as $message) {
$students->add($message->Contact);
}
$students = $students->unique();
}
if ($students->count()) {
$selected = array();
foreach ($students as $student) {
$selected[] = $student->id;
}
$second_email = false;
$student_emails = "";
foreach ($students as $student) {
if ($second_email) {
$student_emails .= ', ' . $student->user_email;
} else {
$student_emails .= $student->user_email;
$second_email = true;
}
}
} else {
$selected = null;
$student_emails = null;
}
/*
if ($request->input('student_checkbox')) {
$selected = array();
foreach ($request->input('student_checkbox') as $student_id => $foo) {
$selected[] = $student_id;
}
$students = $this->contact->whereIn('id', $selected)->get();
$second_email = false;
$student_emails = "";
foreach ($students as $student) {
if ($second_email) {
$student_emails .= ', '.$student->user_email;
} else {
$student_emails .= $student->user_email;
$second_email = true;
}
}
} else {
$selected = null;
$student_emails = null;
}
*/
return view()->make('emails.create', compact('contacts', 'schools', 'selected', 'student_emails'));
}
示例2: exportCSV
public function exportCSV(Request $request)
{
//$messages = $this->message->where('hidden', '0')->get();
if ($request->input('message_id')) {
$messages = Message::processIds($request->input('message_id'));
if ($messages->count()) {
$destinationPath = 'downloads/' . time() . '-' . str_random(8);
$filename = 'export-' . str_random(8) . '.csv';
$directory = File::makeDirectory($destinationPath, 0770);
$file = fopen($destinationPath . '/' . $filename, 'w');
fputcsv($file, array('id', 'date', 'student', 'type', 'school', 'notes'));
foreach ($messages as $message) {
if (count($message->School) > 0) {
$school = $message->School->school_name;
} else {
$school = null;
}
fputcsv($file, array($message->id, $message->updated_at, $message->Contact->fullName(), $message->MessageType->message_type_name, $school, $message->contents));
}
$file = fclose($file);
$headers = array('Content-Type' => 'text/csv');
return response()->download($destinationPath . '/' . $filename, $filename, $headers);
}
} else {
return redirect()->back()->withError('Please select some records');
}
}