本文整理汇总了PHP中str_slug函数的典型用法代码示例。如果您正苦于以下问题:PHP str_slug函数的具体用法?PHP str_slug怎么用?PHP str_slug使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了str_slug函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的PHP代码示例。
示例1: handle
/**
* Handle the command.
*
* @param CreateStaffCommand $command
* @return void
*/
public function handle(CreateStaffCommand $command)
{
$staff_object = Staff::make($command->name, str_slug($command->name, '-'), $command->intro, $command->description, $command->email);
$staff = $this->repo->save($staff_object);
Event::fire(new StaffWasCreated($staff));
return $staff;
}
开发者ID:sidis405,项目名称:area.dev,代码行数:13,代码来源:CreateStaffCommandHandler.php
示例2: generateSlug
/**
* Call it in static boot method before save
*/
public function generateSlug()
{
$attrs = $this->getDirty();
// process only changed slugs or new items without provided slug
if ($this->exists and !isset($attrs[$this->getSlugField()])) {
return;
}
// generate slug from source if it was not provided
$slug = str_slug(empty($attrs[$this->getSlugField()]) ? $this->attributes[$this->getSlugSource()] : $attrs[$this->getSlugField()]);
// check unique
$original = $slug;
$num = 0;
while (true) {
$q = static::where('slug', $slug);
// exclude item itself from checking
if ($this->exists) {
$q->where($this->primaryKey, '!=', $this->attributes[$this->primaryKey]);
}
if (!$q->exists()) {
break;
}
// append next number to slug (until slug becomes unique)
$slug = $original . '-' . ++$num;
}
$this->attributes[$this->getSlugField()] = $slug;
}
开发者ID:nightdiraven,项目名称:amari,代码行数:29,代码来源:Sluggable.php
示例3: nameFile
protected function nameFile()
{
$extension = $this->request['image']->getClientOriginalExtension();
$originName = $this->request['image']->getClientOriginalName();
$this->name = str_slug($originName) . "." . $extension;
return $this;
}
开发者ID:Abdulhmid,项目名称:wecando,代码行数:7,代码来源:ImageUpload.php
示例4: putEdit
public function putEdit(Request $request)
{
if (!ACL::hasPermission('visitWellPhotos', 'edit')) {
return redirect(route('visitWellPhotos'))->withErrors(['Você não pode editar fotos.']);
}
$this->validate($request, ['date' => 'required|max:10', 'title' => 'required|max:100', 'image' => 'image|mimes:jpeg,gif,png'], ['date.required' => 'Informe a data', 'date.max' => 'A data não pode passar de :max caracteres', 'title.required' => 'Informe o nome da turma ou o título da foto', 'title.max' => 'O nome da turma ou título da foto não pode passar de :max caracteres', 'image.image' => 'Envie um formato de imagem válida', 'image.mimes' => 'Formatos suportados: .jpg, .gif e .png']);
$visitWellPhotos = VisitWellPhotos::find($request->visitWellPhotosId);
$visitWellPhotos->date = Carbon::createFromFormat('d/m/Y', $request->date)->format('Y-m-d');
$visitWellPhotos->title = $request->title;
$visitWellPhotos->slug = str_slug($request->title, '-');
if ($request->image) {
//DELETE OLD IMAGE
if ($request->currentImage != "") {
if (File::exists($this->folder . $request->currentImage)) {
File::delete($this->folder . $request->currentImage);
}
}
//IMAGE
$extension = $request->image->getClientOriginalExtension();
$nameImage = Carbon::now()->format('YmdHis') . "." . $extension;
$image = Image::make($request->file('image'));
if ($request->imageCropAreaW > 0 or $request->imageCropAreaH > 0 or $request->imagePositionX or $request->imagePositionY) {
$image->crop($request->imageCropAreaW, $request->imageCropAreaH, $request->imagePositionX, $request->imagePositionY);
}
$image->resize($this->imageWidth, $this->imageHeight)->save($this->folder . $nameImage);
$visitWellPhotos->image = $nameImage;
}
$visitWellPhotos->save();
$success = "Foto editada com sucesso";
return redirect(route('visitWellPhotos'))->with(compact('success'));
}
开发者ID:brunomartins-com,项目名称:espacofarmaceutico,代码行数:31,代码来源:VisitWellPhotosController.php
示例5: submitUpdate
public function submitUpdate($request)
{
$item = $this->item->find($request->id);
$item->update(['slug' => str_slug($request->title), 'title' => $request->title, 'description' => $request->description]);
$this->temporaryPhotoCheck($item);
return $item;
}
开发者ID:jekinney,项目名称:gypsy-v-3,代码行数:7,代码来源:ItemRepository.php
示例6: saveImage
/**
* @param Request $request
* @return string
*/
protected function saveImage(Request $request)
{
$ext = $request->file('image')->getClientOriginalExtension();
$imageName = str_slug($request->input('name')) . '.' . $ext;
$request->file('image')->move('images/products/', $imageName);
return $imageName;
}
开发者ID:fransiskusbenny,项目名称:larashop,代码行数:11,代码来源:ProductControler.php
示例7: create
/**
* Create a new user instance after a valid registration.
*
* @param Request $request
* @return User
*/
public function create(Request $request)
{
$user = User::create($request->only('name', 'email', 'password'));
$title = "{$user->name} kookboek";
Cookbook::create(['title' => $title, 'slug' => str_slug($title), 'user_id' => $user->id]);
return $user;
}
开发者ID:jargij,项目名称:culinologie,代码行数:13,代码来源:AuthController.php
示例8: setUrlAttribute
public function setUrlAttribute($value)
{
if ($value == '') {
$value = $this->attributes['title'];
}
$this->attributes['url'] = str_slug($value);
}
开发者ID:JhonatanH,项目名称:laravel1,代码行数:7,代码来源:Product.php
示例9: fire
/**
* Execute the console command.
* @return void
*/
public function fire()
{
$this->info('Initializing npm, bower and some boilerplates');
// copiar templates
$path_source = plugins_path('genius/elixir/assets/template/');
$path_destination = base_path('/');
$vars = ['{{theme}}' => Theme::getActiveTheme()->getDirName(), '{{project}}' => str_slug(BrandSettings::get('app_name'))];
$fileSystem = new Filesystem();
foreach ($fileSystem->allFiles($path_source) as $file) {
if (!$fileSystem->isDirectory($path_destination . $file->getRelativePath())) {
$fileSystem->makeDirectory($path_destination . $file->getRelativePath(), 0777, true);
}
$fileSystem->put($path_destination . $file->getRelativePathname(), str_replace(array_keys($vars), array_values($vars), $fileSystem->get($path_source . $file->getRelativePathname())));
}
$this->info('... initial setup is ok!');
$this->info('Installing npm... this can take several minutes!');
// instalar NPM
system("cd '{$path_destination}' && npm install");
$this->info('... node components is ok!');
$this->info('Installing bower... this will no longer take as!');
// instalar NPM
system("cd '{$path_destination}' && bower install");
$this->info('... bower components is ok!');
$this->info('Now... edit the /gulpfile.js as you wish and edit your assets at/ resources directory... that\'s is!');
}
开发者ID:estudiogenius,项目名称:oc-genius-elixir,代码行数:29,代码来源:ElixirInit.php
示例10: store
public function store(Request $request)
{
Validator::extend('not_contains', function ($attribute, $value, $parameters) {
// Banned words
$words = array('undefined');
foreach ($words as $word) {
if (stripos($value, $word) !== false) {
return false;
}
}
return true;
});
$messages = array('not_contains' => 'The :attribute is required');
$validator = Validator::make($request->all(), array('name' => 'required|unique:collections|min:3|not_contains'), $messages);
if ($validator->fails()) {
return $validator->messages();
} else {
$user = Auth::user();
$user_id = $user['id'];
$collection = Collection::create($request->all());
$collection->created_by = $user_id;
$collection->approved = False;
$collection->slug = str_slug($collection->name . '-' . $collection->id, "-");
$collection->save();
return response()->json(['status' => 'success', 'data' => $collection]);
}
}
开发者ID:ShehabSunny,项目名称:ProductZap,代码行数:27,代码来源:CollectionController.php
示例11: saving
public function saving($model)
{
if (!$model->{$model->getSlugField()}) {
$i = 0;
while (!$model->{$model->getSlugField()}) {
if (!$model->{$model->getNameField()}) {
throw new Exception("This model does not have any name field", 1);
}
$slug = str_slug($model->{$model->getNameField()} . ($i ? ' ' . $i : ''));
# code...
if ($model->newInstance()->SlugIs($slug)->count()) {
$i++;
} else {
$model->{$model->getSlugField()} = $slug;
}
}
}
// RULES
$rules[$model->getSlugField()] = ['required', 'alpha_dash', 'unique:' . $model->getTable() . ',' . $model->getSlugField() . ',' . ($model->id ? $model->id . ',id' : '')];
$validator = Validator::make($model->toArray(), $rules);
if ($validator->fails()) {
$model->setErrors($validator->messages());
return false;
}
}
开发者ID:ThunderID,项目名称:capcus.v2,代码行数:25,代码来源:HasSlugObserver.php
示例12: store
public function store(Request $request)
{
if ($request->thread_id) {
$this->validate($request, ['content' => 'required']);
} else {
$this->validate($request, ['title' => 'required|max:255', 'content' => 'required']);
}
// Create a new post
$post = new Post();
$post->title = $request->title;
$post->content = $request->content;
$post->forum_id = $request->forum_id;
$post->user_id = Auth::user()->id;
$post->reply_on = Carbon::now();
// Check if this is in response to another Thread
if ($request->thread_id) {
$post->thread_id = $request->thread_id;
} else {
// It's a new post, so add a slug for it
$post->slug = str_slug($request->title, '-');
}
if ($post->save()) {
// Post is made
// Update users posts count
$user = Auth::user();
$user->increment('post_count');
$user->save();
// Update the thread if required
if ($request->thread_id) {
$thread = Post::find($request->thread_id);
$thread->timestamps = false;
$thread->reply_on = Carbon::now();
$thread->save();
}
// Update the forum post count
/*
$forum = Forum::find($post->forum_id);
if($post->thread_id) {
// This is in reply to another post, update the post count
$forum->increment('reply_count');
} else {
// This is a fresh post, update topic count
$forum->increment('post_count');
}
$forum->save();
*/
Session::flash('alert-success', 'Post made!');
} else {
Session::flash('alert-error', 'Could not create post.');
}
if ($post->slug) {
// New post, send them to it
return redirect('/thread/' . $post->id . '/' . $post->slug);
} else {
// Reply to post, send them back to it
return back();
}
}
开发者ID:unbolt,项目名称:imp,代码行数:60,代码来源:PostController.php
示例13: boot
protected static function boot()
{
parent::boot();
static::updating(function ($model) {
$changed = $model->getDirty();
if (isset($changed['name'])) {
$slug = $model->gallery->slug;
$path = public_path() . '/gallery_assets/galleries/' . $slug;
//Get old file
$oldPath = $path . '/' . $model->file;
$file = new File($oldPath);
//Set the new file with original extension
$newName = strtolower(str_slug($model->name) . '_' . str_random(5)) . '.' . $file->getExtension();
$renamed = $path . '/' . $newName;
//Rename asset
if (rename($file, $renamed)) {
$model->setAttribute('file', $newName);
return true;
} else {
return false;
}
}
return true;
});
static::deleting(function ($model) {
$slug = $model->gallery->slug;
$path = public_path() . '/gallery_assets/galleries/' . $slug;
$oldPath = $path . '/' . $model->file;
$file = new File($oldPath);
@unlink($file);
//@ to prevent errors
return true;
});
}
开发者ID:Krato,项目名称:kgallery,代码行数:34,代码来源:PhotoEvents.php
示例14: initForm
protected function initForm($model)
{
$this->html = "";
$this->model = $model;
foreach ($this->model->getFieldSpec() as $key => $property) {
if (starts_with($key, 'seo') && $this->showSeo or !starts_with($key, 'seo') && !$this->showSeo) {
$this->formModelHandler($property, $key, $this->model->{$key});
}
}
if (isset($this->model->translatedAttributes) && count($this->model->translatedAttributes) > 0) {
$this->model->fieldspec = $this->model->getFieldSpec();
foreach (config('app.locales') as $locale => $value) {
if (config('app.locale') != $locale) {
$target = "language_box_" . str_slug($value) . "_" . str_random(160);
$this->html .= $this->containerLanguage($value, $target);
$this->html .= "<div class=\"collapse\" id=\"" . $target . "\">";
foreach ($this->model->translatedAttributes as $attribute) {
$value = isset($this->model->translate($locale)->{$attribute}) ? $this->model->translate($locale)->{$attribute} : '';
$this->property = $this->model->fieldspec[$attribute];
if (starts_with($attribute, 'seo') && $this->showSeo or !starts_with($attribute, 'seo') && !$this->showSeo) {
$this->formModelHandler($this->model->fieldspec[$attribute], $attribute . '_' . $locale, $value);
}
}
$this->html .= "</div>";
}
}
}
}
开发者ID:marcoax,项目名称:laraCms,代码行数:28,代码来源:AdminForm.php
示例15: setNameAttribute
/**
* The filable value of Name.
*
* @var string
*/
public function setNameAttribute($valor)
{
if (!empty($valor)) {
$this->attributes['name'] = $valor;
$this->attributes['slug'] = str_slug($valor);
}
}
开发者ID:wachap,项目名称:imagic-api,代码行数:12,代码来源:Photo.php
示例16: getItems
/**
* Method to get the Items related to the second level root categoty
* @param $category_id
* @return array
**/
public function getItems($category_id){
if (DB::table('products')->where('category_id',$category_id)->count() > 0)
{
/*********** BREADCRUMBS -START- **********/
$subcategory = DB::table('categories')->where('id',$category_id)->get();
$parent = DB::table('categories')->where('id',$subcategory[0]->parent_id)->get();
$breadcrumb = array(
0 => array( 'name' => $parent[0]->name, 'link' => route('reqCatalogo').'#' . str_slug($parent[0]->name)),
1 => array( 'name' => $subcategory[0]->name, 'link' => route('productos', ['category' => $subcategory[0]->id]))
);
/********** BREADCRUMBS -END- ***********/
$products = DB::table('products')->where('category_id',$category_id)->get();
$title = DB::table('categories')->where('id',$category_id)->get();
$title = $title[0]->name;
foreach ($products as $product) {
$parentName = DB::table('categories')->where('id',$product->parent_id)->get();
$product->parent_id = $parentName[0]->name;
}
return view('catalogo.productos', ['title' => $title, 'products' => $products,'breadcrumb' => $breadcrumb]);
}
else
{
return redirect()->route('reqCatalogo');
}
}
开发者ID:nedblu,项目名称:ProjectAB15_front,代码行数:40,代码来源:QueriesController.php
示例17: run
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$role = new Role();
$role->name = 'Admin';
$role->slug = str_slug('admin');
$role->save();
}
开发者ID:baconfy,项目名称:skeleton,代码行数:12,代码来源:RolesTableSeeder.php
示例18: setJudulAttribute
public function setJudulAttribute($value)
{
$this->attributes['judul'] = $value;
if (!$this->exists) {
$this->attributes['slug'] = str_slug($value);
}
}
开发者ID:pramitafirnanda,项目名称:cdc,代码行数:7,代码来源:Agenda.php
示例19: playerDetail
public function playerDetail($id, $name)
{
$player = Player::find($id);
if ($player == null) {
abort(404);
}
$pname = strtolower(str_slug($player->prenom) . '-' . str_slug($player->nom));
if (strtolower($name) != $pname) {
abort(404);
}
$histo = array();
foreach ($player->RankHistos()->orderBy('saison', 'asc')->orderBy('phase', 'asc')->get() as $rankHisto) {
$saison = str_replace('Saison ', '', $rankHisto->saison);
if ($rankHisto->phase == '1') {
$saison = substr($saison, 0, 4);
$saison = $saison . ' Q3';
} else {
$saison = substr($saison, 0, 4) + 1;
$saison = $saison . ' Q1';
}
array_push($histo, array('saison' => $saison, 'point' => $rankHisto->point));
}
$adversaires = $player->Versuses()->orderBy('advclaof')->get();
$advgrp = $adversaires->groupBy('advclaof');
$vdgrp = $adversaires->groupBy('vd');
$adv = array();
foreach ($advgrp as $key => $versus) {
array_push($adv, array('adv' => $key, 'nb' => count($versus)));
}
$vd = array();
foreach ($vdgrp as $key => $versus) {
array_push($vd, array('label' => $key == 'V' ? 'Victoires' : 'Defaites', 'value' => count($versus)));
}
return view('front.players.detail', array('player' => $player, 'histo' => $histo, 'adv' => $adv, 'vd' => $vd, 'rencontres' => $adversaires->sortByDesc('datef')->groupBy('date')));
}
开发者ID:kbiyo,项目名称:ARTTv2,代码行数:35,代码来源:PlayersController.php
示例20: makeName
public function makeName($file)
{
$filename = $file->getClientOriginalName();
$extension = $file->getClientOriginalExtension();
$filename = str_replace($extension, '', $filename);
return Hashids::encode(time()) . '-' . str_slug(strtolower($filename)) . '.' . $extension;
}
开发者ID:sidis405,项目名称:KP,代码行数:7,代码来源:Attachment.php
注:本文中的str_slug函数示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论