File tree Expand file tree Collapse file tree 3 files changed +64
-1
lines changed Expand file tree Collapse file tree 3 files changed +64
-1
lines changed Original file line number Diff line number Diff line change
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
+ }
Original file line number Diff line number Diff line change
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 >
Original file line number Diff line number Diff line change 3
3
use Illuminate \Support \Facades \Route ;
4
4
use App \Http \Controllers \User ;
5
5
use App \Http \Controllers \UserController ;
6
+ use App \Http \Controllers \FormController ;
7
+
6
8
7
9
/*
8
10
|--------------------------------------------------------------------------
34
36
35
37
#Component In Laravel
36
38
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 ' ] );
You can’t perform that action at this time.
0 commit comments