Laravel 4: How to apply a WHERE condition to all queries of an Eloquent class?

前端 未结 3 1861
我在风中等你
我在风中等你 2021-02-02 16:55

I\'m trying to implement an \"approved\' state for a table I have, it\'s pretty straightforward, basically, if the row\'s approve column equals 1; that row should be retrieved,

3条回答
  •  慢半拍i
    慢半拍i (楼主)
    2021-02-02 17:28

    You can use global scope for your need, docs for that are here : https://laravel.com/docs/5.6/eloquent#query-scopes

    Good example is SoftDeletingScope which is applied to all queries by default on models which use SoftDeletes trait.

提交回复
热议问题