Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

If a model extends base model that extended Eloquent, WithTrashed doesn't work. #5026

Closed
ghost opened this issue Jul 11, 2014 · 3 comments
Closed

Comments

@ghost
Copy link

ghost commented Jul 11, 2014

Example Base Model

class BaseMultiLang extends Eloquent implements MessageProviderInterface  { 

}  

Example Model that extend base model that like is up!

class Page  extends BaseMultiLang implements SluggableInterface {


    use SoftDeletingTrait;
    /**
     * Model Table Name
     * @var string 
     */
    public $table =  'pages';
    .........
}

Now we try to run WithTrashed method on test controller

class testController  extends BaseController{

    public function index (){     

        return var_dump(Page::withTrashed()->get()); /// ErrorException  Undefined index: Page


    }

Debug Screen
screenshot from 2014-07-11 21 47 45

Trace

  1. ErrorException
    …/­vendor/­laravel/­framework/­src/­Illuminate/­Database/­Eloquent/­Model.php346
  2. Illuminate\Exception\Handler handleError
    …/­vendor/­laravel/­framework/­src/­Illuminate/­Database/­Eloquent/­Model.php346
  3. Illuminate\Database\Eloquent\Model getGlobalScope
    …/­vendor/­laravel/­framework/­src/­Illuminate/­Database/­Eloquent/­Model.php1700
  4. Illuminate\Database\Eloquent\Model newQueryWithoutScope
    …/­vendor/­laravel/­framework/­src/­Illuminate/­Database/­Eloquent/­SoftDeletingTrait.php113
  5. Page withTrashed
    …/­app/­controllers/­testController.php15
  6. testController index
    <#unknown>0
  7. call_user_func_array
    …/­vendor/­laravel/­framework/­src/­Illuminate/­Routing/­Controller.php231
  8. Illuminate\Routing\Controller callAction
    …/­vendor/­laravel/­framework/­src/­Illuminate/­Routing/­ControllerDispatcher.php93
  9. Illuminate\Routing\ControllerDispatcher call
    …/­vendor/­laravel/­framework/­src/­Illuminate/­Routing/­ControllerDispatcher.php62
  10. Illuminate\Routing\ControllerDispatcher dispatch
    …/­vendor/­laravel/­framework/­src/­Illuminate/­Routing/­Router.php930
  11. Illuminate\Routing\Router Illuminate\Routing{closure}
    <#unknown>0
  12. call_user_func_array
    …/­vendor/­laravel/­framework/­src/­Illuminate/­Routing/­Route.php105
  13. Illuminate\Routing\Route run
    …/­vendor/­laravel/­framework/­src/­Illuminate/­Routing/­Router.php996
  14. Illuminate\Routing\Router dispatchToRoute
    …/­vendor/­laravel/­framework/­src/­Illuminate/­Routing/­Router.php964
  15. Illuminate\Routing\Router dispatch
    …/­vendor/­laravel/­framework/­src/­Illuminate/­Foundation/­Application.php738
  16. Illuminate\Foundation\Application dispatch
    …/­vendor/­laravel/­framework/­src/­Illuminate/­Foundation/­Application.php708
  17. Illuminate\Foundation\Application handle
    …/­vendor/­laravel/­framework/­src/­Illuminate/­Session/­Middleware.php72
  18. Illuminate\Session\Middleware handle
    …/­vendor/­laravel/­framework/­src/­Illuminate/­Cookie/­Queue.php47
  19. Illuminate\Cookie\Queue handle
    …/­vendor/­laravel/­framework/­src/­Illuminate/­Cookie/­Guard.php51
  20. Illuminate\Cookie\Guard handle
    …/­vendor/­stack/­builder/­src/­Stack/­StackedHttpKernel.php23
  21. Stack\StackedHttpKernel handle
    …/­vendor/­laravel/­framework/­src/­Illuminate/­Foundation/­Application.php606
  22. Illuminate\Foundation\Application run
    …/­public/­index.php49

I'm programmer in six month. I'm not sure but there is a bug on line 322 in Laravel Model class. That addGlobalScope method doesn't work correctly!

My native language is not English. I'm sorry my explaining

@ghost
Copy link
Author

ghost commented Jul 11, 2014

In addition WithTrashed method works on UnitTests perfectly but it doesn't work on a controller or a model. This is strange.
Such as

class PageModelTest extends TestCase {
    public function testSimpleSoftDelete() {

        $model = Page::withTrashed()->get();// no exception


    }
}

@taylorotwell
Copy link
Member

Are you extend boot and not calling the parent boot method?

@ghost
Copy link
Author

ghost commented Jul 11, 2014

No.. I have never extend boot method. But your question helps me to find the issue !

// BaseMultiLang

    public function __construct(array $attributes = array()) {

        if (empty($attributes)) {

            return; // this line causes what withTrashed doesn't work !!
        } 

        $WithoutTranslationFileds = $this->Starter($attributes);


        parent::__construct($WithoutTranslationFileds);
    }

Thank you for your feedback :)

@ghost ghost closed this as completed Jul 11, 2014
This issue was closed.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant