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.
TerrePorter said:
Did you run composer dump-autoload after adding the namespace?
Thank you TerrePorter. I done it, but same as before.
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",
...
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!
Sign in to participate in this thread!
The Laravel portal for problem solving, knowledge sharing and community building.
The community