当前位置: 首页>>代码示例>>PHP>>正文


PHP Str::singular方法代码示例

本文整理汇总了PHP中Illuminate\Support\Str::singular方法的典型用法代码示例。如果您正苦于以下问题:PHP Str::singular方法的具体用法?PHP Str::singular怎么用?PHP Str::singular使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Illuminate\Support\Str的用法示例。


在下文中一共展示了Str::singular方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。

示例1: getSearchType

 /**
  * {@inheritdoc}
  */
 public function getSearchType()
 {
     if (property_exists($this, 'documentType')) {
         return $this->documentType;
     }
     return Str::singular($this->getTable());
 }
开发者ID:phroggyy,项目名称:discover,代码行数:10,代码来源:Discoverable.php

示例2: render

 /**
  * Render the field.
  *
  * @access public
  * @return mixed|string
  */
 public function render()
 {
     switch ($this->getContext()) {
         case BaseField::CONTEXT_LIST:
             $values = [];
             foreach ($this->getValue() as $item) {
                 $values[] = $item->{$this->getDisplayField()};
             }
             return implode(', ', $values);
             break;
         case BaseField::CONTEXT_FORM:
             $baseModel = $this->getAdmin()->getModel();
             $baseModel = new $baseModel();
             $primaryKey = $baseModel->getKeyName();
             $relatedModel = $baseModel->{$this->getName()}()->getRelated();
             $relatedModel = get_class($relatedModel);
             $items = [];
             foreach ($relatedModel::all() as $item) {
                 $items[$item->{$primaryKey}] = $item->{$this->getDisplayField()};
             }
             $id = $this->getAdmin()->getFormBuilder()->getIdentifier();
             $values = [];
             foreach ($relatedModel::where(Str::singular($baseModel->getTable()) . '_id', $id)->get() as $item) {
                 $values[] = (string) $item->{$primaryKey};
             }
             return View::make('krafthaus/bauhaus::models.fields._has_many')->with('field', $this)->with('items', $items)->with('values', $values);
             break;
     }
 }
开发者ID:billwaddyjr,项目名称:bauhaus,代码行数:35,代码来源:HasManyField.php

示例3: getTable

 /**
  * Get the table associated with the model.
  *
  * @return string
  */
 public function getTable()
 {
     if (isset($this->table)) {
         return $this->table;
     }
     return str_replace('\\', '', Str::snake(Str::singular(class_basename($this))));
 }
开发者ID:martinbean,项目名称:eloquent-singular-table-names,代码行数:12,代码来源:SingularTableName.php

示例4: model

 /**
  * Get the model related to the controller.
  *
  * @return string
  */
 public function model()
 {
     $model = $this->getShortName();
     $model = str_replace('Controller', null, $model);
     $model = Str::singular($model);
     return $model;
 }
开发者ID:anahkiasen,项目名称:arrounded,代码行数:12,代码来源:ReflectionController.php

示例5: formatEloquentModel

 /**
  * Format an Eloquent model.
  *
  * @param \Illuminate\Database\Eloquent\Model $model
  *
  * @return string
  */
 public function formatEloquentModel($model)
 {
     $key = Str::singular($model->getTable());
     if (!$model::$snakeAttributes) {
         $key = Str::camel($key);
     }
     return $this->encode([$key => $model->toArray()]);
 }
开发者ID:JamesGuthrie,项目名称:api,代码行数:15,代码来源:Json.php

示例6: loadFixtures

 protected static function loadFixtures()
 {
     $system = new Filesystem();
     foreach ($system->files(__DIR__ . '/../fixtures') as $file) {
         $fixture_name = Str::singular(basename($file, '.php'));
         $fixtures = (require $file);
         static::createFixtures($fixture_name, $fixtures);
     }
 }
开发者ID:dadleyy,项目名称:lvpress,代码行数:9,代码来源:TestCase.php

示例7: setApiName

 public function setApiName($name)
 {
     $this->_api_name = Pluralizer::singular($name);
     $this->_collection_name = Str::studly(Str::singular(Str::slug($this->_api_name, " ")));
     if (!class_exists("AndrewLamers\\Chargify\\" . $this->_collection_name)) {
         eval("namespace Andrewlamers\\Chargify; class " . $this->_collection_name . " extends \\Andrewlamers\\Chargify\\Fluent {}");
     }
     $this->_collection_name = "Andrewlamers\\Chargify\\" . $this->_collection_name;
 }
