<?php

namespace App\Http\Controllers\calonsiswa;

use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Input as Input;
use Illuminate\Support\Facades\Auth;
use App\Models\Periodik;
use App\Models\Pendaftar;
use App\User;

class PeriodikController extends Controller
{
    public function index()
    {
    //     $this->data['title'] = 'Data Periodik';

    //     // $this->data['periodik'] = Auth::user()->periodik;
        return view('calonsiswa.dashboard');
    }

    public function create()
    {
    	 $this->data['title'] = 'Buat data periodik';
        return view('calonsiswa.periodik.create',$this->data);
    }


    public function store(Request $request)
    {
        $this->validate($request,[
            'tinggi_badan'=>'required',
            'berat_badan'=>'required',
            'jarak_kesekolah'=>'required',
            'waktu_tempuh'=>'required',
            'jumlah_saudara'=>'required',
            
        ]);

       
            $input['tinggi_badan'] = $request->input('tinggi_badan');
            $input['berat_badan'] = $request->input('berat_badan');
            $input['jarak_kesekolah'] = $request->input('jarak_kesekolah');
            $input['waktu_tempuh'] = $request->input('waktu_tempuh');
            $input['jumlah_saudara'] = $request->input('jumlah_saudara');
            $input['id_pendaftar'] = $request->user()->pendaftar->id;
            $id = $request->input('id');
            
            do {
                Periodik::UpdateOrCreate($input);
                return redirect()->route('periodik.index')->with('info','Selesai mendaftar'); 
        
            }while ($request->user()->id_pendaftar == $id);

           
     }
    
    

    
    


    public function show($id)
        {            //
            $this->data['periodik'] = Periodik::where('id_pendaftar',$id)->get();
            return view('calonsiswa.periodik.show',$this->data);
        }
   
}

