2

I am having troubles using eloquent with Laravel. I am getting an error which I found a lot here on SO but didn't find a solution to it.

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

After searching in the asked questions, it appears everyone omitted the use App/'Model' statement, but I included it in my controller, still getting this error, and I don't know what I am doing wrong

My model:

namespace App;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Support\Facades\DB;

class Activity extends Model
{
    public function covers()
    {
        return $this->belongsToMany('App\Cover');
    }

    public function languages()
    {
        return $this->belongsToMany('App\Language');
    }

}

My controller:

namespace App\Http\Controllers;
use App\Http\Controllers\Controller;
use App\Activity;

class ActivityController extends Controller
{
    public function get_wixer_activities($wid){
        $activities = App\Activity::all();
        dd($activities);
    }
}

I am using Laravel 5.6

2
  • If you have use App\Activity you just need Activity::all. Commented Jul 9, 2018 at 15:51
  • what is location of model. I think you need to put the model in "App" Folder dirtectly Commented Jul 9, 2018 at 15:51

1 Answer 1

6

Because you are importing the Activity class here:

use App\Activity;

It means you can use the Activity class like this:

$activities = Activity::all();

And you don't need the App\Activity.

Sign up to request clarification or add additional context in comments.

1 Comment

Yep, and if you didn't have the use statement, you'd need $activities = \App\Activity::all(); with the leading \.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.