本文整理汇总了PHP中str_slug函数的典型用法代码示例。如果您正苦于以下问题:PHP str_slug函数的具体用法?PHP str_slug怎么用?PHP str_slug使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了str_slug函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的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;
}
示例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;
}
示例3: nameFile
protected function nameFile()
{
$extension = $this->request['image']->getClientOriginalExtension();
$originName = $this->request['image']->getClientOriginalName();
$this->name = str_slug($originName) . "." . $extension;
return $this;
}
示例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'));
}
示例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;
}
示例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;
}
示例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;
}
示例8: setUrlAttribute
public function setUrlAttribute($value)
{
if ($value == '') {
$value = $this->attributes['title'];
}
$this->attributes['url'] = str_slug($value);
}
示例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!');
}
示例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]);
}
}
示例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;
}
}
示例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();
}
}
示例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;
});
}
示例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>";
}
}
}
}
示例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);
}
}