1. <?php
  2.  
  3. namespace App\Http\Controllers;
  4.  
  5. use Illuminate\Http\Request;
  6. use App\Models\Page;
  7.  
  8. class PageController extends Controller
  9. {
  10. public function show($slug)
  11. {
  12. $page = \Cache::remember('page_'.$slug,6000,function() use($slug){
  13. return Page::where('slug', $slug)->where('active', 1)->firstOrfail();
  14. });
  15.  
  16. $description = trim(preg_replace('/\s+/', ' ', strip_tags($page->content)));
  17.  
  18. $page->description = str_limit($description, 200, '');
  19.  
  20. return view('front.page.show', compact('page'))->with('page_title', $page->title);
  21. }
  22.  
  23. public function contact()
  24. {
  25. return view('front.page.contact')->with('page_title', __('Contact Us'));
  26. }
  27.  
  28. public function contactPost(Request $request)
  29. {
  30. $validator = Validator::make($request->all(), [
  31. 'name' => 'required|eco_alpha_spaces|min:2|max:100',
  32. 'email' => 'required|email|max:100',
  33. 'message' => 'required|string|min:10|max:5000',
  34. 'g-recaptcha-response' => (config('settings.captcha') == 1) ? 'required|captcha' : ''
  35. ]);
  36. if ($validator->fails()) {
  37. return redirect()->back()
  38. ->withErrors($validator)
  39. ->withInput();
  40. } else {
  41.  
  42. try {
  43. Mail::send('emails.contact', ['request' => $request], function ($m) {
  44. $m->to(config('settings.site_email'))->subject(config('settings.site_name') . ' - ' . __('Contact Message'));
  45. });
  46. } catch (\Exception $e) {
  47. \Log::info($e->getMessage());
  48. return redirect('contact')->with('warning', __('Your message was not sent due to invalid mail configuration'));
  49. }
  50.  
  51. return redirect('contact')->with('success', __('Your message successfully sent'));
  52. }
  53.  
  54. }
  55.  
  56. }