當前位置: 首頁>>代碼示例>>PHP>>正文


PHP Eloquent類代碼示例

本文整理匯總了PHP中Eloquent的典型用法代碼示例。如果您正苦於以下問題:PHP Eloquent類的具體用法?PHP Eloquent怎麽用?PHP Eloquent使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。


在下文中一共展示了Eloquent類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的PHP代碼示例。

示例1: filterQuery

 /**
  * 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);
     }
 }
開發者ID:ajb,項目名稱:rfpez,代碼行數:15,代碼來源:Bool.php

示例2: hasColumn

 /**
  * 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;
 }
開發者ID:assurrussa,項目名稱:grid-view-vue,代碼行數:15,代碼來源:Model.php

示例3: format_message

 /**
  * 格式化表單校驗消息
  *
  * @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;
 }
開發者ID:ycms,項目名稱:framework,代碼行數:14,代碼來源:YCMS.php

示例4: to_array

/**
 * 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);
}
開發者ID:reith2004,項目名稱:domain,代碼行數:15,代碼來源:helpers.php

示例5: __construct

 /**
  * 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();
 }
開發者ID:maurob45,項目名稱:eloquentdatatables,代碼行數:16,代碼來源:EloquentManager.php

示例6: validateOwnership

 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();
         }
     }
 }
開發者ID:aaronbullard,項目名稱:litmus,代碼行數:10,代碼來源:BaseController.php

示例7: upload

 /**
  * 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();
     }
 }
開發者ID:LavaLite,項目名稱:framework,代碼行數:19,代碼來源:Filer.php

示例8: validate

 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;
     }
 }
開發者ID:AlexCW,項目名稱:LaravelUserApp,代碼行數:13,代碼來源:ValidationObserver.php

示例9: run

 /**
  * 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)]);
 }
開發者ID:skinuxgeek,項目名稱:NewsWise,代碼行數:12,代碼來源:WritersTableSeeder.php

示例10: run

 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     Eloquent::unguard();
     $this->call('EmployeesTableSeeder');
     $this->call('TasksTableSeeder');
     $this->call('CategoriesTableSeeder');
 }
開發者ID:gerry411,項目名稱:MatasTasklist,代碼行數:12,代碼來源:DatabaseSeeder.php

示例11: run

 /**
  * 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";
     }
 }
開發者ID:dwbfox,項目名稱:pasteboard,代碼行數:34,代碼來源:DatabaseSeeder.php

示例12: run

 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     Eloquent::unguard();
     //$this->call('UserTableSeeder');
     //$this->call('UserGroupSeeder');
     $this->call('PostCommentSeeder');
 }
開發者ID:rituzy,項目名稱:iblog,代碼行數:12,代碼來源:DatabaseSeeder.php

示例13: run

 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'));
 }
開發者ID:RetinaInc,項目名稱:booking-app,代碼行數:26,代碼來源:BookingTimesTableSeeder.php

示例14: save

 /**
  * @return boolean true
  * @throws ValidationException
  */
 public function save()
 {
     $this->isValid();
     $this->entity->fill($this->prepareData($this->data));
     $this->entity->save();
     return true;
 }
開發者ID:iscnorena,項目名稱:report,代碼行數:11,代碼來源:BaseManager.php

示例15: save

 public function save(array $options = array())
 {
     parent::save($options);
     $scanUser = $this->getScansUserById();
     $scanUser->updateTotal();
     $scanUser->updateMostRecentScan();
 }
開發者ID:p-tricky,項目名稱:CAEWeb,代碼行數:7,代碼來源:Scan.php


注:本文中的Eloquent類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。