Creating View in Laravel

Last Updated: July 12, 2021

You can use Laravel view to put your all HTML code and you can pass data from Controller to View. The view is located at resources/views

Simple View is like below:

        <h1>Hello, {{ $name }}</h1>

How to pass data form Controller to View

class BookController extends Controller
    public function index(){

    	return view('book.index', ['books' => array("Book A","Book B","Book C")]);


Passing array to View using the the global view helper.

Now you can create the index.blade.php file inside the resources>view>book directory.

List of Books

@foreach($books as $k => $v)		
{{ $v }} 

Finally you can see the following output in your browser.