<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\Link;
use Exception;


class LinkController extends Controller
{

    public function access($token)
    {
        try {

            $link = Link::where('token', $token)->first();

            if (!$link) {
                abort(403, 'Lien expiré ou invalide.');
            }

            $demande = get_demande($link->demande);
            if ($demande) {
                $listIntervenants = get_intervenants($link->demande);
            }
        } catch (Exception $e) {
            dd($e);
        }
        return view('pages.accessView', compact('demande', 'listIntervenants'));
    }
}
