Be part of JetBrains PHPverse 2026 on June 9 – a free online event bringing PHP devs worldwide together.

lattkkthx's avatar

The PHP Practitioner Questions

So I just finished the The PHP Practitioner course and I am trying to update this framework so that I could use it to create simple websites.

Right now to the existing routes I added a

  1. Delete route (deletes a user).

I also added a route to get a single user but its not working properly, only works if its hard coded


$router->get('', 'PagesController@home');
$router->get('about', 'PagesController@about');
$router->get('contact', 'PagesController@contact');

$router->get('users', 'UsersController@index');
$router->get('users/3', 'UsersController@show'); // route to get single user


$router->post('users', 'UsersController@store');
$router->post('users/delete', 'UsersController@delete');

You can see my progress here: https://github.com/andrei-bil/vault_landingpages Thanks

0 likes
11 replies
Ty's avatar

php artisan route:list will show you all registered routes.

$router->get('', 'PagesController@home');
$router->get('about', 'PagesController@about');
$router->get('contact', 'PagesController@contact');

$router->get('users', 'UsersController@index');
$router->get('users/{user}', 'UsersController@show'); // route to get single user


$router->post('users', 'UsersController@store');
$router->post('users/delete', 'UsersController@delete');
Snapey's avatar

Your route

$router->get('users/{user}', 'UsersController@show');

controller


public function show(User $user)
{
    //$user is now an instance of the user model with the passed id
lattkkthx's avatar

Thanks guys, but I am not using laravel, like I said its a framework inspired by the php practitioner course

    /**
     * Load the requested URI's associated controller method.
     *
     * @param string $uri
     * @param string $requestType
     */
    public function direct($uri, $requestType)
    {

        if (array_key_exists($uri, $this->routes[$requestType])) {
            return $this->callAction(
                ...explode('@', $this->routes[$requestType][$uri])
            );
        }

        throw new Exception('No route defined for this URI.');
    }

This is my direct route

Snapey's avatar

Once you get to the end of that course, thats it. Thats the end. Its not built to be extended further. At this point you should discard what you have and move on to Laravel

Cronix's avatar

@click why can't he talk about official Laracasts videos/series on the Laracasts forum, whether they have to do with Laravel directly, or not?

Vue and javascript don't have anything directly to do with Laravel, either, but there are plenty of videos and discussion about them on this forum.

click's avatar

@cronix I wasn't aware that that course is part laracasts. I thought this question was about a total different framework based on the first sentence. My bad.. continue

jlrdw's avatar

That practitionrer series is just a basic understanding, to be honest I would not use that, definitely move on to laravel.

Cronix's avatar

@jlrdw That was actually the point of the series. It was just showing you, at the most basic level (Model/View/Controller) how MVC works, piece by piece. It went beyond that and showed how Dependency Injection works, namespaces, routing, etc. It's actually a great series I'd recommend anyone to watch. It makes the concepts used in Laravel much easier to understand, especially for someone new to the concept of frameworks. The very last video basically says (my paraphrase) "now that you know how all of these pieces in a modern php framework work and what they do, here's laravel that has it all built in. Use that."

lattkkthx's avatar

I wanted to use this for small projects like landing pages.. I dont want to install a whole laravel project, if all I need is a project that has 1 front-page with a contact form :-/

Therefore I thought it is a pretty good idea to update what jefferey showed me a little more.

Thanks for the help. It seems I need to re-construct the routing to match the patterns using regex

jlrdw's avatar

A while back I was playing around with making a small router, got busy and never finished, but this works:

$routes = [
    'dog/indexadmin' => '\Mini\Controller\DogController@indexAdmin',
    'dog/index' => '\Mini\Controller\DogController@indexAdmin'
];
$uri = explode('/', $_SERVER['REQUEST_URI']);
$uri = $uri[2] . '/' . $uri[3];
$newuri = strtok($uri, '?');
$key_to_check = $newuri;
if (array_key_exists($key_to_check, $routes)) {
    $uparts = explode('@', $routes[$key_to_check]);
    $controller = isset($uparts[0]) ? $uparts[0] : null;
    $action = isset($uparts[1]) ? $uparts[1] : null;
    call_user_func_array(array($controller,$action), array(['params']));
}

Needs a default method, error checks, again I was just playing around.

Please or to participate in this conversation.