Laravel Database Connection and Work with Model, Controller
Make Controllers On Two Different Ways
1 |
php artisan make:controller HomeController |
As a Result to execute the Controller
1 |
php artisan make:controller HomeController |
Controller And View Together:
1 2 3 4 5 6 7 |
Directory of Controller : App\Http\Controllers\HomeController.php public function forum() { $name = "Mr.Al Amin"; return view("forum/education"); } |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
1st Way: Controller for View Display - public function forum() { $name = "Mr.Al <span style='color:red;'>Amin</span>"; } 2nd Way: Controller for View Display with array -- public function forum() { return view("pages/forum.education")->with([ 'fname'=>"Md. Al Amin", 'lname' => "Sarker" ]); } 3rd Way: Controller for View Display with Data array -- public function forum() { $data=[]; $data["fname"] = "Md.Al Amin"; $data["lname"] = "Sarker"; return view("pages/forum.education",$data); } |
Output Result after Controller Apply
1 2 3 4 5 6 |
<div class="container"> <div class="content"> <h2 align="center">Hello Man! <?= $fname . " " . $lname; ?></h2> <div class="title">This is Education Forum</div> </div> </div> |