Error:Class 'App\Http\Controllers\App\Model' not found?

0 votes

Here is the Tag model

<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Tag extends Model
{
    protected $fillable = ['page_list_id', 'page_list_tag_id'];

    protected $with = ['tag'];

    public function tag()
    {
        return $this->belongsTo('App\PageListTag', 'page_list_tag_id', 'id');
    }
}

When I run my app I am getting the following error

Class 'App\Http\Controllers\App\Tag' not found

What am I doing wrong in my code?

Apr 3 in Laravel by kartik
• 26,540 points
2,730 views

2 answers to this question.

0 votes

Hello,

In your code you're resolving the Tag class as follows

use App\Tag; // <-- This is right

But in your method you're calling

$pages->tags()->saveMany([
    new App\Tag(), // <-- And this is wrong!
    new App\Tag(),
]);

You simply have to call new Tag() since the use at the top of your file has already included the class.

Otherwise PHP will try to resolve the class from the current namespace. That's why it's throwing

Class 'App\Http\Controllers\App\Tag' not found

Hope this work!!

Thank YoU!

answered Apr 3 by Niroj
• 57,260 points
0 votes

Class ‘App\Http\Controllers\Auth’ Not Found

in Class ‘App\Http\Controllers\Auth’ not found Resolve Error for Go to YourCustomController after that add use Auth; at the top on the Controller Page.


Solution For “Class ‘App\Http\Controllers\Auth’ Not Found”

use Auth; 
// Illuminate\Support\Facades\Auth

//or try it

use Illuminate\Support\Facades\Auth;
The solution posted by github user aliwesome seemed to be that you must use Auth Facade in Admin\Auth\LoginController

add this line :use Illuminate\Support\Facades\Auth;

This issue was posted on the github repo you reference. 

answered Aug 6 by pakainfo

Does this trick works for you??

Related Questions In Laravel

0 votes
1 answer

Artisan migration error “Class 'Doctrine\\DBAL\\Driver\\PDOMySql\\Driver' not found”?

Hello @kartik, This message shows up if you ...READ MORE

answered Apr 6 in Laravel by Niroj
• 57,260 points
449 views
0 votes
1 answer

Error:Laravel PHP Command Not Found

Hello @kartik, Try the follwing snippet: nano ~/.bash_profile And ...READ MORE

answered Jul 30 in Laravel by Niroj
• 57,260 points
508 views
0 votes
1 answer

Error:ReflectionException: Class ClassName does not exist - Laravel

Hello @kartik, Perform a composer update, then composer dump-autoload. If the ...READ MORE

answered Aug 11 in Laravel by Niroj
• 57,260 points
82 views
0 votes
1 answer

Why it is necessary to refresh CSRF token per form request?

Hello, Generating a new CSRF token for each ...READ MORE

answered Mar 19 in Laravel by Niroj
• 57,260 points
751 views
0 votes
1 answer

What is meant by passing the variable by value and reference in PHP?

Hello, When the variable is passed as value ...READ MORE

answered Mar 27 in PHP by Niroj
• 57,260 points
113 views
0 votes
1 answer

Connection with MySQL server using PHP. How can we do that?

Hey @kartik, You have to provide MySQL hostname, ...READ MORE

answered Mar 27 in PHP by Niroj
• 57,260 points
80 views
0 votes
1 answer

How to retrieve or obtain data from the MySQL database using PHP?

Hello kartik,  Actually there are many functions that  ...READ MORE

answered Mar 27 in PHP by Niroj
• 57,260 points
90 views
0 votes
1 answer

Error:Class 'App\Http\Controllers\Model' not found

Hello @kartik, You need to import your model ...READ MORE

answered Sep 11 in Laravel by Niroj
• 57,260 points
22 views
+1 vote
1 answer

Error:Class '\App\User' not found in Laravel when changing the namespace in Laravel?

Hello @kartik Go to config/auth.php and change App\User:class ...READ MORE

answered Apr 3 in Laravel by Niroj
• 57,260 points
3,157 views