Home > Back-end >  Changing Model Name Laravel
Changing Model Name Laravel

Time:04-30

This is my first day with Laravel. I made a model previously named Title and just before I migrated it I decided to change the name to Blog, and In doing so I changed the migration file to create_blogs_table I also changed the model class and the filename to "Blog" and I migrated it with no problem. However when I ran tinker and I tried to do the simple Blog::all() it gave this error

PHP Error:  Class "Blog" not found in Psy Shell code on line 1

and when I ran Title::all() it gave me this error

[!] Aliasing 'Title' to 'App\Models\Title' for this Tinker session.
<warning>PHP Warning:  include(C:\coding\laravel\laravelcwd\vendor\composer/../../app/Models/Title.php): Failed to open stream: No such file or directory in C:\coding\laravel\laravelcwd\vendor\composer\ClassLoader.php on line 571</warning>
<warning>PHP Warning:  include(): Failed opening 'C:\coding\laravel\laravelcwd\vendor\composer/../../app/Models/Title.php' for inclusion (include_path='C:\coding\xampp\php\PEAR') in C:\coding\laravel\laravelcwd\vendor\composer\ClassLoader.php on line 571</warning>
<warning>PHP Warning:  Class "App\Models\Title" not found in C:\coding\laravel\laravelcwd\vendor\laravel\tinker\src\ClassAliasAutoloader.php on line 109</warning>
PHP Error:  Class "Title" not found in Psy Shell code on line 1

My assumption would be that I didn't change the namespace somewhere in the project. So I checked my models file

<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;

class Blog extends Model
{
    use HasFactory;
}

Can someone please drop an explanation for this it would be really appreciated thank you in advance!

CodePudding user response:

You can run the command composer dump-autoload in your terminal at the root of the project.

This command regenerates the list of all the classes that need to be included in the project (autoload_classmap.php).

  • Related