58 lines
1.8 KiB
PHP
58 lines
1.8 KiB
PHP
|
|
<?php
|
||
|
|
|
||
|
|
namespace App\Http\Controllers;
|
||
|
|
|
||
|
|
use App\Models\Attender;
|
||
|
|
use App\Models\Event;
|
||
|
|
use Illuminate\Http\Request;
|
||
|
|
use SimpleSoftwareIO\QrCode\Facades\QrCode;
|
||
|
|
use Illuminate\Support\Facades\Mail;
|
||
|
|
use Illuminate\Http\File;
|
||
|
|
use Illuminate\Support\Facades\DB;
|
||
|
|
use Illuminate\Mail\Message;
|
||
|
|
|
||
|
|
class HomeController extends Controller
|
||
|
|
{
|
||
|
|
public function index(){
|
||
|
|
$events = Event::orderBy('event_date', 'desc')->paginate(3);
|
||
|
|
return view('welcome', [
|
||
|
|
'events' => $events
|
||
|
|
]);
|
||
|
|
}
|
||
|
|
|
||
|
|
public function apply($id){
|
||
|
|
$event_id = $id;
|
||
|
|
return view('signup', [
|
||
|
|
'event_id' => $event_id
|
||
|
|
]);
|
||
|
|
}
|
||
|
|
|
||
|
|
public function submit(Request $request){
|
||
|
|
$data = $request->only(['name', 'surname', 'email', 'file', 'organization', 'is_attending', 'consent_form']);
|
||
|
|
$data['attended'] = 0;
|
||
|
|
$data['is_attending'] = (bool)$data['is_attending'];
|
||
|
|
$data['consent_form'] = (bool)$data['consent_form'];
|
||
|
|
|
||
|
|
$attender = Attender::create($data);
|
||
|
|
$attender->events()->attach($request->event_id);
|
||
|
|
|
||
|
|
$attendance = DB::table('event_attenders')
|
||
|
|
->where('event_id', $request->event_id)
|
||
|
|
->where('attender_id', $attender->id)
|
||
|
|
->first();
|
||
|
|
|
||
|
|
$file_name = uniqid() . '.png';
|
||
|
|
$qrCodePath = public_path('qr/' . $file_name);
|
||
|
|
QrCode::format('png')->size(512)->margin(10)->generate($attendance->id, $qrCodePath);
|
||
|
|
|
||
|
|
Mail::send('emails.qr', ['file_name' => $file_name], function (Message $message) use ($attendance, $qrCodePath) {
|
||
|
|
$message->to($attendance->email)->subject('QRCode');
|
||
|
|
|
||
|
|
$pngFile = new File($qrCodePath);
|
||
|
|
$message->attach($pngFile, ['as' => 'qr_code2.png', 'mime' => 'image/png']);
|
||
|
|
});
|
||
|
|
|
||
|
|
return view('success');
|
||
|
|
}
|
||
|
|
}
|