Answer the question
In order to leave comments, you need to log in
Implementing routing in Laravel?
Hello!
I just started to learn Laravel
, this is my first php framework, and I ran into some difficulties in this mvc model. Actually, the questions are:
controller and the name of the so-called action, that is, in the route we must describe each action? just the simplest controllers in the route look like this
Route::get('/', [
'as' => 'add',
'uses' => '[email protected]'
]);
return View::make('add');
Answer the question
In order to leave comments, you need to log in
1) For good, so that later you don’t tear your hair on your buttocks in attempts to debug (and they will, since there is no experience), YES. And so - as you wish, you can use the resource route or the controller / model route ...
2) If the resource develops, YES is better. And so - as you wish.
3) {{ URL::route('route.name') }}
The routing functionality is simple - it looks at a URI and matches it against a given set of described routes. If it finds a match, it executes the route.
For example!
Let's assume that we have two pages "Home" and page "About us".
We write routes for them, it will look something like this (app/routes.php):
// Для главной странице
Route::get('/', array('as' => 'home', 'uses' => '[email protected]'));
// И для странице о нас
Route::get('/about-us', array('as' => 'about-us', 'uses' => '[email protected]'));
<?php
class SomeController extends BaseController
{
// метод для "Главная"
public function getIndex()
{
return View::make("index");
}
// метод для "О нас"
public function getAboutUs()
{
return View::make("about-us");
}
}
<a href="{{ route('about-us') }}">Перейти на страницу "О нас"</a>
<h1>Вы находитесь в главной странице</h1>
<a href="{{ route('home') }}">Главная</a>
<h1>Вы находитесь в странице "О нас"</h1>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question