<?php

    use Eae\Transformation\Transformer\BlockTransformer;


    class BlockController extends Controller
    {

        /**
         * Display a listing of the resource.
         *
         * @return Response
         */
        public function index()
        {
            //
        }


        /**
         * Show the form for creating a new resource.
         *
         * @return Response
         */
        public function create()
        {
            //
        }


        /**
         * Store a newly created resource in storage.
         *
         * @return Response
         */
        public function store()
        {
            //
        }


        /**
         * Display the specified resource.
         *
         * @param  int $id
         * @return Response
         */
        public function show($id)
        {
            // Get Block info, load relations
            $block = Block::full()
                ->with([
                    'squareGrid' => function ($query) {
                        $query->full()
                            ->select('*');
                    },
                    'liveshowList' => function ($query) {
                        $query->full()
                            ->select('*');
                    },
                    'highResolutionImage',
                    'squareImage',
                    'squareImageAux',
                    'gallery'
                ])
                ->where('id', $id)
                ->first();

//            DB::flushQueryLog();

            // Beautify result.
            $result = TransformService::transformItem(
                $block,
                new BlockTransformer(),
                ['squareGrid', 'liveshowList', 'gallery'])->toArray();


//            echo '<pre>';
//            print_r(DB::getQueryLog());
//            dd();

            return Response::json($result);
        }


        /**
         * Show the form for editing the specified resource.
         *
         * @param  int $id
         * @return Response
         */
        public function edit($id)
        {
            //
        }


        /**
         * Update the specified resource in storage.
         *
         * @param  int $id
         * @return Response
         */
        public function update($id)
        {
            //
        }


        /**
         * Remove the specified resource from storage.
         *
         * @param  int $id
         * @return Response
         */
        public function destroy($id)
        {
            //
        }


    }
