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

sifrious's avatar

no definition found: use function Pest\Laravel\get;

I'm trying to use the get() function introduced in episode 4 of Pest Driven Laravel (Write Your First PEST Test) but I can't seem to import get. I'm getting no definition found. I can't find Pest\Laravel; I'm not sure if I messed up the installation. Any explinations or ideas for next steps?

My code is (intended to be) exactly the same as the video:

<?php

use function Pest\Laravel\get;

it('gives back successful response for the home page', function () {

    get(route('home'))->assertStatus(200);
});
0 likes
4 replies
LaryAI's avatar
Level 58

The error "no definition found: use function Pest\Laravel\get" suggests that the get function from the Pest\Laravel package is not being imported correctly.

To resolve this issue, you can try the following steps:

  1. Make sure you have installed the pestphp/pest-plugin-laravel package by running the following command in your terminal:
composer require pestphp/pest-plugin-laravel --dev
  1. After installing the package, you need to update your tests/TestCase.php file to include the necessary imports. Open the file and add the following line at the top:
use Pest\Laravel\Concerns\ProvidesRoutes;
  1. Next, update your test file to import the get function correctly. Replace the existing use statement with the following:
use Pest\Laravel\Testing\Concerns\MakesHttpRequests;
  1. Finally, update your test code to use the get function from the MakesHttpRequests trait. Replace the existing test code with the following:
it('gives back successful response for the home page', function () {
    $this->get(route('home'))->assertStatus(200);
});

By following these steps, you should be able to import and use the get function correctly in your tests.

Ben Taylor's avatar
Level 35

You forgot the curly braces

use function Pest\Laravel\{get};
3 likes
sifrious's avatar

Solved

I did run composer require pestphp/pest-plugin-laravel --dev (here's the docs just in case anyone else forgets that step and wants to see) and added curly braces as Ben responded then refreshed visual studio code using the command pallate. After that, get() worked.

I just saw the response from the AI when I came back to post the solution; I don't think steps 2-4 (a.k.a. 1, 1 and 1) are required but it's a good thing to know

1 like

Please or to participate in this conversation.