User: qixieyu Date: 15-7-3 Time: 下午8:41
Inheritance: extends Db
Beispiel #1
0
 /**
  * Filters a query object
  *
  * @param Query		$query
  * @param Eloquent	$model
  *
  * @return void
  */
 public function filterQuery(&$query, $model)
 {
     //if the field is
     if ($this->value !== '') {
         $query->where($model->table() . '.' . $this->field, '=', $this->value);
     }
 }
Beispiel #2
0
 /**
  * @return boolean true
  * @throws ValidationException
  */
 public function save()
 {
     $this->isValid();
     $this->entity->fill($this->prepareData($this->data));
     $this->entity->save();
     return true;
 }
Beispiel #3
0
 /**
  * Check if model's table has column
  *
  * @param \Eloquent $model
  * @param string $column
  * @return bool
  */
 public static function hasColumn($model, $column)
 {
     $table = $model->getTable();
     $columns = \Cache::remember('amigridview.columns.' . $table, 60, function () use($table) {
         return \Schema::getColumnListing($table);
     });
     return array_search($column, $columns) !== false;
 }
Beispiel #4
0
 /**
  * 格式化表单校验消息
  *
  * @param  array $messages 未格式化之前数组
  * @return string 格式化之后字符串
  */
 public static function format_message(\Eloquent $messages)
 {
     $reason = ' ';
     foreach ($messages->all('<span class="text_error">:message</span>') as $message) {
         $reason .= $message . ' ';
     }
     return $reason;
 }
Beispiel #5
0
/**
 * Transform Eloquent models to a JSON object.
 *
 * @param  Eloquent|array  $models
 * @return object
 */
function to_array($models)
{
    if ($models instanceof Laravel\Database\Eloquent) {
        return $models->to_array();
    }
    return array_map(function ($m) {
        return $m->to_array();
    }, $models);
}
 /**
  * EloquentManager constructor.
  *
  * @param Builder|\Eloquent $model
  * @param Request $request
  */
 public function __construct($model, Request $request)
 {
     $this->response = new DataTable();
     $this->query = $model instanceof Builder ? $model : $model->getQuery();
     $this->request = $request;
     //        $this->columns    = $this->query->columns;
     $this->connection = $model->getConnection();
     $this->prefix = $this->connection->getTablePrefix();
     $this->database = $this->connection->getDriverName();
 }
Beispiel #7
0
 protected function validateOwnership(Eloquent $model)
 {
     // Validate correct resource
     if ($model_id = Request::segment(2)) {
         $count = $model->where('id', $model_id)->where('user_id', Auth::id())->count();
         if ($count === 0) {
             return $this->respondNotFound();
         }
     }
 }
Beispiel #8
0
 /**
  * Upload files and save to the table.
  *
  * @param Eloquent $model
  *
  * @return null
  */
 public function upload($model)
 {
     if (empty($model->uploads)) {
         return;
     }
     if (isset($model->uploads['single'])) {
         $model->uploadSingle();
     }
     if (isset($model->uploads['multiple'])) {
         $model->uploadMultiple();
     }
 }
 public function validate(\Eloquent $model)
 {
     $additional_data = $this->getAdditionalData();
     $this->validator->setData(array_merge($model->getAttributes(), is_array($additional_data) ? $additional_data : array()));
     $this->setConditionalRules($model);
     if ($this->validator->fails()) {
         //Here we set any validation error responses to the error field on the model.
         $model->setAttribute('errors', $this->validator->errors());
         return $model;
     } else {
         return $model;
     }
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $faker = Faker::Create();
     $name = $faker->name;
     Eloquent::unguard();
     Writers::create(['name' => $name, 'bio' => 'This is just a sample Writer. There is nothing to say here!', 'image' => '/images/writers/SampleWriter.jpg', 'slug' => str_replace(' ', '-', $name)]);
 }
Beispiel #11
0
 public function save(array $options = array())
 {
     parent::save($options);
     $scanUser = $this->getScansUserById();
     $scanUser->updateTotal();
     $scanUser->updateMostRecentScan();
 }
Beispiel #12
0
 public static function boot()
 {
     parent::boot();
     static::created(function ($topic) {
         SiteStatus::newTopic();
     });
 }
 /**
  * Deletes a blog post and all
  * the associated comments.
  *
  * @return bool
  */
 public function delete()
 {
     // Delete the comments
     $this->comments()->delete();
     // Delete the blog post
     return parent::delete();
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     Eloquent::unguard();
     $this->call('EmployeesTableSeeder');
     $this->call('TasksTableSeeder');
     $this->call('CategoriesTableSeeder');
 }
