<?php

namespace App\Http\Controllers;

use App\Models\Subscriber;
use App\Models\Trafic;
use Illuminate\Support\Facades\Auth;

class SubscriberController extends Controller
{
    public function welcome(){
        $trafics = Trafic::all();
        $user = Auth::id();
        $subscriber = Subscriber::where('user_id', $user)->first();
        return view('welcome', ['trafics' => $trafics, 'subscriber' => $subscriber]);
    }

    public function trafic(Trafic $trafic) {
        $subscriber = Subscriber::where('user_id', Auth::id())->first();
        $subscriber->update([
            'trafic_id' => $trafic->id,
        ]);
        return redirect()->route('welcome');
    }
}
