Laravel 9

Laravel Tutorial: How to Add Numbers Easily Laravel 10

In this tutorials will teach How to add two numbers in Laravel 10.laravel tutorial souce code

First you have to create the new project in laravel using following command

composer create-project laravel/laravel addnumber-app

after create the project open the project into the vscode editor by typing the following command on the command prompt

code .

First Step Create the View. go to the resource folder inside the resource there is a view folder inside the view folder create the file which name is addnumber.blade.php

addnumber.blade.php

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.3.3/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-QWTKZyjpPEjISv5WaRU9OFeRpok6YctnYmDr5pNlyT2bRjXh0JMhjY6hW+ALEwIH" crossorigin="anonymous">
    <title>Document</title>
</head>
<body>
<div class ="container">
<form method="POST" action="{{ route('cal.add') }}">
    @csrf <!-- Add this line to include the CSRF token -->
  
  <h2>Add Two Numbers</h2>
  <div class="form-group">
    <label >Number 1</label>
    <input type="text" class="form-control"  placeholder="Enter Num 1" name="num1">
  
  </div>
  <div class="form-group">
    <label >Number 2</label>
    <input type="text" class="form-control"  placeholder="Enter Num 2" name="num2">
  
  </div>
  <br/>
  <button type="submit" class="btn btn-primary">Submit</button>
</form>

</div>

    
</body>
</html>

same folder create the another page result.blade.php

result.blade.php

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
    <title>Document</title>
</head>
<body>


<div class="container">
        <h1>Result</h1>
        <b>Total: {{ $tot }}</b>
    </div>

<div>


</body>
</html>

After that create the controller CalController

CalController

<?php

namespace App\Http\Controllers;
use Illuminate\Http\Request;

class CalController extends Controller
{

    public function add(Request $request)
    {

        $number1 = $request['num1'];
        $number2 = $request['num2'];
        $tot = $number1 + $number2;

     
        return view('result', ['tot' => $tot]);
    }
}

Routes

implement the routes

<?php

use Illuminate\Support\Facades\Route;
use App\Http\Controllers\CalController;


Route::get('/', function () {
    return view('addnumber');
});


Route::post('/add', [CalController::class, 'add'])->name('cal.add');

i have attached the video link below. which will do this tutorials step by step.

admin

Recent Posts

ChatGPT Free Online Download the ChatGPT App Easily

Have you ever wanted to talk to a friendly, smart robot that helps you with…

3 days ago

Free GPT Chat? DeepSeek AI Does It Better

DeepSeek AI is becoming a friendly and powerful new tool in the world of artificial…

2 weeks ago

Spring Boot MySQL Complete CRUD REST API [ Free Sourecode ]

Do you want to become an expert in Spring Boot CRUD operations? This comprehensive tutorial…

2 weeks ago

CREATE Responsive Navigation Bar with FlexBox CSS!

Modern websites must have a navigation bar that is clear and responsive. FlexBox CSS is…

4 weeks ago

Registration with image upload Java Jdbc(Download Source code)

Introduction In this section, we will guide you step by step in the development of an image upload registration system in Java using MySQL and JDBC. In the application, users register…

2 months ago

Touchable shop Pos system using Java

The Touchable Shop POS (Point of Sale) system is a sophisticated software solution developed using…

3 months ago