Skip to content

[Bug]: wrong relative path if laravel project is in /app folder #625

@tuanpt-0634

Description

@tuanpt-0634

Extension Version

1.6.8

PHP Binary

Docker

Operating System

Linux

What happened?

Pre-conditions:
Our Laravel project is located in /app folder.
The full path of a controller will be, for example, /app/app/Http/Controllers/LoginController.php.

Behavior:
When follow the link of route('login') function:

  • Actual: it opened the controller file at Http/Controllers/LoginController.php
  • Expected: it opens the controller file at app/Http/Controllers/LoginController.php

Reason:
Because base_path() === /app, the function LaravelVsCode::relativePath() replace all occurrences of /app in file path.

return ltrim(str_replace(base_path(), '', realpath($path) ?: $path), DIRECTORY_SEPARATOR);

Solution:
Only replace the first occurrence of base_path().

Mimimal Code Sample

Metadata

Metadata

Assignees

Labels

Type

No type
No fields configured for issues without a type.

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions