You are on page 1of 4

DAFFA TYAN PUTRO

20410100083

PWDL P3

Soal:
Menentukan berat badan ideal berdasarkan tinggi badan

Views
Formku.php
<!DOCTYPE html>
<html>
<head>
<title>LARAVEL</title>
</head>
<body>
<h1>IMT IDEAL </h1>
<P>Masukkan Tinggi Badan anda untuk menentukan Berat Badan Ideal anda</P>
<form method="POST" action="hitungimt">
<input type="hidden" name="_token" value="<?php echo csrf_token();?>">
<input type="text" name="tinggi">
<input type="submit" name="kirim" value="Jumlah">
</form>
</body>
</html>

Controllers
BlogController.php
<?php

namespace App\Http\Controllers;
//untuk isi form
use Illuminate\Http\Request;
//panggil model perhitungan
use App\Models\Perhitungan;

class BlogController extends Controller


{
public function formIMT(){
return view('formku');
}
public function hitungIMT(Request $xx){
$a = $xx->input('tinggi');
$c = new Perhitungan();
echo $c->Hitung($a);
}
}

Models
Perhitungan.php
<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Perhitungan extends Model {


//use hasfactory
public function Hitung ($a) {
return(($a-100)-($a-100)*0.1);
}
}
Routes
Web.php
<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\Controller;
use App\Http\Controllers\BLogController;
/*
|--------------------------------------------------------------------------
| Web Routes
|--------------------------------------------------------------------------
|
| Here is where you can register web routes for your application. These
| routes are loaded by the RouteServiceProvider within a group which
| contains the "web" middleware group. Now create something great!
|
*/

Route::get('formimt', [BlogController::class, 'formIMT']);


Route::post('hitungimt', [BlogController::class, 'hitungIMT']);

OUTPUT:

You might also like