I am trying to put a dash inside a class called "Page". I also need to rename the feature function so that it does not interfere with an existing class function. I thought I did all this successfully, however I have an error indicating the wrong location ?!
Call to undefined function App\Pages\Models\myTraitDefaultScope()
I also tried: MyTrait\defaultScope($query) instead of renaming the conflicting function. But I get the following error:
Call to undefined function App\MyTrait\defaultScope()
Below is the attribute and class contained in separate files.
<?php namespace App; use Illuminate\Support\Facades\Auth; trait MyTrait{ public function defaultScope($query){ return $query->where('active', '1') } }
.
<?php namespace Modules\Pages\Models; use Illuminate\Database\Eloquent\Model; use App\MyTrait; class Page extends Model { use MyTrait{ MyTrait::defaultScope as myTraitDefaultScope; } public function defaultScope($query){ return myTraitDefaultScope($query); } }
I'm not so keen on this, so please donโt shoot if I have something bad.
php namespaces class traits laravel
Jammer
source share