Support the ongoing development of Laravel.io →
Requests Eloquent Queues

hi everybody.

I have function scopeClubBlog at model. But It not working when set namespace. I think can found the model. If don't set namespace , the function can get right result.

#the model

namespace App\Models;

class Blog extends \Eloquent{

    use SoftDeletingTrait;
    
    protected $dates = ['deleted_at'];

    public function scopeClubBlog($query,$clubid)
    {
        return $query->whereClub_id($clubid);
    }
    

    public function content()
    {
        return $this->hasOne('App\Models\BlogContent');
    }

}

#the controller

namespace App\Controllers\Admin;
use App\Models\Blog;
use App\Services\Validators\PageValidator;
use Input, Notification, Redirect, Sentry, Str, Session;

class BlogsController extends \BaseController {
    public function index()
    {
        $clubid = Session::get('clubid');
 
        return \View::make('default.public.default')->with('blogs',Blog::clubBlog($clubid)->get());
    }

#debug info

BadMethodCallException Call to undefined method Illuminate\Database\Query\Builder::clubBlog()

Thank you for read.

Last updated 3 years ago.
0

Did you run composer dump-autoload after adding the namespace?

0

TerrePorter said:

Did you run composer dump-autoload after adding the namespace?

Thank you TerrePorter. I done it, but same as before.

0

A couple things to try,

Eliminate the view to confirm data,

class BlogsController extends \BaseController {
    public function index()
    {
        $clubid = Session::get('clubid');


// dump the db data
         dd( Blog::clubBlog($clubid)->get()->toArray() );

        return \View::make('default.public.default')->with('blogs',Blog::clubBlog($clubid)->get());
    }

Another thing would be the look in the composer autoload and see if it has the model in the list of known classes, vendor/composer/autoload_classmap.php

actually this might be the issue, check the composer.json to make sure it is set to include the models folder in the autoload

"autoload": {
		"classmap": [
			"app/models",
...

0

TerrePorter said:

A couple things to try,

Eliminate the view to confirm data,

class BlogsController extends \BaseController {
   public function index()
   {
       $clubid = Session::get('clubid');


// dump the db data
        dd( Blog::clubBlog($clubid)->get()->toArray() );

       return \View::make('default.public.default')->with('blogs',Blog::clubBlog($clubid)->get());
   }

Another thing would be the look in the composer autoload and see if it has the model in the list of known classes, vendor/composer/autoload_classmap.php

actually this might be the issue, check the composer.json to make sure it is set to include the models folder in the autoload

"autoload": {
  	"classmap": [
  		"app/models",
...

I have checked autoload_classmap.php and found one mistake with 'Blog' model. Thank you very much!

0

Sign in to participate in this thread!

PHPverse

Your banner here too?

shuli1984 shuli1984 Joined 7 May 2015

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.

© 2025 Laravel.io - All rights reserved.