How to configure routes in Laravel 5.3?

Asked

Viewed 215 times

0

I’m studying more on my own Laravel, and yes I’ve looked at his documentation on routes and I can’t make it work here.

I ran a little test:

Route::get('/', function () {
    return view('welcome');
});

Route::get('teste', function() {
    return view('teste');
});

and created the archive teste.blade.php in the briefcase resources/views/teste.blade.php this along with the file welcome.blade.php, where it works smoothly, but when I put in the browser dev.project/teste He can’t find the file. but put yourself dev.project/ he opens the file Welcome.

someone can tell me if any configuration is missing, or maybe I have to create a controller file to run?

  • you executed by some server or was the PHP itself?

  • The correct thing is to create a controller file and from there you call the view. The Routes.php file should only be to do this route transfer to controller and not to perform functions or call views..

1 answer

1

As mentioned in the comments, the correct thing is to create a Controller and there you prepare the data to send to the view. Example:

Route:

Route::get('/teste', ['as'=>'teste.index', 'uses'=> 'TesteController@index']);

Controller:

public function index(){
    return view('teste.index');
}

Browser other questions tagged

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