Support the ongoing development of Laravel.io →
posted 10 years ago
Eloquent
Last updated 2 years ago.
0

You could add in an alias in the app.php...

'aliases' => [
'User'      => 'App\User',
...

I get the object both ways now in 5.0-dev

 php artisan tinker
[1] > (new App\User);
// object(App\User)(
//   'incrementing' => true,
//   'timestamps' => true,
//   'exists' => false
// )
[2] > (new User);
// object(App\User)(
//   'incrementing' => true,
//   'timestamps' => true,
//   'exists' => false
// )

Last updated 2 years ago.
0

TerrePorter said:

You could add in an alias in the app.php...

'aliases' => [
'User'      => 'App\User',
...

I get the object both ways now in 5.0-dev

php artisan tinker
[1] > (new App\User);
// object(App\User)(
//   'incrementing' => true,
//   'timestamps' => true,
//   'exists' => false
// )
[2] > (new User);
// object(App\User)(
//   'incrementing' => true,
//   'timestamps' => true,
//   'exists' => false
// )

#I found autoload solution i add composer.json "app" string

"classmap": [
    ....,
   "app"
]

and delete namespace in app\User.php

and change config/auth.php model=>'App/User' to model=>'User'

Last updated 2 years ago.
0

Not that I know of, as far as I understand namespaces once it has a namespace that is the only way to access it.

You could also do the Use to alias it in the file.

use \App\User as User
Last updated 2 years ago.
0

#I found autoload solution i add composer.json "app" string

"classmap": [
   ....,
  "app"
]

Humm, that didn't work for me.

Anyways, glad you figured it out.

Last updated 2 years ago.
0

TerrePorter said:

#I found autoload solution i add composer.json "app" string

"classmap": [
   ....,
  "app"
]

Humm, that didn't work for me.

Anyways, glad you figured it out.

maybe.. you does not delete namespace in app\User.php

and execute composer dump-autoload -o

anyway very very thanks.

Last updated 2 years ago.
0

This worked for me:

"autoload": {
    ...
    "": [
        "app/Models/"
    ]

(I think it would be app/ if you didn't have Models directory)

then do composer dump-autoload

If you had already namespaced everything just do find and replace to remove your namespace declarations in the models and from in front of model references. (this was easy for us because we were using \App\Models might be harder if your'e using just \App)

Super easy for us! Wish I'd known how easy it was earlier would have saved tons of migration time (we did it half way before trying)

Last updated 7 years ago.
0

Sign in to participate in this thread!

Eventy

Your banner here too?

dbwhddn10 dbwhddn10 Joined 25 Aug 2014

Moderators

We'd like to thank these amazing companies for supporting us

Your logo here?

Laravel.io

The Laravel portal for problem solving, knowledge sharing and community building.

© 2024 Laravel.io - All rights reserved.