Skip to content

Commit f5dc2e0

Browse files
authored
Merge pull request #29 from NikChoudhury/feature/28-laravel-form
#28 Simple Form in laravel
2 parents 52a9ed1 + 23b62a7 commit f5dc2e0

File tree

3 files changed

+64
-1
lines changed

3 files changed

+64
-1
lines changed
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace App\Http\Controllers;
4+
5+
use Illuminate\Http\Request;
6+
7+
class FormController extends Controller
8+
{
9+
public function index(Request $request){
10+
// return $request->post();
11+
# If Called In get Method
12+
// return $request->get('name');
13+
#or
14+
// return $request->query();
15+
#Some Other function
16+
// return $request->method(); --> gives method of the from
17+
// return $request->post(); -->Gives path of the form
18+
$method = $request->method();
19+
// return $method;
20+
if ($method=="POST") {
21+
return array($request->post(),$method);
22+
}else {
23+
return array($request->query(),$method);
24+
}
25+
}
26+
}

resources/views/form.blade.php

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
<!DOCTYPE html>
2+
<html lang="en">
3+
<head>
4+
<meta charset="UTF-8">
5+
<meta http-equiv="X-UA-Compatible" content="IE=edge">
6+
<meta name="viewport" content="width=device-width, initial-scale=1.0">
7+
<title>Laravel Form</title>
8+
</head>
9+
<body>
10+
<h1>
11+
This Is Laravel Form !!
12+
</h1>
13+
<h3>Post Method</h3>
14+
<form action="formSubmit" method="post">
15+
{{@csrf_field()}}
16+
<input type="text" name="name"><br><br>
17+
<input type="submit" value="submit">
18+
</form>
19+
<br>
20+
<br>
21+
<h3>Get Method</h3>
22+
<form action="formSubmit" method="get">
23+
{{@csrf_field()}}
24+
<input type="text" name="name"><br><br>
25+
<input type="submit" value="submit">
26+
</form>
27+
</body>
28+
</html>

routes/web.php

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,8 @@
33
use Illuminate\Support\Facades\Route;
44
use App\Http\Controllers\User;
55
use App\Http\Controllers\UserController;
6+
use App\Http\Controllers\FormController;
7+
68

79
/*
810
|--------------------------------------------------------------------------
@@ -34,4 +36,11 @@
3436

3537
#Component In Laravel
3638
Route::view('page','page');
37-
Route::view('page2','page2');
39+
Route::view('page2','page2');
40+
41+
#Form in Laravel
42+
Route::view('my_form','form');
43+
44+
#To handle A form
45+
Route::post('formSubmit', [FormController::class, 'index'] );
46+
Route::get('formSubmit', [FormController::class, 'index'] );

0 commit comments

Comments
 (0)