本文整理汇总了PHP中Slug::source方法的典型用法代码示例。如果您正苦于以下问题:PHP Slug::source方法的具体用法?PHP Slug::source怎么用?PHP Slug::source使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Slug
的用法示例。
在下文中一共展示了Slug::source方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: setForObject
public static function setForObject($object)
{
$slug_source = Slug::source($object->id);
$instances = DB::table($object->name)->get();
$slugs = [];
foreach ($instances as $instance) {
if ($slug_source === null) {
$slug = Slug::make($instance->created_at->format('Y-m-d'), $slugs);
} else {
$slug = Slug::make($instance->{$slug_source}, $slugs);
}
DB::table($object->name)->where('id', $instance->id)->update(['slug' => $slug]);
$slugs[] = $slug;
}
}
示例2: store
public function store($object_name, $linked_id = false)
{
$object = DB::table(DB_OBJECTS)->where('name', $object_name)->first();
$fields = DB::table(DB_FIELDS)->where('object_id', $object->id)->where('visibility', '<>', 'hidden')->orderBy('precedence')->get();
//metadata
$inserts = array('created_at' => new DateTime(), 'updated_at' => new DateTime(), 'created_by' => Auth::user()->id, 'updated_by' => Auth::user()->id, 'precedence' => DB::table($object->name)->max('precedence') + 1);
//run various cleanup processes on the fields
foreach ($fields as $field) {
if (!in_array($field->type, array('checkboxes', 'images'))) {
$inserts[$field->name] = self::sanitize($field);
}
}
//determine where slug is coming from
if ($slug_source = Slug::source($object->id)) {
$slug_source = Input::get($slug_source);
} else {
$slug_source = date('Y-m-d');
}
//get other values to check uniqueness
$uniques = DB::table($object->name)->lists('slug');
//add unique, formatted slug to the insert batch
$inserts['slug'] = Slug::make($slug_source, $uniques);
//run insert
$instance_id = DB::table($object->name)->insertGetId($inserts);
//handle any checkboxes, had to wait for instance_id
foreach ($fields as $field) {
if ($field->type == 'checkboxes') {
//figure out schema, loop through and save all the checkboxes
$object_column = self::getKey($object->name);
$remote_column = self::getKey($field->related_object_id);
if (Input::has($field->name)) {
foreach (Input::get($field->name) as $related_id) {
DB::table($field->name)->insert(array($object_column => $instance_id, $remote_column => $related_id));
}
}
} elseif ($field->type == 'image') {
DB::table(DB_FILES)->where('id', Input::get($field->name))->update(array('instance_id' => $instance_id));
} elseif ($field->type == 'images') {
$file_ids = explode(',', Input::get($field->name));
$precedence = 0;
foreach ($file_ids as $file_id) {
DB::table(DB_FILES)->where('id', $file_id)->update(array('instance_id' => $instance_id, 'precedence' => ++$precedence));
}
}
}
//update objects table with latest counts
DB::table(DB_OBJECTS)->where('id', $object->id)->update(array('count' => DB::table($object->name)->whereNull('deleted_at')->count(), 'updated_at' => new DateTime(), 'updated_by' => Auth::user()->id));
//clean up any abandoned files
FileController::cleanup();
//return to target
return Redirect::to(Input::get('return_to'));
}