<?php
namespace App\Http\Controllers;

use App\Domain\Payments\Models\Requisites;
use App\Domain\Payments\Models\BankRequisites;

class RequisitesController extends Controller
{
    public function updateBank()
    {
        $user = auth()->user();
        $number = request()->number;
        $bankRequisites = $user->bank_requisites->first();
        if(!$bankRequisites){
            $bankRequisites = new BankRequisites;
            $bankRequisites->user()->associate(auth()->user());
            $bankRequisites->number = $number;
            $bankRequisites->save();

            $requisites = new Requisites;
            $requisites->user()->associate(auth()->user());
            $bankRequisites->requisites()->save($requisites);
        }else{
            $bankRequisites->number = $number;
            $bankRequisites->save();
        }


        return redirect()->back()->with('success', 'Реквизиты успешно обновлены!');

    }
}
