Views - Icybrew/Stackoverflow-documentation GitHub Wiki
Views are structured HTML pages, that are used to render what end-user sees.
Every view uses twig as template engine and must be structured accordingly to twig standards.
/* app/controllers/IndexController.php */
public function index() {
// First parameter which view to load, second is optional data array
$this->view('index', ['title' => 'My title', 'content' => 'Lorem ipsum ...']);
}
/* resources/views/index.php */
<html>
<head>
<title>{{ title }}</title>
</head>
<body>
<p>{{ content }}</p>
</body>
</htm>
To generate url to a given route, use {{ route('route.name', params) }} function.
/* views/***.php.twig */
/* Without parameters */
<a href="{{ route('home') }}">Home</a>
/* With parameters */
/* config/routes.php */
Route::get('topic/{topic}', 'topicController@show')->name('topic.show');
<a href="{{ route('topic.show', {'topic': 1}) }}">Topic 1</a>
Method function is helper that generates hidden input field for additional PUT, PATCH, DELETE methods since forms cannot make those requests!
/* views/***.php.twig */
<form action="" method="post">
{{ method('PUT') }}
...
</form>