本文整理汇总了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());
}
示例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;
}
}
示例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))));
}
示例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;
}
示例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()]);
}
示例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);
}
}
示例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;
}
示例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);
}
示例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);
}
示例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;
}
示例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');
}
示例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];
}
示例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);
}
示例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));
}
}
示例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];
}