本文整理汇总了PHP中Illuminate\Support\Str::slug方法的典型用法代码示例。如果您正苦于以下问题:PHP Str::slug方法的具体用法?PHP Str::slug怎么用?PHP Str::slug使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Illuminate\Support\Str
的用法示例。
在下文中一共展示了Str::slug方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的PHP代码示例。
示例1: importTaxonomy
/**
* @param array $data
* @param \Exolnet\Taxonomy\Taxonomy|null $parent
* @return \Exolnet\Taxonomy\Taxonomy
*/
protected function importTaxonomy(array $data, Taxonomy $parent = null)
{
$taxonomy = $this->newTaxonomy();
$attributes = array_except($data, 'children');
$children = (array) array_get($data, 'children', []);
// Assign attributes
$taxonomy->fillWithTranslations($attributes);
// Assign computed attributes
foreach ($taxonomy->getTranslations() as $translation) {
if ($translation->getSlug() === null) {
$slug = Str::slug($translation->getName());
$translation->setSlug($slug);
}
if ($translation->getPermalink() === null) {
$permalink = ltrim(($parent ? $parent->getTranslation($translation->getLocale())->getPermalink() . '/' : '') . $translation->getSlug(), '/');
$translation->setPermalink($permalink);
}
}
// Save the taxonomy
if ($parent) {
$taxonomy->insertAsChildOf($parent);
} else {
$taxonomy->insertAsRoot();
}
// Import children
$this->importTaxonomies($children, $taxonomy);
return $taxonomy;
}
示例2: edit
/**
* Edite l'article voulu
*
* @access public
* @param $slug Slug de l'article à édité
* @param $id Id de l'article
* @return post.admin_edit_post
*/
public function edit($slug, $id)
{
$post = Article::find($id);
if (Request::isMethod('post')) {
$input = Input::all();
$post->title = $input['title'];
$post->slug = Str::slug($post->title);
$post->content = $input['content'];
//$post->user_id = Auth::user()->id;
// Verifie qu'une image à était upload
if (Input::hasFile('image') && Input::file('image')->getError() == 0) {
// Le fichier est bien une image
if (in_array(Input::file('image')->getClientOriginalExtension(), array('jpg', 'jpeg', 'bmp', 'png', 'tiff'))) {
// Déplace et ajoute le nom à l'objet qui sera sauvegarder
$post->image = 'article-' . uniqid() . '.' . Input::file('image')->getClientOriginalExtension();
Input::file('image')->move(getcwd() . '/files/img/', $post->image);
} else {
// Image null car invalide ou mauvais format
$post->image = null;
}
} else {
// Erreur sur l'image donc null
$post->image = null;
}
$v = Validator::make($post->toArray(), $post->rules);
if ($v->fails()) {
Session::put('message', 'An error has occured');
} else {
$post->save();
return Redirect::route('admin_article_index')->with('message', 'Your article has been modified');
}
}
return View::make('Admin.article.edit', array('post' => $post));
}
示例3: slug
public static function slug($name)
{
$extension = self::getExtension($name);
$name = str_replace($extension, '', $name);
$name = Str::slug($name);
return $name . strtolower($extension);
}
示例4: run
public function run()
{
$films = [];
$faker = Faker\Factory::create('es_MX');
for ($i = 0; $i < self::AMOUNT; $i++) {
$film = array();
$film['title'] = implode(' ', $faker->words(rand(3, 6)));
$film['slug'] = \Illuminate\Support\Str::slug($film['title']) . '-' . rand(0, 4);
$film['original_title'] = 'Original' . $film['title'];
$film['years'] = self::getListOfYears();
$film['duration'] = $faker->time();
$film['genre_id'] = rand(0, 10);
$film['director'] = self::getListOfNames($faker);
$film['script'] = self::getListOfNames($faker);
$film['photographic'] = self::getListOfNames($faker);
$film['music'] = self::getListOfNames($faker);
$film['edition'] = self::getListOfNames($faker);
$film['production'] = self::getListOfNames($faker);
$film['cast'] = self::getListOfNames($faker);
$film['synopsis'] = $faker->paragraphs(rand(1, 5), true);
$film['notes'] = $faker->paragraphs(rand(0, 6), true);
$film['trailer'] = '<iframe width="560" height="315" src="https://www.youtube.com/embed/Gjg_Mi0zLlg" frameborder="0" allowfullscreen></iframe>';
$film['created_at'] = new DateTime();
$film['updated_at'] = new DateTime();
array_push($films, $film);
}
DB::table('films')->truncate();
DB::table('films')->insert($films);
}
示例5: upload
/**
* Upload un torrent
*
* @access public
* @return View torrent.upload
*
*/
public function upload()
{
$user = Auth::user();
// Post et fichier upload
if (Request::isMethod('post')) {
// No torrent file uploaded OR an Error has occurred
if (Input::hasFile('torrent') == false) {
Session::put('message', 'You must provide a torrent for the upload');
return View::make('torrent.upload', array('categories' => Category::all(), 'user' => $user));
} else {
if (Input::file('torrent')->getError() != 0 && Input::file('torrent')->getClientOriginalExtension() != 'torrent') {
Session::put('message', 'An error has occurred');
return View::make('torrent.upload', array('categories' => Category::all(), 'user' => $user));
}
}
// Deplace et decode le torrent temporairement
TorrentTools::moveAndDecode(Input::file('torrent'));
// Array from decoded from torrent
$decodedTorrent = TorrentTools::$decodedTorrent;
// Tmp filename
$fileName = TorrentTools::$fileName;
// Info sur le torrent
$info = Bencode::bdecode_getinfo(getcwd() . '/files/torrents/' . $fileName, true);
// Si l'announce est invalide ou si le tracker et privée
if ($decodedTorrent['announce'] != route('announce', ['passkey' => $user->passkey]) && Config::get('other.freeleech') == true) {
Session::put('message', 'Your announce URL is invalid');
return View::make('torrent.upload', array('categories' => Category::all(), 'user' => $user));
}
// Find the right category
$category = Category::find(Input::get('category_id'));
// Create the torrent (DB)
$torrent = new Torrent(['name' => Input::get('name'), 'slug' => Str::slug(Input::get('name')), 'description' => Input::get('description'), 'info_hash' => $info['info_hash'], 'file_name' => $fileName, 'num_file' => $info['info']['filecount'], 'announce' => $decodedTorrent['announce'], 'size' => $info['info']['size'], 'nfo' => Input::hasFile('nfo') ? TorrentTools::getNfo(Input::file('nfo')) : '', 'category_id' => $category->id, 'user_id' => $user->id]);
// Validation
$v = Validator::make($torrent->toArray(), $torrent->rules);
if ($v->fails()) {
if (file_exists(getcwd() . '/files/torrents/' . $fileName)) {
unlink(getcwd() . '/files/torrents/' . $fileName);
}
Session::put('message', 'An error has occured may bee this file is already online ?');
} else {
// Savegarde le torrent
$torrent->save();
// Compte et sauvegarde le nombre de torrent dans cette catégorie
$category->num_torrent = Torrent::where('category_id', '=', $category->id)->count();
$category->save();
// Sauvegarde les fichiers que contient le torrent
$fileList = TorrentTools::getTorrentFiles($decodedTorrent);
foreach ($fileList as $file) {
$f = new TorrentFile();
$f->name = $file['name'];
$f->size = $file['size'];
$f->torrent_id = $torrent->id;
$f->save();
unset($f);
}
return Redirect::route('torrent', ['slug' => $torrent->slug, 'id' => $torrent->id])->with('message', trans('torrent.your_torrent_is_now_seeding'));
}
}
return View::make('torrent.upload', array('categories' => Category::all(), 'user' => $user));
}
示例6: make
public static function make($string, $table = [], $exclude_id = 0, $column = 'slug')
{
//die('slug string was ' . $string);
# $table can be array
if (is_array($table)) {
$uniques = array_values($table);
} else {
$uniques = DB::table($table)->where('id', '<>', $exclude_id)->lists($column);
if (empty($uniques)) {
$uniques = [];
}
}
# Convert string into array of url-friendly words
$words = explode('-', Str::slug($string, '-'));
# Reset indexes
$words = array_values($words);
# Limit length of slug down to fewer than 50 characters
while (self::checkLength($words) === false) {
array_pop($words);
}
# Check uniqueness
while (self::checkUniqueness($words, $uniques) === false) {
self::increment($words);
}
return self::makeFromWords($words);
}
示例7: setNameAttribute
public function setNameAttribute($value)
{
$this->attributes['name'] = $value;
$slug = Str::slug($value);
$slugCount = $this->whereRaw("slug REGEXP '^{$slug}(-[0-9]*)?\$'")->count();
$this->attributes['slug'] = $slugCount > 0 ? "{$slug}-{$slugCount}" : $slug;
}
示例8: setName
public function setName($name)
{
$name = Str::limit($name, 40, '');
$this->name = Str::slug($name);
$this->name .= "-{$this->width}x{$this->height}x{$this->command}";
return $this;
}
示例9: createFromName
public static function createFromName($name)
{
$category = new self();
$category->name = $name;
$category->slug = Str::slug($name);
return $category;
}
示例10: store
/**
* Store a newly created resource in storage.
*
* @param \Illuminate\Http\Request $request
*
* @return \Illuminate\Http\Response
*/
public function store(Request $request)
{
$validator = Validator::make($request->all(), ['course' => 'required', 'description' => 'required|min:15', 'url' => 'required|url', 'section' => 'required']);
if ($validator->fails()) {
Alert::error('Oops', 'Invalid Inputs');
return redirect('/dashboard');
}
$course = new Course();
if (Course::where('course', '=', $request->get('course'))->exists()) {
Alert::warning('Oops', 'Course Already Exists');
return Redirect::back();
}
$course->slug = Str::slug($request->input('course'));
$checkId = $course->video_id = $this->getVideoId($request->input('url'));
$course->user_id = Auth::user()->id;
if ($this->youtubeExist($checkId)) {
$values = $request->all();
$course->fill($values)->save();
Alert::success('Good', 'Course created successfully!');
return redirect('/dashboard');
} else {
Alert::error('Oops', 'Only Youtube Videos are allowed!');
return redirect('/dashboard');
}
}
示例11: store
/**
* Store a newly created resource in storage.
*
* @param StoreMediaRequest $request
* @return Response
*/
public function store(StoreMediaRequest $request)
{
if ($request->ajax()) {
$response = ['error' => 1, 'path' => ''];
if ($request->hasFile('file')) {
$file = $request->file('file');
$folder = '/public/uploads/' . $request->folder;
if (!\Storage::exists($folder)) {
\Storage::makeDirectory($folder);
}
$path = $folder . '/' . date('Y-m-d');
$hashed = sha1(Str::slug($file->getClientOriginalName() . time())) . '.' . $file->getClientOriginalExtension();
if (!\Storage::exists($path)) {
\Storage::makeDirectory($path);
}
if ($file->move(storage_path('app') . $path, $hashed)) {
$path = str_replace('/public', '', $path);
$medium = $this->medium->create(['path' => $path . '/' . $hashed]);
if ($medium) {
$response['error'] = 0;
$response['path'] = $path . '/' . $hashed;
return response($response, 200);
}
// TODO: ln -s storage/app/public/uploads /path/to/public_html/public
}
}
}
return response('error', 400);
}
示例12: postEdit
public function postEdit()
{
// $page=page::find(Input::get('idedit'));
// Input::merge(array('name' => str_replace("\"","'",trim(Input::get('name')))));
// $page->fill(Input::get());
// if($page->update()){
// return redirect('admin/page')->with(['message'=>'Cập nhật thành công trang "'.Input::get('name').'"']);
// }else{
// return redirect('admin/page/edit?id='.Input::get('idedit'))->with(['message'=>'Cập nhật thất bại. Vui lòng thử lại.']);
// }
$page = new page();
$name = str_replace("\"", "'", trim(Input::get('name')));
$url = trim(Input::get('url'));
if ($url == '') {
$url = $name;
}
$url = Str::slug($url);
if ($url == '') {
return redirect('admin/page/edit?id=' . Input::get('idedit'))->with('message', 'Url đã tồn tại');
}
$kt = $page->where('url', $url)->where('id', '<>', Input::get('idedit'))->count();
if ($kt > 0) {
$message = trim(Input::get('url')) == '' ? 'Trang đã tồn tại.' : 'Url đã tồn tại.';
return redirect('admin/page/edit?id=' . Input::get('idedit'))->with('message', $message);
}
$data = array('name' => $name, 'content' => Input::get('content'), 'url' => $url);
$page = $page->find(Input::get('idedit'));
$page->fill($data);
if ($page->update()) {
return redirect('admin/page')->with(['message' => 'Cập nhật thành công page ' . Input::get('name')]);
} else {
return redirect('admin/page/edit?id=' . Input::get('idedit'))->with('message', 'Có lỗi. Cập nhật thất bại. Vui lòng thử lại.');
}
}
示例13: store
/**
* Store a newly created resource in storage.
*
* @return Response
*/
public function store()
{
$pub = new Publikasi();
$pub->judul_publikasi = Input::get('judul_publikasi');
$pub->slug_publikasi = Str::slug(Input::get('judul_publikasi'));
$pub->deskripsi_publikasi = Input::get('deskripsi_publikasi');
// Upload File PDF
$the_pdf = Input::file('file_pdf');
$lokasi_simpan1 = 'upload/publikasi';
$filename_pdf = 'file-publikasi-' . Str::slug(Input::get('judul_publikasi')) . '.' . $the_pdf->getClientOriginalExtension();
$upload_pdf = Input::file('file_pdf')->move($lokasi_simpan1, $filename_pdf);
$pub->file_pdf = $filename_pdf;
// Upload File Flipbook
$the_flip = Input::file('file_flip');
$lokasi_simpan2 = 'publikasi/view/' . Str::slug(Input::get('judul_publikasi'));
$filename_flip = Str::slug(Input::get('judul_publikasi')) . '.' . $the_flip->getClientOriginalExtension();
$upload_pdf = Input::file('file_flip')->move($lokasi_simpan2, $filename_flip);
$pub->file_flipbook = $filename_flip;
// Extract File Zip
$fileZip = $lokasi_simpan2 . '/' . $filename_flip;
$zip = new ZipArchive();
$res = $zip->open($fileZip);
if ($res === TRUE) {
$zip->extractTo($lokasi_simpan2);
$zip->close();
}
// Hapus Zip Setelah Di Extract
File::delete($lokasi_simpan2 . '/' . $filename_flip);
if ($pub->save()) {
return redirect()->to('admin/publikasi')->with('alert', 'Data berhasil di simpan');
}
}
示例14: boot
public static function boot()
{
parent::boot();
static::saving(function ($event) {
$event->slug = \Illuminate\Support\Str::slug($event->name);
});
}
示例15: create
/**
* create name before creating a new role instance.
*
* @param array $data
*
* @return EloquentRole
*/
public function create(array $data)
{
if (!array_key_exists('name', $data)) {
$data['name'] = Str::slug($data['display_name']);
}
return parent::create($data);
}