<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use App\Models\School;

class SchoolController extends Controller
{
    // 显示创建学校的表单
    public function create()
    {
        return view('school.create');
    }

    // 处理表单提交
    public function store(Request $request)
    {
        // 验证请求数据
        $data = $request->validate([
            'school' => 'required|string|max:255',
            'name' => 'required|string|max:255',
            'phone' => 'required|string|max:255',
            'password' => 'required|string|max:255',
            'schoolinfo' => 'required|string',
            'schooltype' => 'required|string|max:255',
            'gradetype' => 'required|string|max:255',
            'num' => 'required|string|max:255',
            'address' => 'required|string|max:255',
        ]);

        // 将数据插入到数据库中
        School::create($data);

        // 重定向到一个新的页面或显示成功消息
        return response()->json(['message' => '学校信息已保存！']);
    }
}
