Not a member of gistpad yet?
Sign Up,
it unlocks many cool features!
- <?php
- namespace App\Http\Controllers;
- use Illuminate\Http\Request;
- use App\Models\Page;
- class PageController extends Controller
- {
- public function show($slug)
- {
- $page = \Cache::remember('page_'.$slug,6000,function() use($slug){
- return Page::where('slug', $slug)->where('active', 1)->firstOrfail();
- });
- $description = trim(preg_replace('/\s+/', ' ', strip_tags($page->content)));
- $page->description = str_limit($description, 200, '');
- return view('front.page.show', compact('page'))->with('page_title', $page->title);
- }
- public function contact()
- {
- return view('front.page.contact')->with('page_title', __('Contact Us'));
- }
- public function contactPost(Request $request)
- {
- $validator = Validator::make($request->all(), [
- 'name' => 'required|eco_alpha_spaces|min:2|max:100',
- 'email' => 'required|email|max:100',
- 'message' => 'required|string|min:10|max:5000',
- 'g-recaptcha-response' => (config('settings.captcha') == 1) ? 'required|captcha' : ''
- ]);
- if ($validator->fails()) {
- return redirect()->back()
- ->withErrors($validator)
- ->withInput();
- } else {
- try {
- Mail::send('emails.contact', ['request' => $request], function ($m) {
- $m->to(config('settings.site_email'))->subject(config('settings.site_name') . ' - ' . __('Contact Message'));
- });
- } catch (\Exception $e) {
- \Log::info($e->getMessage());
- return redirect('contact')->with('warning', __('Your message was not sent due to invalid mail configuration'));
- }
- return redirect('contact')->with('success', __('Your message successfully sent'));
- }
- }
- }
RAW Gist Data
Copied