开发者ID:andrewlamers,项目名称:chargify-php-sdk,代码行数:9,代码来源:Chargify.php

示例8: getResourceOption

 /**
  * Get resource.
  *
  * @return string
  */
 protected function getResourceOption()
 {
     $name = $this->getNameInput();
     $resource = $this->option('resource') ?: $name;
     if (Str::contains($resource, '/')) {
         $segments = explode('/', $resource);
         $resource = is_array($segments) ? end($segments) : $resource;
     }
     return Str::singular($resource);
 }
开发者ID:jenky,项目名称:laravel-generators,代码行数:15,代码来源:LangMakeCommand.php

示例9: getModelsName

 /**
  * get the names of the parent or nested resource
  */
 private function getModelsName($nested = false)
 {
     $classBaseName = class_basename($this);
     $segments = explode('_', snake_case($classBaseName));
     //the last segment should be the string 'controller'
     $modelName = $segments[0];
     $nestedModelName = $segments[1];
     $name = $nested ? $nestedModelName : $modelName;
     return Str::singular($name);
 }
开发者ID:whitegolem,项目名称:laracrud,代码行数:13,代码来源:NestedController.php

示例10: getModel

 /**
  * @param $name
  * @param bool $usePrefix
  *
  * @return bool|ModelEx
  */
 public function getModel($name, bool $usePrefix = false)
 {
     try {
         $prefix = $usePrefix ? defined('MODEL_PREFIX') ? MODEL_PREFIX : 'M' : '';
         $class = $this->normalize($prefix . ucfirst(Str::camel(Str::singular("{$name}"))), defined('MODEL_DIR') ? MODEL_DIR : 'App\\Model');
         return class_exists($class) ? $class : false;
     } catch (\Throwable $e) {
     }
     return false;
 }
开发者ID:minutephp,项目名称:framework,代码行数:16,代码来源:Resolver.php

示例11: generateFields

 private function generateFields()
 {
     $fieldTemplate = $this->commandData->templatesHelper->getTemplate('field.blade', $this->viewsPath);
     $fieldsStr = '';
     foreach ($this->commandData->inputFields as $field) {
         switch ($field['type']) {
             case 'text':
                 $fieldsStr .= FormFieldsGenerator::text($fieldTemplate, $field) . "\n\n";
                 break;
             case 'textarea':
                 $fieldsStr .= FormFieldsGenerator::textarea($fieldTemplate, $field) . "\n\n";
                 break;
             case 'password':
                 $fieldsStr .= FormFieldsGenerator::password($fieldTemplate, $field) . "\n\n";
                 break;
             case 'email':
                 $fieldsStr .= FormFieldsGenerator::email($fieldTemplate, $field) . "\n\n";
                 break;
             case 'file':
                 $fieldsStr .= FormFieldsGenerator::file($fieldTemplate, $field) . "\n\n";
                 break;
             case 'checkbox':
                 $fieldsStr .= FormFieldsGenerator::checkbox($fieldTemplate, $field) . "\n\n";
                 break;
             case 'radio':
                 $fieldsStr .= FormFieldsGenerator::radio($fieldTemplate, $field) . "\n\n";
                 break;
             case 'number':
                 $fieldsStr .= FormFieldsGenerator::number($fieldTemplate, $field) . "\n\n";
                 break;
             case 'date':
                 if ($this->commandData->fromTable) {
                     $fieldsStr .= FormFieldsGenerator::date2($fieldTemplate, $field) . "\n\n";
                 } else {
                     $fieldsStr .= FormFieldsGenerator::date($fieldTemplate, $field) . "\n\n";
                 }
                 break;
             case 'select':
                 if ($this->commandData->fromTable) {
                     $modelName = Str::lower(Str::singular($this->commandData->modelName));
                     $fieldsStr .= FormFieldsGenerator::select2($fieldTemplate, $field, false, $modelName) . "\n\n";
                 } else {
                     $fieldsStr .= FormFieldsGenerator::select($fieldTemplate, $field) . "\n\n";
                 }
                 break;
         }
     }
     $templateData = $this->commandData->templatesHelper->getTemplate('fields.blade', $this->viewsPath);
     $templateData = str_replace('$FIELDS$', $fieldsStr, $templateData);
     $templateData = str_replace('$MODEL_NAME_PLURAL_CAMEL$', $this->commandData->modelNamePluralCamel, $templateData);
     $fileName = 'fields.blade.php';
     $path = $this->path . $fileName;
     $this->commandData->fileHelper->writeFile($path, $templateData);
     $this->commandData->commandObj->info('field.blade.php created');
 }
开发者ID:julioalves,项目名称:laravel-api-generator,代码行数:55,代码来源:ViewGenerator.php

示例12: getTemplateVars

 /**
  * Function to get the minimum template variables
  * 
  * @return array
  */
 public function getTemplateVars()
 {
     $entity = $this->getEntityName();
     $fieldData = $this->getFieldData();
     $instance = Str::singular(Str::snake($entity));
     $cols = array_keys($fieldData);
     $cells = array_map(function ($x) use($instance) {
         return "\${$instance}->{$x}";
     }, $cols);
     return ['Entity' => Str::studly($entity), 'Entities' => Str::plural(Str::studly($entity)), 'collection' => Str::plural(Str::snake($entity)), 'instance' => $instance, 'fields' => $fieldData, 'headings' => $cols, 'cells' => $cells];
 }
开发者ID:julioalves,项目名称:blacksmith,代码行数:16,代码来源:ViewIndex.php

示例13: buildClass

 /**
  * Build the class with the given name.
  *
  * @param string $name
  *
  * @throws \Illuminate\Contracts\Filesystem\FileNotFoundException
  * @return string
  */
 protected function buildClass($name)
 {
     $stub = parent::buildClass($name);
     list($resourceStub, $actionStub) = explode('#split', $stub);
     if ($this->option('model')) {
         $modelClass = Str::singular(str_replace('.', '\\', $this->getNameInput()));
         $resourceStub = str_replace(['DummyModelClass'], [$modelClass], $resourceStub);
         return trim($resourceStub);
     }
     return trim($actionStub);
 }
开发者ID:vampirekiss,项目名称:lumen-restful-starter-kit,代码行数:19,代码来源:ApiMakeCommand.php

示例14: seed

 /**
  * Run a seeder.
  *
  * @param string $table
  */
 public function seed($table)
 {
     $timer = microtime(true);
     $this->command->info('Seeding ' . $table);
     $this->call($table . 'TableSeeder');
     // Log results
     $results = Str::singular($table);
     $results = $this->container['arrounded']->qualifyModel($results);
     if (class_exists($results)) {
         $timer = round(microtime(true) - $timer, 2);
         $this->command->comment(sprintf('-- %s entries created (%ss)', $results::count(), $timer));
     }
 }
开发者ID:anahkiasen,项目名称:arrounded,代码行数:18,代码来源:AbstractSeeder.php

示例15: getTemplateVars

 /**
  * Function to get the minimum template variables
  * 
  * @return array
  */
 public function getTemplateVars()
 {
     $entity = $this->getEntityName();
     $fieldData = $this->getFieldData();
     $form_rows = [];
     foreach ($fieldData as $property => $meta) {
         $display = Str::title(str_replace('_', ' ', $property));
         $result['label'] = "{{ Form::label('{$property}', '{$display}:') }}";
         $elementType = $this->getElementType($meta['type']);
         $result['element'] = "{{ Form::{$elementType}('{$property}') }}";
         $form_rows[] = $result;
     }
     return ['Entity' => Str::studly($entity), 'Entities' => Str::plural(Str::studly($entity)), 'collection' => Str::plural(Str::snake($entity)), 'instance' => Str::singular(Str::snake($entity)), 'fields' => $fieldData, 'form_rows' => $form_rows];
 }
开发者ID:julioalves,项目名称:blacksmith,代码行数:19,代码来源:Form.php


注:本文中的Illuminate\Support\Str::singular方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。