Search

Laravel Artisan Tinker: The doc Command

December 7, 2016 —John Koster

The doc command can be used to view the documentation for an object, class, constant, method, function or property. It can accept either the function, method, class, etc name or a reference to an instance's methods as its arguments. Because of Laravel's numerous and high quality code documentation, this command is very useful.

For example, we can look at the documentation for the config helper function within the command-line environment (some lines have been manually wrapped and indented to prevent wrapping that may cause readability issues):

1>>> doc config
2function config($key = null, $default = null)
3
4Description:
5 Get / set the specified configuration value.
6
7 If an array is passed as the key, we will assume you want to set an
8 array of values.
9
10Param:
11 array|string $key
12 mixed $default
13
14Return:
15 mixed
16>>> doc auth
17function auth($guard = null)
18
19Description:
20 Get the available auth instance.
21
22Param:
23 string|null $guard
24
25Return:
26 \Illuminate\Contracts\Auth\Factory|\Illuminate\Contracts\Auth\
27 Guard|\Illuminate\Contracts\Auth\StatefulGuard

To contrast, the following example demonstrates how to retrieve the documentation for a class property; in this case, the doc command is being used to display the help information related to the $table property on an Eloquent model:

1>>> $user = new App\User
2=> App\User {#644}
3>>> doc $user->table
4protected $table
5
6Description:
7 The table associated with the model.
8
9Var: string

Some absolutely amazing
people

The following amazing people help support this site and my open source projects ♥️
If you're interesting in supporting my work and want to show up on this list, check out my GitHub Sponsors Profile.