Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

Laravel project gives Undefined property error when run php artisan serve command

I have a Laravel project,
this code from routes/web.php

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

When I try to run ‘php artisan serve’ it gives Undefined property: Illuminate\Routing\Router::$app error,

I tried adding container instead of app

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

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

then it gives ‘Error: cannot access protected property’
Please let me know if anyone knows how to clear this issue and run the project

ErrorException: Undefined property: Illuminate\Routing\Router::$app

at /Applications/XAMPP/xamppfiles/htdocs/em2/routes/web.php:18 at Illuminate\Foundation\Bootstrap\HandleExceptions->handleError(8, 'Undefined property: Illuminate\Routing\Router::$app', '/Applications/XAMPP/xamppfiles/htdocs/em2/routes/web.php', 18, array('router' => object(Router))) (/Applications/XAMPP/xamppfiles/htdocs/em2/routes/web.php:18) at Illuminate\Routing\RouteFileRegistrar->{closure}()

>Solution :

use app() helper method to access app instance from anywhere. try this

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

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading