<?php

namespace App\Http\Controllers;

use App\Events\MessageButton;
use App\Models\Profile;
use Illuminate\Http\Request;
use App\Http\Controllers\IndexController\Auth;

class IndexController extends Controller
{
    
    public function show()
    {
        if (\Auth::check()) {          
            event(new MessageButton("controllers"));
            return view('hello');
        } else {
            return redirect('/login');
        }
    }

    public function db()
    {
        if (\Auth::check()) {
            event(new MessageButton("models"));
            $res = \App\Models\Header::where('id', 1)->firstOrFail();
            return view('models', [
                'data' => $res
            ]);
        } else {
            return redirect('/login');
        }
    }

    public function form()
    {
        if (\Auth::check()) {
            event(new MessageButton("forms"));
            return view('regform');
        } else {
            return redirect('/login');
        }
    }

    public function form_send(Request $request)
    {
        $validatedata =  $request->validate([
            'name' => 'required|max:30',
            'lastname' => 'required|max:50',
            'email' => 'required',
            'phone' => 'required|max:11',
            'section' => 'required|max:100'

        ]);
        $newprofile = Profile::create($validatedata);
        $name = $request->input('name');

        // dd($newprofile);
        return "";
    }
}
