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

Sujeevan

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

$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}()
Maik Lowrey

Perhaps you looking for app Version. then use config('app.version'); resp. app()->version(). What @aimme has already said

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

OR

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

Both will returned the app version. The App Version you define in the config/app.php.

'version' => env('APP_VERSION', '1.1.1'),

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

Laravel 5.1 gives 'undefined index: http_host ' when run 'php artisan serve'

Laravel | MySQL error when i run php artisan migrate command

laravel failed to open stream fatal error when running php artisan serve command

run laravel project without artisan serve

Php Artisan serve command not serving Laravel 5.8

php artisan serve command display error message

error when i run php artisan migrate command on line 51

Php artisan serve in laravel

PhpStorm: run php artisan serve Undefined index: REQUEST_URI

My laravel 5.6 project is opening on localhost but not on php artisan serve cmd

Run laravel 5 app without php artisan serve

Laravel command php artisan serve showing Directory does not exist

Whats the point of running Laravel with the command 'php artisan serve'?

Generate Artisan command instead of "php artisan serve"

How to exit the command stream when running php artisan serve?

laravel on xampp got error but php artisan serve is working

PHP MVC Framework Laravel Seems an Error Artisan Serve

Undefined constant 'App\Product' when i run php artisan db:seed laravel6

Laravel 5.7 - Unable to run php artisan commands when shifted project to live

Laravel php artisan serve logs stored and start artisan serve automatically

Laravel error: SQLSTATE[23000]: Integrity constraint violation: 1062 Duplicate entry (only when run as artisan command)

Error in Laravel Artisan command

What is the equivalent of "php artisan serve" for a CodeIgniter project?

How to run "php artisan serve" on local network

Command php artisan serve on other network?

Why command "php artisan serve" not working

Run artisan command in laravel 5

Laravel - Unable to run artisan command

Laravel 5.3 - Is it possible to run php artisan command by clicking on a link/button