Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

PHP Notice: Undefined Variable #1

Closed
keenminded opened this issue Feb 10, 2020 · 3 comments
Closed

PHP Notice: Undefined Variable #1

keenminded opened this issue Feb 10, 2020 · 3 comments

Comments

@keenminded
Copy link

keenminded commented Feb 10, 2020

Hello Marcel,

First and foremost, thank you for all the tools and packages you and your team have produced. Your many contributions have been absolutely invaluable. Keep up the great work.

I have just upgraded Tinkerwell app to 2.2.0 and installed the tinkerwell-helper package. While overall everything appears to work properly, I am unable to get the value of the variable in the Tinkerwell window. When I close the Tinkerwell app, the tinker($events) command relaunches the application, so the handoff seems to occur, however, trying to access the value returns the PHP Notice. I am using the hyn/tenancy package in our project, and initially, I am activating the right tenant to access the correct database.

I hope the information below helps you in tracking down the issue! Thank you in advance.

Here is the code in controller app:

$events = Event::orderBy('official_name', 'DESC')->get();
tinker($events);
return view('admin.events.index', compact('events'));

Here is the code in Tinkerwell app:

/**
 * Welcome to Tinkerwell!
 *
 * You can tinker using the built-in
 * Laravel 6 application and use all the
 * nice Laravel features right away.
 *
 * Try modifying this file - the changes will
 * be automatically evaluated as you type.
 */

// $movies = [
//     [
//         'name' => 'Back to the Future',
//         'released_in' => 1985,
//     ],
//     [
//         'name' => 'Ghostbusters',
//         'released_in' => 1984,
//     ],
//     [
//         'name' => '2001: A Space Odyssey',
//         'released_in' => 1968,
//     ],
// ];

$hostname = Hyn\Tenancy\Models\Hostname::find(1);
$website = Hyn\Tenancy\Models\Website::find(1);
$tenancy = app(Hyn\Tenancy\Environment::class);
$tenancy->hostname($hostname);
$tenancy->hostname();
$tenancy->tenant($website);
$tenancy->tenant();

$event = Event::first();
echo $event->created_at;

echo $events;

Here is the result:

[!] Aliasing 'Event' to 'App\Models\Tenant\Event' for this Tinker session.
2020-02-05 08:15:59
PHP Notice:  Undefined variable: events in phar:///Applications/Tinkerwell.app/Contents/Resources/tinkerwell/tinker.phar/index.php(66) : eval()'d code on line 65
@mpociot
Copy link
Member

mpociot commented Feb 20, 2020

Can you verify that $events can be serialized?
In order to make the variable available to the Tinkerwell app, I'm serializing the data and then unserialize it in Tinkerwell again.

@keenminded
Copy link
Author

Hi Marcel,

I updated to the new version (2.2.1) of the Tinkerwell app today, and the above started working. Both serialized and unserialized data are showing up correctly now.

$hostname = Hyn\Tenancy\Models\Hostname::find(1);
$website = Hyn\Tenancy\Models\Website::find(1);
$tenancy = app(Hyn\Tenancy\Environment::class);
$tenancy->hostname($hostname);
$tenancy->hostname();
$tenancy->tenant($website);
$tenancy->tenant();

$events;

The above returned an expected collection or an array in case of ->toArray(). If something had changed in the new version, thank you.

@keenminded
Copy link
Author

On the other hand, I had updated the code to use a repository pattern instead of directly calling "$events = Events::all()"; so the serialization most likely had been the culprit in my case about a week ago. Hope this helps someone. Thank you for your input.

mpociot pushed a commit that referenced this issue Mar 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants