create views is relatively simple, already took a look at the documentation?
first, create a controller, for example, in the folder app\Http\Controllers
create a file named: homeController, in the contents of your controller, put for example:
homeController.php
namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
class homeController extends Controller
{
public function index()
{
return view('home');
}
}
in the briefcase resources/views
, create a file called home.blade.php
Laravel uses the Blade to create your templates, in the contents of your template, put your html. there will be other things to consider but I will explain only the basics.
Creating routes:
now in the Routes/web.php folder, copy the line:
Route::get('/', function () {
return view('welcome');
});
and edit to look like this (if not returning the controller view):
Example 1:
Route::get('/', function () {
return view('home');
});
the "/" in get means that this is the home page of the application. if it is to add other routes it would be:
Route::get('produtos', function () {
return view('produtos');
});
if the view (file containing html) is inside a subfolder, then it would be:
Route::get('produto', function () {
return view('produtos.produto');
});
in your case as you would be returning the controller view would be:
Example 2:
Route::get('/', 'homeController@index')->name('home');
(small explanation: homeController is the name of your controller, @index is the name of the function that returns the view there in your controller)
if your template has some dynamic pages, for example, that need to return some backend information, then create a controller for that page as in example 2, if not, just create a route and return the view to the route as in example 1.
Thank you. I tested and it worked;
– Jéhh
Why did you put the
h
instead ofH
inhomeController
?– novic
it’s just an example, it’s not a convention to follow.
– Leandro