Framework: Tinker must be restarted for code to take effect.

Created on 21 Apr 2015  路  10Comments  路  Source: laravel/framework

Hello

I've started studying the Laravel framework on @JeffreyWay's Laracasts for a few hours and I noticed this:

Bug:

When using tinker, I receive the mass-assignment error even if the columns are whitelisted with $fillable. The error is: Illuminate\Database\Eloquent\MassAssignmentException with message 'title')

How to reproduce:

  1. Create a Model with a title column
  2. Start tinker now
  3. Whitelist the title for mass assignment
  4. Try to add a new row and notice the error eg.

    >>> App\Article::create(['title'=>'1st Article']);

  5. Restart tinker
  6. Repeat (4), this now it works

    So...

Is there a way to avoid restarting tinker?

Most helpful comment

@kadimi Here a simple bash command:

while true; do php artisan tinker; done

CTRL+D = reload
CTRL+C = exit

or

.profile file:

alias pat="php artisan tinker"
alias patt="while true; do php artisan tinker; done"

after type "pat" to normal tinker, and "patt" to continous tinker.

All 10 comments

I think you mean tinker cause tinkster is _way_ something else :D

@Anahkiasen Yep, thanks.

This is not a bug. It is how tinker works.

@JosephSilber I see, thanks.

@kadimi you might want to check out this repo: https://github.com/ajthinking/tinx

We've love contributions back to the original repo. We were discussing the possibility of restarts only recently.

you can use tinx and call re() to refresh session

@kadimi Here a simple bash command:

while true; do php artisan tinker; done

CTRL+D = reload
CTRL+C = exit

or

.profile file:

alias pat="php artisan tinker"
alias patt="while true; do php artisan tinker; done"

after type "pat" to normal tinker, and "patt" to continous tinker.

@GrahamCampbell Any more recent thoughts about how not to be required to restart Tinker after editing code?

I see "Laravel Tinx was archived on 12th December 2019 and is no longer maintained." but also that it seems to be just a suggestion like https://github.com/laravel/framework/issues/8504#issuecomment-478248339

@szekeresa It seems to work for me so far (+1), but would you mind explaining what that is doing and what the downsides are of running Tinker that way?

Thanks!

@szekeresa It seems to work for me so far (+1), but would you mind explaining what that is doing and what the downsides are of running Tinker that way?

Thanks!

This command while true; do php artisan tinker; done runs a loop with tinker, and every time you close it by Cmd+D or exit it the loop starts over again, so it reloads the classes and all the lot. Cmd+C closes it.

Was this page helpful?
0 / 5 - 0 ratings