<?php

namespace App\Http\Controllers;

use App\Models\Article;
use App\Models\Category;

class ArticleController extends Controller
{

    public function show(Article $article)
    {
        if ($article->url) {
            return redirect($article->url);
        }


        $category = $article->categories()->first();
        $parent   = $category;
        $topCate  = $category->getTopCategory();

        if ($category->childrens->isEmpty() && $category->parent) {
            $parent = $category->parent;
        }

        $data = [
            'article'  => $article,
            'category' => $category,
            'parent'   => $parent,
            'topCate'  => $topCate,
        ];
        return view('articles.show', $data);
    }

}
