<?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()
    {
        return view('calonsiswa.dashboard');
    }

    public function edit($id)
    {
        $this->data['kartu'] = Periodik::findOrFail($id);
        return view('calonsiswa.periodik.edit',$this->data);
    }

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

            $kartu = Periodik::findOrFail($id);
            $kartu -> tinggi_badan = $request->tinggi_badan;
            $kartu -> berat_badan = $request->berat_badan;
            $kartu -> jarak_kesekolah = $request->jarak_kesekolah;
            $kartu -> waktu_tempuh = $request->waktu_tempuh;
            $kartu -> jumlah_saudara = $request->jumlah_saudara;
            $kartu-> save();
            return view('calonsiswa.dashboard')->with('info','Berhasil diubah');

        }

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

