<?php

namespace App\Http\Controllers\Web;

use App\Product;
use App\Http\Controllers\Controller;

class ProductController extends Controller
{

    private $view = 'web.products.';

    public function index()
    {
        $products = Product::withDescription();
        $title = __('products.head');
        return view($this->view.'index', get_defined_vars());
    }

    public function show(Product $product)
    {
        /**
         * This means that the product is not allowed to display
         */
        if (!$product->is_special){
            return redirect()->route('product.index');
        }

        $product = Product::withDescription([$product->id]);
        $title = $product->name;
        $advantages = $product->advantages;
        $advantages = preg_replace('/\r\n/', '', $advantages);
        $advantages = explode('@@', $advantages);
        $advantages = array_filter($advantages);
        return view($this->view.'show', get_defined_vars());
    }

}
