GuestController.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253
  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->is_active, 404, 'Invalid access code');
  21. abort_if($section->guest_access_level == 'NONE', 401, 'Invalid access code');
  22. $patient = null;
  23. if($section->note){
  24. $patient = $section->note->client;
  25. }else{
  26. $patient = $section->client;
  27. }
  28. return view('app.guest.section', compact('patient','section', 'guestAccessCode'));
  29. }
  30. public function handout(Request $request, $handoutClientUid )
  31. {
  32. $handoutClient = HandoutClient::where('uid', $handoutClientUid)->first();
  33. abort_if((!$handoutClient || !$handoutClient->is_active), 404, 'Invalid access code');
  34. $handout = Handout::where('id', $handoutClient->handout_id)->first();
  35. abort_if((!$handout || !$handout->is_active), 404, 'Invalid access code');
  36. return Response::download(
  37. $handout->pdf_file_path,
  38. $handout->internal_name . '.pdf',
  39. ['Content-Type: application/pdf']
  40. );
  41. }
  42. }