Configure Template(ready) in Laravel 5.x

Asked

Viewed 1,469 times

0

I’m relatively new to developing with Laravel. I bought a template(bootstrap) for my system but do not know how to configure it to work frontend of my application. I’ve tried some tutorials that copies index to the Welcome and folders CSS and JS to the folder public. I’ve changed routes and I haven’t been successful either, if anyone can help me.

1 answer

1

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;

  • Why did you put the h instead of H in homeController?

  • it’s just an example, it’s not a convention to follow.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.