Beispiel #15
0
 public static function boot()
 {
     parent::boot();
     if (!static::$logActivities) {
         return true;
     }
     // Attach to created event
     static::created(function ($model) {
         Activity::log(['contentId' => $model->id, 'contentType' => get_class($model), 'action' => 'Created', 'description' => 'Created ' . get_class($model)]);
     });
     static::deleted(function ($model) {
         Activity::log(['contentId' => $model->id, 'contentType' => get_class($model), 'action' => 'Deleted', 'description' => 'Deleted ' . get_class($model)]);
     });
     static::updating(function ($model) {
         $details = '';
         // Get changes in model
         foreach ($model->getDirty() as $attribute => $value) {
             $original = $model->getOriginal($attribute);
             $details .= "{$attribute}: from '{$original}' to '{$value}'\r\n";
         }
         // Do not log if there's no changes
         if (!empty($details)) {
             Activity::log(['contentId' => $model->id, 'contentType' => get_class($model), 'action' => 'Updated', 'description' => 'Updated ' . get_class($model), 'details' => trim($details)]);
         }
     });
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     Eloquent::unguard();
     $this->call('RangeCronJobsTableSeeder');
     $this->call('UserMgmtTablesSeeder');
     $this->call('AddTypesTableSeeder');
 }
Beispiel #17
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     Eloquent::unguard();
     $this->call('RolesTableSeeder');
     $this->call('SedesTableSeeder');
     $this->call('UsuariosTableSeeder');
 }
Beispiel #18
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     Eloquent::unguard();
     DB::table('tags')->truncate();
     //DB::table('pastes')->truncate();
     $faker = Faker\Factory::create();
     $paste_count = 10;
     $tags = array('php', 'javascript', 'ruby', 'js', 'cpp', 'c++', 'c#', 'go', 'html', 'css');
     for ($i = 0; $i < $paste_count; $i++) {
         $tags_per_paste = rand(1, 3);
         // Generate the paste
         $examplePaste = new Paste();
         $examplePaste->paste = $faker->paragraph;
         $examplePaste->title = $faker->realText(46);
         $examplePaste->expire = $faker->dateTime($max = 'now');
         $examplePaste->token = Str::random(40);
         $examplePaste->private = rand(0, 1);
         $examplePaste->delete_token = Str::random(40);
         $examplePaste->save();
         // Attach some tags to the new paste
         for ($i = 0; $i < $tags_per_paste; ++$i) {
             $exampleTag = new Tag();
             $exampleTag->tag = $tags[rand(0, sizeof($tags) - 1)];
             $exampleTag->paste_id = $examplePaste->id;
             $examplePaste->tags()->save($exampleTag);
         }
         print "Seeded paste with ID of " . $examplePaste->id . "\n";
     }
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     Eloquent::unguard();
     $this->call('InvoiceTableSeeder');
     $this->call('InvoiceItemTableSeeder');
     $this->call('BookTableSeeder');
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     Eloquent::unguard();
     $this->call('UsersTableSeeder');
     $this->call('PostsTableSeeder');
     $this->call('FavoritesTableSeeder');
 }
Beispiel #21
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     Eloquent::unguard();
     //$this->call('UserTableSeeder');
     //$this->call('UserGroupSeeder');
     $this->call('PostCommentSeeder');
 }
 public static function boot()
 {
     parent::boot();
     static::deleting(function ($photo) {
         $photo->galleries()->detach($photo->id);
         return true;
     });
     static::deleted(function ($photo) {
         unlink(public_path() . \Config::get('laravel-photogallery::upload_dir') . '/' . $photo->path);
         $destination = public_path() . \Config::get('laravel-photogallery::upload_dir') . "/";
         $formats = \Config::get('laravel-photogallery::formats');
         foreach ($formats as $name => $format) {
             unlink($destination . $name . '/' . $photo->path);
         }
     });
     static::created(function ($photo) {
         $destination = public_path() . \Config::get('laravel-photogallery::upload_dir') . "/";
         $orig = $destination . $photo->path;
         $img = \Image::make($orig);
         $formats = \Config::get('laravel-photogallery::formats');
         foreach ($formats as $name => $format) {
             $img->resize($format['w'], $format['h'], function ($constraint) {
                 $constraint->aspectRatio();
             });
             $img->save($destination . $name . '/' . $photo->path, $format['q']);
         }
     });
 }
 public function run()
 {
     Eloquent::unguard();
     // DB::table('packages')->delete();
     $currentDate = date('Y-m-d');
     BookingTimes::create(array('booking_date' => date('Y-m-d', strtotime($currentDate . ' + 5 days')), 'booking_time' => '01:00'));
     BookingTimes::create(array('booking_date' => date('Y-m-d', strtotime($currentDate . ' + 5 days')), 'booking_time' => '23:00'));
     BookingTimes::create(array('booking_date' => date('Y-m-d', strtotime($currentDate . ' + 10 days')), 'booking_time' => '13:00'));
     BookingTimes::create(array('booking_date' => date('Y-m-d', strtotime($currentDate . ' + 10 days')), 'booking_time' => '14:00'));
     BookingTimes::create(array('booking_date' => date('Y-m-d', strtotime($currentDate . ' + 11 days')), 'booking_time' => '13:00'));
     BookingTimes::create(array('booking_date' => date('Y-m-d', strtotime($currentDate . ' + 11 days')), 'booking_time' => '16:00'));
     BookingTimes::create(array('booking_date' => date('Y-m-d', strtotime($currentDate . ' + 12 days')), 'booking_time' => '10:00'));
     BookingTimes::create(array('booking_date' => date('Y-m-d', strtotime($currentDate . ' + 12 days')), 'booking_time' => '14:00'));
     BookingTimes::create(array('booking_date' => date('Y-m-d', strtotime($currentDate . ' + 13 days')), 'booking_time' => '16:00'));
     BookingTimes::create(array('booking_date' => date('Y-m-d', strtotime($currentDate . ' + 13 days')), 'booking_time' => '17:00'));
     BookingTimes::create(array('booking_date' => date('Y-m-d', strtotime($currentDate . ' + 14 days')), 'booking_time' => '13:00'));
     BookingTimes::create(array('booking_date' => date('Y-m-d', strtotime($currentDate . ' + 14 days')), 'booking_time' => '11:00'));
     BookingTimes::create(array('booking_date' => date('Y-m-d', strtotime($currentDate . ' + 15 days')), 'booking_time' => '12:00'));
     BookingTimes::create(array('booking_date' => date('Y-m-d', strtotime($currentDate . ' + 15 days')), 'booking_time' => '13:00'));
     BookingTimes::create(array('booking_date' => date('Y-m-d', strtotime($currentDate . ' + 16 days')), 'booking_time' => '16:00'));
     BookingTimes::create(array('booking_date' => date('Y-m-d', strtotime($currentDate . ' + 16 days')), 'booking_time' => '19:00'));
     BookingTimes::create(array('booking_date' => date('Y-m-d', strtotime($currentDate . ' + 17 days')), 'booking_time' => '13:00'));
     BookingTimes::create(array('booking_date' => date('Y-m-d', strtotime($currentDate . ' + 17 days')), 'booking_time' => '14:00'));
     BookingTimes::create(array('booking_date' => date('Y-m-d', strtotime($currentDate . ' + 17 days')), 'booking_time' => '15:00'));
     BookingTimes::create(array('booking_date' => date('Y-m-d', strtotime($currentDate . ' + 17 days')), 'booking_time' => '16:00'));
 }
