<?php

namespace App\Http\Controllers;

use App\Http\Middleware\CheckAdminRole;
use Illuminate\Support\Facades\Storage;
use App\Http\Requests\add_statement_request;
use App\Models\User;
use App\Models\Abonent;
use App\Models\Statement;
use App\Models\Tariff;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;

class StatementController extends Controller
{
    public function addstatement(add_statement_request $request){
        $user = Auth::user();
        $state = new Statement();
        $state->user_id = $user->id;
        $state->carnumber = $request->carnumber;
        $state->comment = $request->comment;
        $state->status = "Рассматривается";
        $state->save();
        if(Auth::user()->role == "admin"){
            return redirect()->route('adminpanel');
        }
        else{
            return redirect()->route('statements');
        }
        
    }

    public function statements(){
        $states = Statement::where('user_id', Auth::id())->get();
        return view('statements', ['states' => $states]);
    }
}
