{"id":19324874,"url":"https://github.com/spatie/laravel-visit","last_synced_at":"2025-05-16T05:05:00.849Z","repository":{"id":41871487,"uuid":"460121828","full_name":"spatie/laravel-visit","owner":"spatie","description":"Quickly visit any route in your Laravel app","archived":false,"fork":false,"pushed_at":"2025-02-17T10:49:52.000Z","size":2707,"stargazers_count":150,"open_issues_count":0,"forks_count":8,"subscribers_count":4,"default_branch":"main","last_synced_at":"2025-04-08T15:06:57.796Z","etag":null,"topics":["debug","laravel","php","route","testing"],"latest_commit_sha":null,"homepage":"https://freek.dev/2216-introducing-visit-a-cli-tool-made-for-humans-to-make-networks-requests","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/spatie.png","metadata":{"files":{"readme":"README.md","changelog":"CHANGELOG.md","contributing":null,"funding":".github/FUNDING.yml","license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":"spatie"}},"created_at":"2022-02-16T18:09:34.000Z","updated_at":"2025-04-04T04:41:03.000Z","dependencies_parsed_at":"2025-04-01T13:11:29.271Z","dependency_job_id":null,"html_url":"https://github.com/spatie/laravel-visit","commit_stats":{"total_commits":127,"total_committers":5,"mean_commits":25.4,"dds":0.4173228346456693,"last_synced_commit":"bd58978bca4286c88895f737d0ff938eb9c04d17"},"previous_names":[],"tags_count":9,"template":false,"template_full_name":"spatie/package-skeleton-laravel","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spatie%2Flaravel-visit","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spatie%2Flaravel-visit/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spatie%2Flaravel-visit/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/spatie%2Flaravel-visit/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/spatie","download_url":"https://codeload.github.com/spatie/laravel-visit/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":253540659,"owners_count":21924523,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["debug","laravel","php","route","testing"],"created_at":"2024-11-10T02:07:18.637Z","updated_at":"2025-05-16T05:05:00.832Z","avatar_url":"https://github.com/spatie.png","language":"PHP","funding_links":["https://github.com/sponsors/spatie"],"categories":[],"sub_categories":[],"readme":"# Quickly visit any route of your Laravel app\n\n[![Latest Version on Packagist](https://img.shields.io/packagist/v/spatie/laravel-visit.svg?style=flat-square)](https://packagist.org/packages/spatie/laravel-visit)\n[![GitHub Tests Action Status](https://img.shields.io/github/workflow/status/spatie/laravel-visit/run-tests?label=tests)](https://github.com/spatie/laravel-visit/actions?query=workflow%3Arun-tests+branch%3Amain)\n[![GitHub Code Style Action Status](https://img.shields.io/github/workflow/status/spatie/laravel-visit/Check%20\u0026%20fix%20styling?label=code%20style)](https://github.com/spatie/laravel-visit/actions?query=workflow%3A\"Check+%26+fix+styling\"+branch%3Amain)\n[![Total Downloads](https://img.shields.io/packagist/dt/spatie/laravel-visit.svg?style=flat-square)](https://packagist.org/packages/spatie/laravel-visit)\n\nThis package contains an artisan command `visit` that allows you to visit any route of your Laravel app. \n\n```bash\nphp artisan visit /my-page\n```\n\nThe command display the colorized version of the HTML...\n\n![screenshot](https://spatie.github.io/laravel-visit/images/html.png)\n\n... followed by a results block.\n\n![screenshot](https://spatie.github.io/laravel-visit/images/results.png)\n\nThe command can also colorize JSON output. It also has support for some Laravel niceties such as logging in users before making a request, using a route name instead of and URL, and much more.\n\n## Want to use `visit` to visit any site\n\n[The `spatie/visit` tool](https://github.com/spatie/visit) can be installed globally to visit any site.\n\n## Support us\n\n[\u003cimg src=\"https://github-ads.s3.eu-central-1.amazonaws.com/laravel-visit.jpg?t=1\" width=\"419px\" /\u003e](https://spatie.be/github-ad-click/laravel-visit)\n\nWe invest a lot of resources into creating [best in class open source packages](https://spatie.be/open-source). You can support us by [buying one of our paid products](https://spatie.be/open-source/support-us).\n\nWe highly appreciate you sending us a postcard from your hometown, mentioning which of our package(s) you are using. You'll find our address on [our contact page](https://spatie.be/about-us). We publish all received postcards on [our virtual postcard wall](https://spatie.be/open-source/postcards).\n\n## Installation\n\nYou can install the package via composer:\n\n```bash\ncomposer require spatie/laravel-visit\n```\n\nTo colorize HTML, you should install `bat`.\n\n```bash\nbrew install bat\n```\n\nTo colorize JSON, you should install `jq`.\n\n```bash\nbrew install jq\n```\n\n\nOptionally, you can publish the config file.\n\n```bash\nphp artisan vendor:publish --tag=\"visit-config\"\n```\n\nThis is the content of the published config file:\n\n```php\nreturn [\n    /*\n     * These classes are responsible for colorizing the output.\n     */\n    'colorizers' =\u003e [\n        Spatie\\Visit\\Colorizers\\JsonColorizer::class,\n        Spatie\\Visit\\Colorizers\\HtmlColorizer::class,\n    ],\n\n    /*\n     * These stats will be displayed in the response block.\n     */\n    'stats' =\u003e [\n        ...Spatie\\Visit\\Stats\\DefaultStatsClasses::all(),\n    ]\n];\n```\n\n## Usage\n\nTo visit a certain page, execute `php artisan` followed by a URL.\n\n```bash\nphp artisan visit /your-page\n```\n\n![screenshot](https://spatie.github.io/laravel-visit/images/html.png)\n\nInstead of passing an URL, you can pass a route name to the `route` option. Here's an example where we will visit the route named \"contact\".\n\n```bash\nphp artisan visit --route=contact\n```\n\n### Using a different method\n\nBy default, the `visit` command will make GET request. To use a different HTTP verb, you can pass it to the `method` option.\n\n```bash\nphp artisan visit /users/1 --method=delete\n```\n\n### Passing a payload\n\nYou can pass a payload to non-GET request by using the payload. The payload should be formatted as JSON.\n\n```bash\nphp artisan visit /users --method=post --payload='{\"testKey\":\"testValue\"}'\n```\n\nWhen you pass a payload, we'll assume that you want to make a `POST` request. If you want to use another http verb, pass it explicitly.\n\n```php\nvisit \u003cyour-url\u003e --method=patch --payload='{\"testKey\":\"testValue\"}'\n```\n\n### Logging in a user\n\nTo log in a user before making a request, add the `--user` and pass it a user id.\n\n```php\nphp artisan visit /api/user/me --user=1\n```\n\nAlternatively, you can also pass an email address to the `user` option.\n\n```php\nphp artisan visit /api/user/me --user=john@example.com\n```\n\n### Showing the headers of the response\n\nBy default, the `visit` command will not show any headers. To display them, add the `--headers` option\n\n```bash\nphp artisan visit /my-page --headers\n```\n\n![screenshot](https://spatie.github.io/laravel-visit/images/headers.png)\n\n### Following redirects\n\nBy default, the `visit` command will not follow redirects. To follow redirects and display the response of the redirection target, add the `--follow-redirects` option.\n\n```bash\nphp artisan visit /my-page --follow-redirects\n```\n\n### Showing exception pages\n\nWhen your application responds with an exception, the `visit` command will show the html of the error page.\n\nTo let the `visit` command display the actual exception, use the `--show-exception` option.\n\n```bash\nphp artisan visit /page-with-exception --show-exception\n```\n\n### Only displaying the response\n\nIf you want the `visit` command to only display the response, omitting the response result block at the end, pass the `--only-response` option.\n\n```bash\nphp artisan visit / --only-response\n```\n\n### Only displaying the response properties block\n\nTo avoid displaying the response, and only display the response result block, use the `--only-stats` option\n\n```bash\nphp artisan visit / --only-stats\n```\n\n### Avoid colorizing the response\n\nThe `visit` command will automatically colorize any HTML and JSON output. To avoid the output being colorized, use the `--no-color` option.\n\n```bash\nphp artisan visit / --no-color\n```\n\n### Displaying the result HTML as text\n\nUsually an HTML response is quite lengthy. This can make it hard to quickly see what text will be displayed in the browser. To convert an HTML to a text variant, you can pass the `--text` option.\n\n```bash\nphp artisan visit / --text\n```\n\nThis is how the default Laravel homepage will look like.\n\n![screenshot](https://spatie.github.io/laravel-visit/images/text.png)\n\n### Filtering HTML output\n\nIf you only want to see a part of an HTML response you can use the `--filter` option. For HTML output, you can pass [a css selector](https://www.w3schools.com/cssref/css_selectors.asp).\n\nImagine that your app's full response is this HTML:\n\n```html\n\u003chtml\u003e\n    \u003cbody\u003e\n        \u003cdiv\u003eFirst div\u003c/div\u003e\n        \u003cp\u003eFirst paragraph\u003c/p\u003e\n        \u003cp\u003eSecond paragraph\u003c/p\u003e\n    \u003c/body\u003e\n\u003c/html\u003e\n```\n\nThis command ...\n\n```bash\nphp artisan visit / --filter=\"p\"\n```\n\n... will display:\n\n```html\n\u003cp\u003eFirst paragraph\u003c/p\u003e\n\u003cp\u003eSecond paragraph\u003c/p\u003e\n```\n\n### Filtering JSON output\n\nIf you only want to see a part of an JSON response you can use the `--filter` option. You may use dot-notation to reach nested parts.\n\nImagine that your app's full response is this JSON:\n\n```json\n{\n    \"firstName\": \"firstValue\",\n    \"nested\": {\n        \"secondName\": \"secondValue\"\n    }\n}\n```\n\nThis command ...\n\n```bash\nphp artisan visit / --filter=\"nested.secondName\"\n```\n\n... will display:\n\n```html\nsecondValue\n```\n\n### Adding stats\n\nIn the results block underneath the response, you'll see a few interesting stats by default, such as the response time and queries executed.\n\nYou can add more stats there by creating your own `Stat` class. A valid `Stat` is any class that extends `Spatie\\Visit\\Stats\\Stat`. \n\nHere's how that base class looks like:\n\n```php\nnamespace Spatie\\Visit\\Stats;\n\nuse Illuminate\\Contracts\\Foundation\\Application;\n\nabstract class Stat\n{\n    public function beforeRequest(Application $app)\n    {\n    }\n\n    public function afterRequest(Application $app)\n    {\n    }\n\n    abstract public function getStatResult(): StatResult;\n}\n```\n\nAs an example implementation, take a look at the `RunTimeStat` that ships with the package.\n\n```php\nnamespace Spatie\\Visit\\Stats;\n\nuse Illuminate\\Contracts\\Foundation\\Application;\nuse Symfony\\Component\\Stopwatch\\Stopwatch;\nuse Symfony\\Component\\Stopwatch\\StopwatchEvent;\n\nclass RuntimeStat extends Stat\n{\n    protected Stopwatch $stopwatch;\n\n    protected ?StopwatchEvent $stopwatchEvent = null;\n\n    public function __construct()\n    {\n        $this-\u003estopwatch = new Stopwatch(true);\n    }\n\n    public function beforeRequest(Application $app)\n    {\n        $this-\u003estopwatch-\u003estart('default');\n    }\n\n    public function afterRequest(Application $app)\n    {\n        $this-\u003estopwatchEvent = $this-\u003estopwatch-\u003estop('default');\n    }\n\n    public function getStatResult(): StatResult\n    {\n        $duration = $this-\u003estopwatchEvent-\u003egetDuration();\n\n        return StatResult::make('Duration')\n            -\u003evalue($duration . 'ms');\n    }\n}\n```\n\nTo activate a `Stat`, you should add its class name to the `stats` key of the `visit` config file.\n\n```php\n// in config/stats.php\n\nreturn [\n    // ...\n    \n    'stats' =\u003e [\n        App\\Support\\YourCustomStat::class,\n        ...Spatie\\Visit\\Stats\\DefaultStatsClasses::all(),\n    ]\n]\n```\n\n## Testing\n\n```bash\ncomposer test\n```\n\n## Changelog\n\nPlease see [CHANGELOG](CHANGELOG.md) for more information on what has changed recently.\n\n## Contributing\n\nPlease see [CONTRIBUTING](https://github.com/spatie/.github/blob/main/CONTRIBUTING.md) for details.\n\n## Security Vulnerabilities\n\nPlease review [our security policy](../../security/policy) on how to report security vulnerabilities.\n\n## Credits\n\n- [Freek Van der Herten](https://github.com/freekmurze)\n- [All Contributors](../../contributors)\n\n## License\n\nThe MIT License (MIT). Please see [License File](LICENSE.md) for more information.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspatie%2Flaravel-visit","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fspatie%2Flaravel-visit","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fspatie%2Flaravel-visit/lists"}