Comments (9)
This is unfortunately how it works. You could use the full namespace or use the alias blacklist to prevent classes from being aliased: https://laravel.com/docs/5.7/artisan#tinker
from tinker.
Wouldn't this still be considered unexpected behavior? If the output to the user is that the short class name is aliased to the fully qualified class name, then the behavior of Tinker should behave such that it was indeed aliased.
What's the point in aliasing one value to another if the original value doesn't return the data it was mapped to?
from tinker.
@brysonreece because aliasing wasn't meant to be used in combination with a full app lifecycle. If you want to run code from your app itself inside Tinker then you'd best use the full namespace.
Aliasing was meant to do some quick data retrieval, etc by just using the class name.
from tinker.
I understand, however the larger issue is that it is still unexpected behavior that conflicts with what the user is being told. Can the message at least be amended to reflect that better or at least be documented somewhere?
from tinker.
Plus it's not hard to encounter this issue without requiring interaction of a full app lifecycle.
from tinker.
@brysonreece I'm not sure how the message can be more clear. It's already pretty clear what it means to me.
from tinker.
It may be a matter of semantics but I think it's easy to misinterpret "how" the requested class is aliased to the fully qualified class name. Aliasing is usually assumed that one value maps to another, like the user is being informed of. However when the value is requested again, in this case, it's not returning what they were informed it was actually "aliased" to, which leads to unexpected behavior.
from tinker.
@brysonreece maybe a note to the docs? Feel free to send in a PR if you want to.
from tinker.
hello to have the thing return the full class please import first, if in your code
otherwise in artisan alias manually like
use App\Models\User as AliasUser;
AliasUser::class; ///gives the correct
App\Models\User
instead ofUser
as if you just do User::class, this is as seems tinker aliases for you it only does so when you use the class not just when you want to echo the class.
consider writing say in your code
echo User::class;
without first importing User
it will echo just fine without any errors but it will just echo 'User' while what you want is App\Models\User
usually this is important in mapping polymorphic relationships
so correct use of it to give fully qualified name would rather be:
use App\Models\User;
echo User::class;
its more of a php issue than a laravel as php ideally should not just return the class name you give it when you have not imported it.
from tinker.
Related Issues (20)
- Tinker lost colors HOT 18
- How is idea of making laravel tinker that detect the updates in code instantly? HOT 3
- Add ability to refresh Tinker session from within Tinker? HOT 3
- Contextual binding doesn't appear to work in tinker HOT 4
- Add migrate:install to white listed commands HOT 1
- assert always returns true HOT 2
- Can't open Tinker because of a bad $options argument to Symfony HOT 2
- Commands inside tinker incorrectly parsed HOT 1
- Tinker broken in laravel 9.0.0 HOT 8
- Issue registering StorageLinkCommand HOT 2
- PHP Error: Call to a member function make() on null HOT 5
- Closures not working when using the --execute argument. HOT 1
- stream_wrapper_register(): Protocol hoa:// is already defined in psy/psysh/src/Readline/Hoa/ProtocolWrapper.php:473 HOT 1
- Recoverable fatal error: Object of class Illuminate\Foundation\Application could not be converted to string in Command line code on line 8 HOT 1
- Parse error: Syntax error, unexpected ':' in vendor\psy\psysh\src\Exception\ParseErrorException.php on line 40. HOT 1
- The destructor is not executed HOT 2
- Loop only returns the last value if the curly brackets start on a new line HOT 5
- Output cleared and missing colors after upgrading to Laravel 9 HOT 4
- First time i open tinker, i have to dispatch a job twice to get it pushed to queue HOT 1
- Silent crash when initializing a PDO connection to PostgreSQL HOT 8
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from tinker.