D
D
DiaTMss2019-03-30 19:13:55
Laravel
DiaTMss, 2019-03-30 19:13:55

How is route done in laravel?

Good day, dear programmers, how are routers created in laravel? For more than 2 months I can not understand how everything is arranged? For happiness, I just have to deal with this and continue to train on my own framework.
Just tell me how routing is arranged in laravel pliz
In which folder is the $router->get() implementation as I understand it RESTful API ->post,
https://habr.com/en/post/265845/
I thought that the url should connect a controller, for example
, lumen.local/public/about
AboutController.php
further
lumen.local/public/controller/action/parametr
But everything is different here, there is also app/Http/Controllers
lumen.local/public
lumen.local/public/about
routes/web.php

$router->get('/', function () use ($router) {
    return $router->app->version();
});

$router->get('/about', function()
{
  return 'About';
});

I did something like this roughly speaking in laravel, everything is elegant compared to my shit code
<?php

    $action = $_SERVER['REQUEST_URI'];

    $routes = [];

    route('/', function()
    {
        $title = 'Home';

        $template =
        [
            'header',
            'content',
            'footer'
        ];

        view($title, $template);
    });

    route('about', function()
    {
        $title = 'About';

        $template =
        [
            'header',
            'content',
            'footer'
        ];

        view($title, $template);
    });

    function route($action = null, $callback = null)
    {
        global $routes;

        $action = trim($action, '/');

        $routes[$action] = $callback;
    }

    function getPath($action = null)
    {
        global $routes;

        $action = trim($action, '/');

        $callback = $routes[$action];

        call_user_func($callback);
    }

    getPath($action);

    //View

    function view($title = null, $template = [])
    {
        require_once 'views/' . 'index.php';
    }

Answer the question

In order to leave comments, you need to log in

1 answer(s)
M
Maxim Fedorov, 2019-03-30
@DiaTMss

Look at the basics, you will understand, then you will understand:
PSR-7 framework 2/7: Routing and controllers
In the video, you create your own routing, close to the Aura package, which in turn is close to Laravel. That is, not just how to use it, but how it works and why. Long and helpful.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question