Interacting With Your Application

Problem

You want an easy way to interact with your application.

Solution

Use the php artisan tinker command.

This command provides a REPL (Read-Eval-Print Loop) for PHP with your application's settings already loaded.

$ php artisan tinker
[1] > echo Config::get('app.url');
http:://your.app.url
[2] > exit;

You can access the database, use models, etc.

$ php artisan tinker
[1] > $user = User::find(1);
->object(User)(
  'incrementing' => true,
  'timestamps' => true,
  'exists' => true
)
[2] > echo $user->name;
Chuck
[3] > exit;

Discussion

The tinker command uses Boris.

Boris is a robust, little REPL for PHP. Check out their web page at github.com/d11wtq/boris.

If the tinker command doesn't work for you, it is very likely the disable_functions setting in your php.ini contains the needed pcntl_() functions. Put a comment before this line in your php.ini and that should allow tinker to work.

comments powered by Disqus