Error in the Eloquent concept and namespaces

0

I am developing an application with laravel 5.3

THE application changes the name App to MyApp with artisan

Everything works fine except when I went to use an eloquent model, for example User

composer.json

...
"psr-4": {
            "Cprsync\": "app/",
            "Abkrim\Rbackcp\": "vendor/abkrim/rbackcp/src/",
            "Abkrim\Tools\": "vendor/abkrim/tools/src/"
        }
...

app / Console / Commands / CpMyCommand.app

...
namespace Cprsync\Console\Commands;

// Some code
$cpanel = new Cpanel() // Llama a una Clase bajo namespace vendor/abkrim/rbackcp/src/; 
$cpanel->setUserList;
...

vendor / abkrim / rbackcp / src / Cpanel.php

<?php
namespace Abkrim\Rbackcp;

use Illuminate\Support\Facades\App;
use Log;
use SSH;
use Cprsync\User; // De acuerdo a https://laravel.com/docs/5.3/eloquent#retrieving-models

...
private $users;
...

...
public function setUserList()
    {
        // Some code update private $users
        $this->users = json_decode($this->getUserList(),true);

        $this->updateUsers();
    }

private function updateUSers()
{
    $users_cpanel = $this->users;

    $users = User:all(); // para coger todos los usuarios que existen en mi tabla de usuarios
    // Aqui se produce el error. 
 } 

Error

[Symfony\Component\Debug\Exception\FatalThrowableError]  
      Class 'Abkrim\Rbackcp\User' not found 

If I return everything to the state of calling my app, in the original App (rerunning php app:name App if it works.

What is my mistake?

    
asked by abkrim 26.10.2016 в 09:54
source

2 answers

0

If you say that you get an error when calling a Model, it must be that you have an outdated namespace. By default when using the command the namespace of the classes should be updated within the app folder, but it would ensure that% of use of when you have imported models in other classes to use them.

Even so, it would be good to show us the error that it gives you, surely it contains more information to help solve it.

If you work in Sublime Text, you can do for example Ctrl + Mayus + F to search for a text string. Find App\User in the entire project directory after changing the name to MyApp . If you find matches, they will be files that have not been updated and you will have to change those matches to MyApp\User . Keep in mind that this can happen for each model, although the User is usually the most problematic to come by defecte and have references in various places.

    
answered by 26.10.2016 в 11:39
0

In fact, you're calling the class:

Abkrim\Rbackcp\User

when you have declared with:

use Cprsync\User;

Try to call him with:

$users = \Cprsync\User:all();

or what you want:

$users = \Abkrim\Rbackcp\User::all();
    
answered by 26.10.2016 в 18:06