<?php

namespace AdRepository\Devdetail\Http\Controllers;

use App\Http\Controllers\PublicWebController as PublicController;
use AdRepository\Devdetail\Interfaces\DevdetailRepositoryInterface;

class DevdetailPublicWebController extends PublicController
{
    /**
     * Constructor.
     *
     * @param type \AdRepository\Devdetail\Interfaces\DevdetailRepositoryInterface $devdetail
     *
     * @return type
     */
    public function __construct(DevdetailRepositoryInterface $devdetail)
    {
        $this->repository = $devdetail;
        parent::__construct();
    }

    /**
     * Show devdetail's list.
     *
     * @param string $slug
     *
     * @return response
     */
    protected function index()
    {
        $devdetails = $this->repository->scopeQuery(function($query){
            return $query->orderBy('id','DESC');
        })->paginate();

        return $this->theme->of('devdetail::public.devdetail.index', compact('devdetails'))->render();
    }

    /**
     * Show devdetail.
     *
     * @param string $slug
     *
     * @return response
     */
    protected function show($slug)
    {
        $devdetail = $this->repository->scopeQuery(function($query) use ($slug) {
            return $query->orderBy('id','DESC')
                         ->where('slug', $slug);
        })->first(['*']);

        return $this->theme->of('devdetail::public.devdetail.show', compact('devdetail'))->render();
    }
}