本文整理汇总了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);
}
}
示例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;
}
示例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;
}
示例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);
}
示例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();
}
示例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();
}
}
}
示例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();
}
}
示例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;
}
}
示例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)]);
}
示例10: run
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
Eloquent::unguard();
$this->call('EmployeesTableSeeder');
$this->call('TasksTableSeeder');
$this->call('CategoriesTableSeeder');
}
示例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";
}
}
示例12: run
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
Eloquent::unguard();
//$this->call('UserTableSeeder');
//$this->call('UserGroupSeeder');
$this->call('PostCommentSeeder');
}
示例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'));
}
示例14: save
/**
* @return boolean true
* @throws ValidationException
*/
public function save()
{
$this->isValid();
$this->entity->fill($this->prepareData($this->data));
$this->entity->save();
return true;
}
示例15: save
public function save(array $options = array())
{
parent::save($options);
$scanUser = $this->getScansUserById();
$scanUser->updateTotal();
$scanUser->updateMostRecentScan();
}