<?php

namespace App\Http\Controllers;

use App\Http\Requests\create_apply_request;
use App\Models\Apply;
use Illuminate\Support\Facades\Auth;

class ApplyController extends Controller
{
    public function addapply(create_apply_request $request)
    {
        Apply::create([
            'name' =>  $request->name,
            'number' =>  $request->number,
            'email' =>  $request->email,
            'address' =>  $request->address,
            'date' =>  $request->date,
            'time' =>  $request->time,
            'paymethod' =>  $request->paymethod,
            'category_id' =>  $request->category_id,
            'user_id' =>  Auth::id(),
            'customcategory' =>  $request->customcategory,
        ]);
        return redirect()->route('myapply');
    }

    public function myapply()
    {
        $myaps = Apply::with('category')->where('user_id', Auth::id())->orderBy('created_at', 'desc')->get();

        return view('myApply', ['myaps' => $myaps]);
    }
}
