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

Create a folder and put a model file in it. As long as the namespace is correct it should work.

Moving the User model needs a few more changes. Update the namespace in the model file and update the the config\auth.php

I have yet to do this as i'm looking in to repositories.

Here are some links that were posted in another topic related to repositories, http://laravel.io/forum/10-26-2014-laravel-5-where-is-the-models-folder

Here's some resources on the matter:

Edit

I also forgot about this Laracasts video which would be helpful in general as well:

Hope that helps.

0

For example if you create a folder (eg app/Models), there are two ways to move your models:

  1. Laravel5 style = Use PSR4
  • namespace all your model files with napespace App\Models;
  • Access your models anywhere with their full namespace, eg: \App\Models\User::find(1);
  1. Laravel4 style
  • Load your model with composer autoloader. In composer.json add:
    "autoload": {
        "classmap": [
            "database",
            "app/Models"			
        ],
        ...
  • You don't need to namespace your Models. They are in ther root namespace
  • In namespaced files you can access them as \User::find(1);

Matt Stauffer has an excelent post Upgrading from Laravel 4 to Laravel 5

Extra notes:

  • If you change tha nampspace of User model you have to update config\auth.php
  • The easiest way get rid of long napespaces is to import your models in the begining of your php files, For example: use App\Models\User;
Last updated 9 years ago.
0

@igaster Just to make sure I'm thinking correctly.

The Laravel 4 style would require you to do a 'composer dump-autoload', if you added in any new models, right ?

And thanks for the better explanation.

0

Sign in to participate in this thread!

Eventy

Your banner here too?

ottz0 ottz0 Joined 15 Nov 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.