Beispiel #24
0
 /**
  * 设置 Model 类型对象
  *
  * @param Model $model
  */
 public function setModelObject(Model $model)
 {
     $config = $model->getConnection();
     self::$table = $config['tablename'];
     $this->setConfig($config);
     self::$model = $model;
 }
Beispiel #25
0
 public function newPivot(Eloquent $parent, array $attributes, $table, $exists)
 {
     if ($parent instanceof Tratamientos) {
         return new PresupuestoTratamiento($parent, $attributes, $table, $exists);
     }
     return parent::newPivot($parent, $attributes, $table, $exists);
 }
Beispiel #26
0
 /**
  * Listen for save event
  */
 protected static function boot()
 {
     parent::boot();
     static::saving(function ($model) {
         return $model->validate();
     });
 }
Beispiel #27
0
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     Eloquent::unguard();
     $this->call(UserTableSeeder::class);
     $tbis->call(EventsTableSeeder::class);
     Eloquent::reguard();
 }
Beispiel #28
0
 public function run()
 {
     Eloquent::unguard();
     DB::table('years')->delete();
     Year::create(['id' => 1, 'year' => 2015, 'nombre_colegio' => 'LICEO ADVENTISTA LIBERTAD', 'abrev_colegio' => 'LAL', 'nota_minima_aceptada' => 70, 'resolucion' => 'RESOLUCIÓN 2563 DE 2014', 'actual' => true, 'alumnos_can_see_notas' => true]);
     $this->command->info("Año 2014 y 2015 agregados.");
     /* OTRA FORMA ********************************************************************
     		// Abrimos el archivo donde tengo los municipios restantes de Colombia
     		// recorremos los registros y los ingresamos a la base de datos
     		$this->command->info("Leemos los csv para las cuidades colombianas faltantes...");
     
     		$csv = dirname(__FILE__) .'/SqlTables/CuidadesDeColombia.csv'; 
     		$file_handle = fopen($csv, "r");
     
     		while (!feof($file_handle)) {
     		    $line = fgetcsv($file_handle);
     
     		    if (empty($line)) {
     		        continue; // skip blank lines
     		    }
     
     		    $c = array();
     		    $c['nombre']		= $line[0];
     		    $c['pais_codigo']	= $line[1];
     		    $c['distrito']		= $line[2];
     		    $c['poblacion']		= $line[3];
     
     		    //$this->command->info( implode(",", $c));
     		    DB::table('ciudads')->insert($c);
     		}
     		fclose($file_handle);
     */
 }
Beispiel #29
0
 public static function boot()
 {
     parent::boot();
     static::deleted(function ($user) {
         SocialProfile::destroy($user->socialProfiles->lists('id'));
     });
 }
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     Eloquent::unguard();
     $this->call('UserSeeder');
     // $this->call('TransportasiSeeder');
     // $this->call('PasanganSeeder');
 }