Search
 
SCRIPT & CODE EXAMPLE
 

PHP

Laravel model - CRUD only with records where one column = certain value

<?php
 
namespace AppScopes;
 
use IlluminateDatabaseEloquentBuilder;
use IlluminateDatabaseEloquentModel;
use IlluminateDatabaseEloquentScope;
 
class AdministrationScope implements Scope
{
    /**
     * Apply the scope to a given Eloquent query builder.
     *
     * @param  IlluminateDatabaseEloquentBuilder  $builder
     * @param  IlluminateDatabaseEloquentModel  $model
     * @return void
     */
    public function apply(Builder $builder, Model $model)
    {
        $builder->where('administration', '=', 2);
    }
}

<?php
 
  // model
namespace AppModels;
 
use AppScopesAdministrationScope;
use IlluminateDatabaseEloquentModel;
 
class YourModel extends Model
{
    /**
     * The "booted" method of the model.
     *
     * @return void
     */
    protected static function booted()
    {
        static::addGlobalScope(new AdministrationScope);
    }
}
Comment

PREVIOUS NEXT
Code Example
Php :: virtual fields cakephp 4 
Php :: get count mini cart item total 
Php :: escape class wordpress 
Php :: PHP str_rot13 — Perform the rot13 transform on a string 
Php :: prosedur dan fungsi dengan php 
Php :: php async curl request 
Php :: jupiter/framework/admin/generators/option-generator.php on line 80 
Php :: ifmodule condition in htaccess 
Php :: how to auto calculate price in mysql table and php 
Php :: woocommerce subscriptions custom user rolde 
Php :: php find odd even number in loop 
Php :: can we acces session variable in two files 
Php :: laravel first or with callback 
Php :: propel find index 
Php :: Primary Termlaravel recursive relationships 
Php :: php array_walk_recursive 
Php :: php iterate through objects 
Php :: menggunakan pengkondisian dalam string php 
Php :: warning: parameter 2 to search_by_title() expected to be a reference, value given in 
Php :: modal align center yii2 
Php :: how to call a function in model from a controller 
Php :: get original data without cast laravel 
Php :: call a class in another class php 
Php :: infoplist codepush key 
Php :: correction of controller 
Php :: php if simple 
Php :: add reviews from code site reviews wp 
Php :: get_distance 
Php :: andebol 
Php :: Indexed Array 
ADD CONTENT
Topic
Content
Source link
Name
5+6 =