GuestController.php 1.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. <?php
  2. namespace App\Http\Controllers;
  3. use App\Models\CareMonth;
  4. use App\Models\CareMonthEntry;
  5. use App\Models\Client;
  6. use App\Models\Handout;
  7. use App\Models\HandoutClient;
  8. use App\Models\Pro;
  9. use App\Models\Section;
  10. use App\Models\SectionTemplate;
  11. use Illuminate\Http\Request;
  12. use Illuminate\Support\Facades\File;
  13. use Illuminate\Support\Facades\Response;
  14. class GuestController extends Controller
  15. {
  16. public function section(Request $request, $guestAccessCode )
  17. {
  18. $section = Section::where('guest_access_code', $guestAccessCode)->first();
  19. abort_if(!$section, 404, 'Invalid access code');
  20. abort_if($section->guest_access_level == 'NONE', 401, 'Invalid access code');
  21. $patient = null;
  22. if($section->note){
  23. $patient = $section->note->client;
  24. }else{
  25. $patient = $section->client;
  26. }
  27. return view('app.guest.section', compact('patient','section', 'guestAccessCode'));
  28. }
  29. public function handout(Request $request, $handoutClientUid )
  30. {
  31. $handoutClient = HandoutClient::where('uid', $handoutClientUid)->first();
  32. abort_if((!$handoutClient || !$handoutClient->is_active), 404, 'Invalid access code');
  33. $handout = Handout::where('id', $handoutClient->handout_id)->first();
  34. abort_if((!$handout || !$handout->is_active), 404, 'Invalid access code');
  35. return Response::download(
  36. $handout->pdf_file_path,
  37. $handout->internal_name . '.pdf',
  38. ['Content-Type: application/pdf']
  39. );
  40. }
  41. }