本文整理汇总了PHP中Illuminate\Support\Str::snake方法的典型用法代码示例。如果您正苦于以下问题:PHP Str::snake方法的具体用法?PHP Str::snake怎么用?PHP Str::snake使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Support\Str
的用法示例。
在下文中一共展示了Str::snake方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: initVariables
public function initVariables()
{
$this->modelNamePlural = Str::plural($this->modelName);
$this->tableName = strtolower(Str::snake($this->modelNamePlural));
$this->modelNameCamel = Str::camel($this->modelName);
$this->modelNamePluralCamel = Str::camel($this->modelNamePlural);
$this->modelNamespace = Config::get('generator.namespace_model', 'App') . "\\" . $this->modelName;
}
示例2: getForeignKey
/**
* Get the default foreign key name for the model.
*
* @return string
*/
public function getForeignKey()
{
if (empty($this->foreignKey)) {
return Str::snake(class_basename($this)) . '_id';
}
return $this->foreignKey;
}
示例3: getNamespace
/**
* Get the package namespace.
*
* @return string
*/
public function getNamespace()
{
$namespace = str_replace('\\', '/', get_class($this));
$namespace = Str::snake(basename($namespace));
$namespace = str_replace('_', '-', $namespace);
return $namespace;
}
示例4: autoRoute
/**
* Controller Auto-Router
*
* @param string $controller eg. 'Admin\\UserController'
* @param array $request_methods eg. array('get', 'post', 'put', 'delete')
* @param string $prefix eg. admin.users
* @param array $disallowed eg. array('private_method that starts with one of request methods)
* @return Closure
*/
public static function autoRoute($controller, $request_methods, $disallowed = array(), $prefix = '')
{
return function () use($controller, $prefix, $disallowed, $request_methods) {
//get all defined functions
$methods = get_class_methods(App::make($controller));
//laravel methods to disallow by default
$disallowed_methods = array('getBeforeFilters', 'getAfterFilters', 'getFilterer');
//build list of functions to not allow
if (is_array($disallowed)) {
$disallowed_methods = array_merge($disallowed_methods, $disallowed);
}
//if there is a index method then lets just bind it and fill the gap in route_names
if (in_array('getIndex', $methods)) {
Lara::fillRouteGaps($prefix, $controller . '@getIndex');
}
//over all request methods, get, post, etc
foreach ($request_methods as $type) {
//filter functions that starts with request method and not in disallowed list
$actions = array_filter($methods, function ($action) use($type, $disallowed_methods) {
return Str::startsWith($action, $type) && !in_array($action, $disallowed_methods);
});
foreach ($actions as $action) {
$controller_route = $controller . '@' . $action;
// Admin\\Controller@get_login
$url = Str::snake(str_replace($type, '', $action));
// login; snake_case
//double check and dont bind to already bound gaps filled index
if (in_array($action, $methods) && $action !== 'getIndex') {
$route = str_replace('..', '.', $prefix . '.' . Str::snake($action));
Route::$type($url, array('as' => $route, 'uses' => $controller_route));
}
}
}
};
}
示例5: getPrefix
private function getPrefix()
{
$raw = get_called_class();
$raw = str_replace($this->removePrefix(), '', $raw);
$raw = Str::snake($raw, '_');
$raw = str_replace('\\_', '.', $raw);
return $this->prefixFixer($raw);
}
示例6: getCollectionName
/**
* Get the collection associated with the model.
*
* @return string
*/
public function getCollectionName()
{
if (static::$collection) {
return static::$collection;
}
return str_replace('\\', '', Str::snake(Str::plural(class_basename($this))));
}
示例7: fire
/**
* Execute the console command.
*
* @return mixed
*/
public function fire()
{
$model = ucfirst(strtolower($this->argument('model')));
$models = Str::plural($model);
$table = strtolower(Str::snake($models));
$modelsLower = strtolower($models);
$fields = $this->getInputFields();
$modelGen = Generator::get('model')->make(['name' => $model, 'namespace' => 'App\\Models', 'table' => $table, 'fields' => $fields]);
$this->info("\nModel Created:");
$this->comment($modelGen);
$controllerGen = Generator::get('controller')->make(['name' => $model, 'namespace' => 'App\\Http\\Controllers', 'modelsLower' => $modelsLower]);
$this->info("\nController Created:");
$this->comment($controllerGen);
$this->info("\nRoute Added:");
$this->comment($modelsLower);
// $viewGen = Generator::get('view')->make([
// 'name' => $model,
// 'modelsLower' => $modelsLower,
// 'models' => $models,
// ]);
// $this->info("\nView Created :");
// $this->comment($modelsLower);
$migrationGen = Generator::get('migration')->make(['models' => $models, 'table' => $table, 'fields' => $fields]);
$this->info("\nMigration Created:");
$this->comment($migrationGen);
$formGen = Generator::get('form')->make(['name' => $model, 'models' => $models, 'fields' => $fields, 'namespace' => 'App\\Forms']);
$this->info("\nForm Created:");
$this->comment($formGen);
}
示例8: makeMigration
/**
* Create migration file if not null
*
* @param $option
*/
private function makeMigration($option)
{
if ($option) {
$table = Str::plural(Str::snake(class_basename($this->argument('name'))));
$this->call('make:migration', ['name' => "create_{$table}_table", '--create' => $table]);
}
}
示例9: getSizeMessage
/**
* {@inheritdoc}
*/
protected function getSizeMessage($attribute, $rule)
{
$lowerRule = Str::snake($rule);
$type = $this->getAttributeType($attribute);
$key = "validation.{$lowerRule}.{$type}";
return $this->translator->get($key);
}
示例10: send
/**
* Send the given notification.
*
* @param mixed $notifiable
* @param \Illuminate\Notifications\Notification $notification
* @return void
*/
public function send($notifiable, Notification $notification)
{
if (!$notifiable->routeNotificationFor('mail')) {
return;
}
$message = $notification->toMail($notifiable);
if ($message instanceof Mailable) {
return $message->send($this->mailer);
}
$this->mailer->send($message->view, $message->data(), function ($m) use($notifiable, $notification, $message) {
$recipients = empty($message->to) ? $notifiable->routeNotificationFor('mail') : $message->to;
if (!empty($message->from)) {
$m->from($message->from[0], isset($message->from[1]) ? $message->from[1] : null);
}
if (is_array($recipients)) {
$m->bcc($recipients);
} else {
$m->to($recipients);
}
$m->subject($message->subject ?: Str::title(Str::snake(class_basename($notification), ' ')));
foreach ($message->attachments as $attachment) {
$m->attach($attachment['file'], $attachment['options']);
}
foreach ($message->rawAttachments as $attachment) {
$m->attachData($attachment['data'], $attachment['name'], $attachment['options']);
}
});
}
示例11: handle
/**
* Handle the event.
*
* @param Event $event
*/
public function handle(Event $event)
{
$event->site->updateStatus('Adding mysql database');
$sql = 'CREATE DATABASE IF NOT EXISTS ' . Str::snake($event->site->name) . ';';
$this->envoy->run('mysql --sql="' . $sql . '"', true);
$this->envoy->run('artisan --path="' . $event->site->rootPath . '" --cmd="migrate"', true);
}
示例12: getTable
/**
* 系统的默认表名会将类名变为复数,如 org 将会变为 orgs;
* 复写该类取消这一功能,声明 Model 时将类名与表名保持一致即可
*/
public function getTable()
{
if (isset($this->table)) {
return $this->table;
}
return str_replace('\\', '', Str::snake(class_basename($this)));
}
示例13: resource
/**
* Get the resource associated with the controller.
*
* @return string
*/
public function resource()
{
$resource = str_replace('Controller', null, $this->getName());
$resource = Str::snake($resource, '-');
$resource = str_replace('\\', '.', $resource);
$resource = str_replace('.-', '.', $resource);
return $resource;
}
示例14: getAbility
public function getAbility($actionName)
{
list($controller, $method) = explode('@', $actionName);
$name = str_plural(strtolower(Str::snake(preg_replace('/Controller$/i', '', class_basename($controller)))));
$resourceAbilityMap = $this->resourceAbilityMap();
$method = isset($resourceAbilityMap[$method]) === true ? $resourceAbilityMap[$method] : $method;
return sprintf('admin.%s.%s', $name, $method);
}
示例15: __call
/**
* Set a constraint.
*
* @param string $constraint
* @param mixed $value
*/
public function __call($method, $arguments)
{
$constraint = Str::snake($method);
$value = $arguments[0];
$type = $this->constraintType($constraint);
$this->setConstraint($constraint, $value, $type);
return $this;
}