In this tutorial we will discuss how to write html code in laravel controller. Write html code between double quotes and print or return it.
Print or return html code in controller
In Controller we take a variable and pass some html code between double quotes than echo or return this variable it show this html result.Let understand by an example
Make a controller by run this command "php artisan make:controller HtmlController".
<?php namespace App\Http\Controllers; use Illuminate\Http\Request; use App\Models\Student; class HtmlController extends Controller{ public function index(){ $name = "Anmol Sharma"; $html = "<h1>Hello, I am ".$name."</h1><p>And this is a laravel tutorial for write html code in controller.</p>"; echo $html; //or return $html; } }