Professional Documents
Culture Documents
HelloWorld.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
class HelloWorld extends Controller
{
//
// public function index () {
// return "HelloWorld, teks ini berasal dari Controller
HelloWorld";
//}
// public function getName(){
// $name = 'Berlian';
// return ($name);
//}
//public function index(){
// $nama = $this -> getName();
//return "Hello $nama, teks ini berasal dari Controller Hello
World";
// }
}
Hitung.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
FormNameHandling.php
<?php
namespace App\Http\Controllers;
use Illuminate\Http\Request;
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<form method="POST" action="{{route('submit_name')}}">
@csrf
<div class="row row-space">
<div class="col-2">
<div class="input-group">
<label class="label"> fisrt name </label>
<input class="input--style-4" type="text"
name="first_name" placeholder="your name">
</div>
</div>
</div>
<div class="p-t-15">
<button class="btn btn--radius-2 btn--blue"
type="submit">Submit</button>
</div>
</body>
</html>
Success_name.blade.php
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
</head>
<body>
<div class="card-body">
<h2 class="tittle">
Hello, {{$nama}} !
</h2>
</div>
</body>
</html>
Hasil.blade.php
@extends('layout')
@section('content')
<h1>Hasil</h1>
<p>Bilangan 1: {{ $bilangan1 }}</p>
<p>Bilangan 2: {{ $bilangan2 }}</p>
<p>Penjumlahan: {{ $hasil_penjumlahan }}</p>
<p>Pengurangan: {{ $hasil_pengurangan }}</p>
<p>Perkalian: {{ $hasil_perkalian }}</p>
<p>Pembagian: {{ $hasil_pembagian }}</p>
<a href="{{ route('hitung') }}">Kembali ke halaman hitung</a>
@endsection
Hitung.blade.php
@extends('layout')
@section('content')
<h1>Hitung</h1>
<form method="POST" action="{{ route('proses') }}">
@csrf
<div>
<label for="bilangan1">Bilangan 1</label>
<input type="number" id="bilangan1" name="bilangan1" required>
</div>
<div>
<label for="bilangan2">Bilangan 2</label>
<input type="number" id="bilangan2" name="bilangan2" required>
</div>
<button type="submit">Hitung</button>
</form>
@endsection
Layout.blade.php
<!DOCTYPE html>
<html>
<head>
<title>Kalkulator</title>
</head>
<body>
<div class="container">
@yield('content')
</div>
</body>
</html>
Web.php
<?php
use App\Http\Controllers\HelloWorld;
use App\Http\Controllers\FormNameHandling;
use App\Http\Controllers\Hitung;
Route::get('/helloworld',[HelloWorld::class,'index']);
Route::get('/hello/{nama}',[HelloWorld::class,'hello']);
Route::post('/namesubmission', [FormNameHandling::class, 'handleForm'])-
>name('submit_name');
Route::get('/hitung', [Hitung::class, 'hitung'])->name('hitung');
Route::post('/hitung', [Hitung::class, 'proses'])->name('proses');
Route::get('/form', function () {
return view('form');
});
Output :