<?php

namespace App\Http\Controllers\Api;

use App\Http\Requests\Api\UserRequest;
use App\Http\Resources\Api\UserResource;
use App\Jobs\Api\SaveLastTokenJob;
use App\Models\Book;
use App\Models\Url;
use App\Models\Log;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Tymon\JWTAuth\Exceptions\TokenExpiredException;
use Illuminate\Support\Facades\DB;

class UrlController extends Controller
{
    public function index()
    {
        $urls = Url::all();
        return $this->success($urls);
    }
    public function add(Request $req)
    {
        $hosts = $req->hosts;
        foreach ($hosts as $v) {
            $urls = new Url;
            $urls->host = $v;
            $urls->save();
        }
        return $this->success("");
    }
    public function del(Request $req)
    {
        $id = $req->id;
        Url::where('id', $id)->delete();
        return $this->success("");
    }
    public function set(Request $req)
    {
        $host = $req->host;
        $url = $req->url;
        $log = new Log;
        $log->host = $host;
        $log->url = $url;
        $log->save();
        Url::where('host', $host)->update(['url' => $url]);
        return $this->success("");
    }    public function text()
    {
        //$users = DB::select('select * from `users` where `name` = giaogiao limit 1');
        return $this->success("");
    }
}
