S
S
sacred12014-12-17 11:25:30
Laravel
sacred1, 2014-12-17 11:25:30

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]'
]);

2) And in general, is it necessary to make this very controllers on each page?
3) And how to insert a regular link into your template on a page for example / add.php (with the controller that I wrote came out, well, which in turn returns ) I would be very grateful if someone explained the work of routing in general in public words return View::make('add');

Answer the question

In order to leave comments, you need to log in

2 answer(s)
S
Sergey Gladkovskiy, 2014-12-17
@SMGladkovskiy

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.

M
Mokhirjon Naimov, 2015-01-08
@zvermafia

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]'));

That is, the route " example.com/ " will call the getIndex() method in the SomeController controller,
also the route " example.com/about-us " will call the getAboutUs() method in the SomeController controller.
The controller itself (app/controllers/SomeController.php):
<?php
class SomeController extends BaseController
{
   // метод для "Главная"
    public function getIndex()
    {
        return View::make("index");
    }

   // метод для "О нас"
    public function getAboutUs()
    {
        return View::make("about-us");
    }
}

Now the templates themselves (index, about-us):
app/views/index.blade.php:
<a href="{{ route('about-us') }}">Перейти на страницу "О нас"</a>
<h1>Вы находитесь в главной странице</h1>

app/views/about-us.blade.php:
<a href="{{ route('home') }}">Главная</a>
<h1>Вы находитесь в странице "О нас"</h1>

I think it's clear...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question