本文整理汇总了PHP中Illuminate\Support\Str::limit方法的典型用法代码示例。如果您正苦于以下问题:PHP Str::limit方法的具体用法?PHP Str::limit怎么用?PHP Str::limit使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Support\Str
的用法示例。
在下文中一共展示了Str::limit方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: value
public function value()
{
if ($this->entity->value === '0' || $this->entity->value === '1') {
return $this->entity->value === '0' ? 'false' : 'true';
}
return Str::limit($this->entity->value, 20);
}
示例2: getDescriptionAttribute
/**
* @param $value
* @return string
*/
public function getDescriptionAttribute($value)
{
if ($value == '') {
return Str::limit(strip_tags($this->attributes['content']), 130, '...');
}
return $value;
}
示例3: index
public function index()
{
Str::limit('hello', 10);
$data['posts'] = Post::getAll();
$data['slides'] = [(object) ['src' => 'assets/img/gallery/slider-img-1.jpg', 'alt' => 'Slider', 'href' => 'gallery-single.htm', 'name' => 'test1'], (object) ['src' => 'assets/img/gallery/slider-img-2.jpg', 'alt' => 'Slider', 'href' => 'gallery-single.htm', 'name' => 'test1'], (object) ['src' => 'assets/img/gallery/slider-img-2.jpg', 'alt' => 'Slider', 'href' => 'gallery-single.htm', 'name' => 'test1'], (object) ['src' => 'assets/img/gallery/slider-img-1.jpg', 'alt' => 'Slider', 'href' => 'gallery-single.htm', 'name' => 'test1']];
$data['post'] = Post::getLatest()->first();
return view('home.index', $data);
}
示例4: getTransactionLink
/**
* @param Currency $currency
*
* @return string
*/
public function getTransactionLink(Currency $currency)
{
if ($this->category == 'move') {
return '';
}
if ($currency->explorer) {
return HTML::link(str_replace('%id', $this->txid, $currency->explorer), Str::limit($this->txid, 20), ['target' => '_blank']) . " <span class='fa fa-new-window'></span>";
}
return HTML::link('#', Str::limit($this->txid, 20), ['data-toggle' => 'tooltip', 'title' => $this->txid]);
}
示例5: fire
/**
* Execute the console command.
*
* @return void
*/
public function fire()
{
$dayBefore = Carbon::now()->subDay();
$content = Content::where('created_at', '>', $dayBefore)->orderBy('uv', 'desc')->firstOrFail();
$client = new Client(['base_url' => 'https://api.twitter.com/1.1/', 'defaults' => ['auth' => 'oauth']]);
$oauth = new Oauth1(['consumer_key' => config('social.twitter.consumer_key'), 'consumer_secret' => config('social.twitter.consumer_secret'), 'token' => config('social.twitter.token'), 'token_secret' => config('social.twitter.token_secret')]);
$client->getEmitter()->attach($oauth);
$params = ['status' => Str::limit($content->title, 100) . ' https://strm.pl/c/' . $content->hashId()];
$client->post('statuses/update.json', ['body' => $params]);
}
示例6: getItemUuiD
/**
* Generate Item uuid.
*
* @param $menuName
* @param $itemURL
*
* @return string
*/
public function getItemUuiD($menuItem)
{
$itemID = '';
if (is_a($menuItem, MenuItem::class)) {
$itemID = 'MenuItem' . $menuItem->getURL();
}
if (is_a($menuItem, MenuBuilder::class)) {
$itemID = 'MenuBuilder' . $menuItem->getName();
}
return Str::limit(md5(Str::slug($itemID)), 12, null);
}
示例7: render
function render($instance, $key, $options)
{
if ($instance->{$key}) {
$limit = 100;
if ($options && intval($options)) {
$limit = intval($options);
}
return Str::limit($instance->{$key}, $limit);
}
return null;
}
示例8: createGroup
function createGroup(Author $author)
{
$faker = $this->faker();
$group = new Group();
$group->title = join(' ', $faker->words(5));
$group->link = $faker->boolean() ? '/' . $faker->slug(3) . '.html' : '';
$group->inline = $faker->boolean();
$group->annotation = Str::limit($faker->realText(), 250);
$group->author()->associate($author);
$group->save();
return $group;
}
示例9: testStringLimit
public function testStringLimit()
{
$str1 = 'Laravel is really awesome';
$str2 = Str::limit($str1);
$this->assertEquals($str2, 'Laravel is really awesome');
$str1 = 'Laravel is really awesome';
$str2 = Str::limit($str1, 7);
$this->assertEquals($str2, 'Laravel...');
$str1 = 'Laravel is really awesome';
$str2 = Str::limit($str1, 7, '!!!');
$this->assertEquals($str2, 'Laravel!!!');
}
示例10: up
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('games', function(Blueprint $table)
{
$table->string('slug', 32);
});
$games = Game::all();
foreach( $games as $item )
{
$item->slug = Str::limit( Str::slug( $item->title), 32, '');
$item->save();
}
}
示例11: up
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::table('categories', function(Blueprint $table)
{
$table->string('icon')->nullable();
$table->string('slug', 32);
$table->string('type')->nullable();
});
$categories = Category::all();
foreach( $categories as $item )
{
$item->slug = Str::limit( Str::slug( $item->name), 32, '');
$item->save();
}
}
示例12: run
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$authors = Author::all();
$this->iterate(self::PAGES_TO_SEED / 2, self::PAGES_TO_SEED, function ($i) use($authors) {
$author = $authors->random();
do {
$author = $authors->random();
} while ($author->groups->isEmpty());
$faker = $this->faker();
$page = new Page();
$page->title = $faker->sentence(5);
$page->annotation = Str::limit(join(' ', $faker->sentences(5)), 250);
$page->link = $faker->slug(3);
$page->size = $faker->numberBetween(0, 9999);
$page->author()->associate($author);
$page->group()->associate($author->groups->random());
$page->save();
});
}
示例13: limit
/**
* Limit the number of characters in the string.
*
* @param int $limit
* @param string $end
* @return static
*/
public function limit($limit = 100, $end = '...')
{
return new static(Str::limit($this->string, $limit, $end));
}
示例14: getReleaseDate
public function getReleaseDate()
{
if ($this->released_at !== null) {
return $this->released_at;
}
if ($this->published_at !== null) {
return Str::limit($this->published_at, 10, '');
}
return Str::limit($this->attributes['created_at'], 10, '');
}
示例15: limit
/**
* Limit the number of characters in a string.
*
* @param string $value
* @param int $limit
* @param string $end
* @return string
*/
public function limit($value, $limit = 12, $end = '')
{
return Str::limit($value, $limit, $end);
}