<?php

use Illuminate\Database\Seeder;
use App\Fortunemethod;
use App\Seo;

class UpdateMethodSlug extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        $methods = Fortunemethod::all();
        foreach ($methods as $it) {
            if ($it->slug == null && $it->slug == "") {
                $slug = str_replace(" ", "", $it->name);
                $slug = trim(strip_tags($slug));
                $it->update(['slug' => $slug]);
                print "Update method slug of " . $it->name . " \r\n";
            }

            $uri = "/method/" . $it->slug;
            $checkSeo = Seo::where('uri', $uri)->first();
            if (!isset($checkSeo) || $checkSeo == null || !isset($checkSeo->id)) {
                $seoTitle = "『" . $it->name . "』の当たると口コミで評判のオススメの占い師｜占いの森 / URAMORI";
                $seoDesc = "『" . $it->name . "』の的中率の高い・当たると評判のオススメ占い師を口コミ評価レビュー、占い料金、性別、得意な占術・相談お悩み内容などで検索し探せます。";
                Seo::create([
                    'uri'         => $uri,
                    'title'       => $seoTitle,
                    'description' => $seoDesc,
                    'type'        => 'method',
                    'created_at'  => date('Y-m-d H:i:s'),
                    'updated_at'  => date('Y-m-d H:i:s'),
                ]);
                print "Update method SEO Info of " . $it->name . " \r\n";
            }
        }
    }
}
