public function save() { $id = Input::get('id'); $ct = $this->category->find($id); $token = \Input::get('_token'); if (\Session::token() === $token) { $data = array('ten_vi' => Input::get('ten_vi'), 'hienthi' => Input::has('hienthi'), 'parent' => Input::get('category'), 'slug_vi' => \Str::slug(Input::get('ten_vi'), '-'), 'title_seo_vi' => Input::get('title_seo_vi'), 'desc_seo_vi' => Input::get('desc_seo_vi'), 'keyword_seo_vi' => Input::get('keyword_seo_vi')); // var_dump($data);die(); $ct->hienthi = $data['hienthi']; $ct->ten_vi = $data['ten_vi']; $ct->slug_vi = $data['slug_vi']; $ct->parent = $data['parent']; $ct->title_seo_vi = $data['title_seo_vi']; $ct->desc_seo_vi = $data['desc_seo_vi']; $ct->keyword_seo_vi = $data['keyword_seo_vi']; /* avoiding resubmission of same content */ if (count($ct->getDirty()) > 0) { \DB::beginTransaction(); try { $ct->save(); } catch (\Exception $e) { \DB::rollBack(); return \Redirect::back()->withInput()->with('success', 'ERROR : Update fail'); } \DB::commit(); return \Redirect::back()->withInput()->with('success', 'Cập nhật thành công'); } else { return \Redirect::back()->withInput()->with('success', 'Không thay đổi gì'); } } else { return \Redirect::back()->withInput()->with('success', 'Cập nhật thất bại, Token hết hiệu lực'); } }
public static function make($string, $table = [], $exclude_id = 0, $column = 'slug') { # $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, '-')); # Words should be unique $words = array_unique($words); # Remove stop words $words = array_diff($words, self::$stop_words); # 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); }
public function postEdit($id) { if (!$this->checkRoute()) { return Redirect::route('index'); } $title = 'Edit A Modpack Creator - ' . $this->site_name; $creator = Creator::find($id); $input = Input::only('name', 'deck', 'website', 'donate_link', 'bio', 'slug'); $messages = ['unique' => 'The modpack creator already exists in the database.', 'url' => 'The :attribute field is not a valid URL.']; $validator = Validator::make($input, ['name' => 'required|unique:creators,name,' . $creator->id, 'website' => 'url', 'donate_link' => 'url'], $messages); if ($validator->fails()) { return Redirect::action('CreatorController@getAdd')->withErrors($validator)->withInput(); } $creator->name = $input['name']; $creator->deck = $input['deck']; $creator->website = $input['website']; $creator->donate_link = $input['donate_link']; $creator->bio = $input['bio']; if ($input['slug'] == '' || $input['slug'] == $creator->slug) { $slug = Str::slug($input['name']); } else { $slug = $input['slug']; } $creator->slug = $slug; $creator->last_ip = Request::getClientIp(); $success = $creator->save(); if ($success) { return View::make('creators.edit', ['title' => $title, 'creator' => $creator, 'success' => true]); } return Redirect::action('CreatorController@getEdit', [$id])->withErrors(['message' => 'Unable to edit modpack creator.'])->withInput(); }
public function updateCategory() { if (!Request::ajax()) { return App::abort(404); } if (Input::has('pk')) { return self::updateQuickEdit(); } $arrReturn = ['status' => 'error']; $category = new Category(); $category->name = Input::get('name'); $category->short_name = Str::slug($category->name); $category->description = Input::get('description'); $category->parent_id = (int) Input::get('parent_id'); $category->order_no = (int) Input::get('order_no'); $category->active = Input::has('active') ? 1 : 0; $pass = $category->valid(); if ($pass) { $category->save(); $arrReturn = ['status' => 'ok']; $arrReturn['message'] = $category->name . ' has been saved'; $arrReturn['data'] = $category; } else { $arrReturn['message'] = ''; $arrErr = $pass->messages()->all(); foreach ($arrErr as $value) { $arrReturn['message'] .= "{$value}\n"; } } return $arrReturn; }
public function postEdit($slug) { $album = $this->repo->album($slug); if (!\Request::get('name')) { \Flash::error('Musisz podać nazwę.'); return \Redirect::back()->withInput(); } $name = \Request::get('name'); $slug = \Str::slug($name); $description = \Request::get('description'); $exists = $this->repo->album($slug); if ($exists && $exists->id != $album->id) { \Flash::error('Album z tą nazwą już istnieje.'); return \Redirect::back()->withInput(); } if (\Input::hasFile('image')) { $image_name = \Str::random(32) . \Str::random(32) . '.png'; $image = \Image::make(\Input::file('image')->getRealPath()); $image->save(public_path('assets/gallery/album_' . $image_name)); $callback = function ($constraint) { $constraint->upsize(); }; $image->widen(480, $callback)->heighten(270, $callback)->resize(480, 270); $image->save(public_path('assets/gallery/album_thumb_' . $image_name)); $album->image = $image_name; } $album->name = $name; $album->slug = $slug; $album->description = $description; $album->save(); \Flash::success('Pomyślnie edytowano album.'); return \Redirect::to('admin/gallery/' . $slug . '/edit'); }
public function action_edit($id) { $post = \Blog\Models\Post::find($id); if ($post === null) { return Event::first('404'); } if (Str::lower(Request::method()) == "post") { $validator = Validator::make(Input::all(), self::$rules); if ($validator->passes()) { $post->title = Input::get('title'); if (Input::get('slug')) { $post->slug = Str::slug(Input::get('slug')); } else { $post->slug = Str::slug(Input::get('title')); } $post->intro = Input::get('intro'); $post->content = Input::get('content'); $post->author_id = Input::get('author_id'); $post->category_id = Input::get('category_id'); $post->publicated_at = Input::get('publicated_at_date') . ' ' . Input::get('publicated_at_time'); $post->save(); return Redirect::to_action('blog::admin.post@list'); } else { return Redirect::back()->with_errors($validator)->with_input(); } } else { $categories = array(); $originalCategories = \Blog\Models\Category::all(); foreach ($originalCategories as $cat) { $categories[$cat->id] = $cat->name; } return View::make('blog::admin.post.new')->with_post($post)->with('editMode', true)->with('categories', $categories); } }
public function apply($id) { $job = DB::select("EXEC spJobByID_Select @JobID = {$id}")[0]; $data = []; $data['job'] = $job; $data['form'] = Input::all(); $email = Input::get('email'); $name = Input::get('name'); if (Input::hasFile('cv')) { $newfilename = Str::slug($name) . '_cv_' . uniqid() . '.' . Input::file('cv')->getClientOriginalExtension(); Input::file('cv')->move(public_path() . '/uploads/cvs/', $newfilename); Mail::send('emails.jobs.apply', $data, function ($message) use($email, $name, $newfilename, $job) { $message->to($email, $name)->subject('APPLICATION RECEIVED for ' . $job->JobTitle . ' REF: ' . $job->JobRefNo); $message->bcc($job->OperatorEmail, $job->OperatorName . ' ' . $job->OperatorSurname)->subject('APPLICATION RECEIVED for ' . $job->JobTitle . ' REF: ' . $job->JobRefNo); $message->attach(public_path() . '/uploads/cvs/' . $newfilename); }); } else { // Send email to KDC Mail::send('emails.jobs.apply', $data, function ($message) use($email, $name, $job) { $message->to($email, $name)->subject('APPLICATION RECEIVED for ' . $job->JobTitle . ' REF: ' . $job->JobRefNo); $message->bcc($job->OperatorEmail, $job->OperatorName . ' ' . $job->OperatorSurname)->subject('APPLICATION RECEIVED for ' . $job->JobTitle . ' REF: ' . $job->JobRefNo); $message->bcc('*****@*****.**', 'KDC')->subject('APPLICATION RECEIVED for ' . $job->JobTitle . ' REF: ' . $job->JobRefNo); }); } return Redirect::back()->withInfo('Your application has been sent'); }
/** * Save charity settings * * @return Response */ public function postsettings() { $input = Input::all(); $profile = User::find(Auth::user()->id); if (!$profile->charity) { $charity = new Charity(); } else { $charity = Charity::find($profile->charity_id); } $charity->name = $input['name']; $charity->goal = $input['goal']; $charity->description = $input['description']; $charity->save(); $profile->charity_id = $charity->id; $profile->profile_url = Str::slug($input['name']); $profile->phone = $input['phone']; $profile->country = $input['country']; $profile->city = $input['city']; $profile->picture = $input['picture_id']; $profile->zip = $input['zip']; $profile->paypal = $input['paypal']; //Disabling validation rules $profile::$rules['email'] = ''; $profile::$rules['agree'] = ''; $profile->autoHashPasswordAttributes = false; if ($profile->save(['charity_id' => 'required|exists:charity,id', 'profile_url' => 'unique:users,profile_url,' . $profile->id])) { return Redirect::to('/charity/' . $profile->profile_url); } else { return Redirect::to('charity/settings')->with('errors', $profile->errors()->all()); } }
/** * @param url $url protocol to redirect to * @return ApiResponse Response to client */ public static function toApplication($url_suffix, $protocol = null) { $response = self::make(); $protocol = empty($protocol) ? Str::slug(Config::get('app.name')) : $protocol; $response->header('Location', $protocol . '://' . $url_suffix); return $response; }
public function update() { $rules = array('name' => 'required', 'desc' => 'required', 'totalposts' => 'required|numeric'); $validator = Validator::make(Input::all(), $rules); $badgeid = Input::get('id'); if ($validator->fails()) { return Redirect::to('admin/editbadge/' . $badgeid)->withErrors($validator)->withInput(); } else { $name = Input::get('name'); if (Input::get('badge')) { $image = explode('/', Input::get('badge')); $image = urldecode(end($image)); $extension = explode(".", $image); $extension = end($extension); $img = Image::make('files/' . $image); $img->resize(160, null, function ($constraint) { $constraint->aspectRatio(); $constraint->upsize(); })->save('files/' . $image); $newname = date('YmdHis') . '_' . Str::slug($name, '_') . '.' . $extension; File::move('files/' . $image, 'badges/' . $newname); } $badge = Badge::find($badgeid); $badge->name = Input::get('name'); $badge->description = Input::get('desc'); if (Input::get('badge')) { $badge->image = $newname; } $badge->total_posts = Input::get('totalposts'); $badge->save(); Session::flash('success', 'Badge updated'); return Redirect::to('admin/badges'); } }
public static function boot() { parent::boot(); // Overriding the slug method to prefix with a forward slash self::$sluggable['method'] = function ($string, $sep) { return '/' . \Str::slug($string, $sep); }; static::creating(function ($page) { // If the record is being created and there is a "main image" supplied, set it's width and height if (!empty($page->main_image)) { $page->updateMainImageSize(); } }); static::created(function ($page) { // If the record is being created and there is a "main image" supplied, set it's width and height if (!empty($page->main_image)) { $page->updateMainImageSize(); } }); static::updating(function ($page) { // If the record is about to be updated and there is a "main image" supplied, get the current main image // value so we can compare it to the new one $page->oldMainImage = self::where('id', '=', $page->id)->first()->pluck('main_image'); return true; }); static::updated(function ($page) { // If the main image has changed, and the save was successful, update the database with the new width and height if (isset($page->oldMainImage) && $page->oldMainImage != $page->main_image) { $page->updateMainImageSize(); } }); }
public function post_create() { $posts = Input::all(); $title = $posts['thread_name']; $contentRaw = $posts['inputarea']; if ($title != '' && strlen($contentRaw) > 10) { $alias = Str::slug($title, '-'); $exist = Thread::where('alias', '=', $alias)->first(); if ($exist != null) { return Redirect::to($exist->id); } $threadData = array('title' => $posts['thread_name'], 'alias' => $alias, 'type' => 0, 'poster_ip' => Request::ip(), 'dateline' => date("Y-m-d H:i:s"), 'last_message_at' => date("Y-m-d H:i:s")); $thread = Thread::create($threadData); if ($thread != null) { $content = static::replace_at(BBCode2Html(strip_tags_attributes($contentRaw)), $thread->id); $postData = array('thread_id' => $thread->id, 'entry' => $content, 'userip' => Request::ip(), 'user_id' => Sentry::user()->id, 'datetime' => date("Y-m-d H:i:s"), 'count' => 1, 'type' => 0); $pst = Post::create($postData); if ($pst != null) { return Redirect::to($thread->id); } } } else { return Redirect::to(URL::full()); } }
public function update($object_name) { //rename table if necessary $object = DB::table(DB_OBJECTS)->where('name', $object_name)->first(); $new_name = Str::slug(Input::get('name'), '_'); if ($object->name != $new_name) { Schema::rename($object->name, $new_name); } //enforce predence always ascending $order_by = Input::get('order_by'); $direction = Input::get('direction'); if ($order_by == 'precedence') { $direction = 'asc'; } //not sure why it's necessary, doesn't like empty value all of a sudden $group_by_field = Input::has('group_by_field') ? Input::get('group_by_field') : null; //linked objects DB::table(DB_OBJECT_LINKS)->where('object_id', $object->id)->delete(); if (Input::has('related_objects')) { foreach (Input::get('related_objects') as $linked_id) { DB::table(DB_OBJECT_LINKS)->insert(['object_id' => $object->id, 'linked_id' => $linked_id]); } } //update objects table DB::table(DB_OBJECTS)->where('id', $object->id)->update(['title' => Input::get('title'), 'name' => $new_name, 'model' => Input::get('model'), 'url' => Input::get('url'), 'order_by' => $order_by, 'direction' => $direction, 'singleton' => Input::has('singleton') ? 1 : 0, 'can_see' => Input::has('can_see') ? 1 : 0, 'can_create' => Input::has('can_create') ? 1 : 0, 'can_edit' => Input::has('can_edit') ? 1 : 0, 'list_grouping' => Input::get('list_grouping'), 'group_by_field' => $group_by_field, 'list_help' => trim(Input::get('list_help')), 'form_help' => trim(Input::get('form_help'))]); self::saveSchema(); return Redirect::action('InstanceController@index', $new_name); }
protected function generateSlug($source) { $separator = $this->sluggable['separator']; $method = $this->sluggable['method']; $max_length = $this->sluggable['max_length']; if ( $method === null ) { $slug = \Str::slug($source, $separator); } elseif ( $method instanceof Closure ) { $slug = $method($source, $separator); } elseif ( is_callable($method) ) { $slug = call_user_func($method, $source, $separator); } else { throw new \UnexpectedValueException("Sluggable method is not a callable, closure or null."); } if ($max_length) { $slug = substr($slug, 0, $max_length); } return $slug; }
function contentItem($imagen, $nombrelook, $idlook, $imagenmarca, $textoTwitter, $categoria) { $prod = '<img src="' . url() . '/img/lookbook/portada/' . Str::slug($imagen) . '.jpg" class="img-responsive" alt="' . $nombrelook . '" /> <div class="caption"> </div> <a href="' . url() . '/lookbook/' . $idlook . '/' . Str::slug($categoria) . '/' . Str::slug($nombrelook) . '"> <div class="boton-item-galeria"> <div class="content-b-look"><img src="' . url() . '/img/lookbook/marcas/' . $imagenmarca . '" class="img-responsive"/></div> </div> </a> <div class="compartir-galeria"> <img src="' . url() . '/images/sarah/compartelo.png" alt="compartir" class="compartir-lookbook" /> <div class="compartir-galeria-redes"> <ul> <li><a href="https://www.facebook.com/sharer/sharer.php?u=' . url() . '/lookbook/' . $idlook . '/' . Str::slug($categoria) . '/' . Str::slug($nombrelook) . '" target="_blank"><img src="' . url() . '/img/facebook.png" alt="facebook" /></a></li> <li><a href="https://twitter.com/home?status=' . $textoTwitter . '" target="_blank"><img src="' . url() . '/img/twitter.png" alt="twitter" /></a></li> </ul> </div> </div>'; return $prod; }
public function postEdit($id) { if (!$this->checkRoute()) { return Redirect::route('index'); } $title = 'Edit A Modpack Code - ' . $this->site_name; $input = Input::only('name', 'deck', 'description', 'slug'); $modpacktag = ModpackTag::find($id); $messages = ['unique' => 'This modpack tag already exists in the database!']; $validator = Validator::make($input, ['name' => 'required|unique:modpack_tags,name,' . $modpacktag->id, 'deck' => 'required'], $messages); if ($validator->fails()) { return Redirect::action('ModpackTagController@getEdit', [$id])->withErrors($validator)->withInput(); } $modpacktag->name = $input['name']; $modpacktag->deck = $input['deck']; $modpacktag->description = $input['description']; $modpacktag->last_ip = Request::getClientIp(); if ($input['slug'] == '' || $input['slug'] == $modpacktag->slug) { $slug = Str::slug($input['name']); } else { $slug = $input['slug']; } $modpacktag->slug = $slug; $success = $modpacktag->save(); if ($success) { Cache::tags('modpacks')->flush(); Queue::push('BuildCache'); return View::make('tags.modpacks.edit', ['title' => $title, 'success' => true, 'modpacktag' => $modpacktag]); } return Redirect::action('ModpackTagController@getEdit', [$id])->withErrors(['message' => 'Unable to edit modpack code.'])->withInput(); }
public function postProfil() { $validate = Validator::make(Input::all(), ['adsoyad' => 'required', 'email' => 'required|email|unique:users,email,' . Auth::user()->id . '', 'profil' => 'mimes:jpg,png,gif,jpeg']); $messages = $validate->messages(); if ($validate->fails()) { return Redirect::back()->with(array('mesaj' => 'true', 'title' => 'Doğrulama Hatası', 'text' => '' . $messages->first() . '', 'type' => 'error')); } $user = User::findOrFail(Auth::user()->id); $user->namesurname = Input::get('adsoyad'); if (Input::has('password')) { $user->password = Hash::make(Input::get('password')); $user->save(); } $user->email = Input::get('email'); if (Input::hasFile('profil')) { if (Auth::user()->profil != '') { File::delete('Backend/avatar/' . Auth::user()->profil . ''); } $profil = Input::file('profil'); $dosyaadi = $profil->getClientOriginalName(); $uzanti = $profil->getClientOriginalExtension(); $isim = Str::slug($dosyaadi) . Str::slug(str_random(5)) . '.' . $uzanti; $dosya = $profil->move('Backend/avatar/', $isim); $image = Image::open('Backend/avatar/' . $isim)->resize(80, 80)->save(); $user->profil = $isim; $user->save(); } $user->save(); if ($user->save()) { return Redirect::back()->with(array('mesaj' => 'true', 'title' => 'Kullanıcı Güncellendi', 'text' => 'Kullanıcı Başarı İle Güncellendi', 'type' => 'success')); } else { return Redirect::back()->with(array('mesaj' => 'true', 'title' => 'Kullanıcı Güncellenemedi', 'text' => 'Kullanıcı Güncellenirken Sorun İle Karşılaşıldı', 'type' => 'error')); } }
public function run() { $faker = Faker::create(); foreach (range(1, 500) as $index) { $keywords = ''; for ($i = 0; $i < $faker->numberBetween(4, 9); $i++) { $keywords .= $faker->word . ','; } $keywords = rtrim($keywords, ','); $name = $faker->name; $short_name = Str::slug($name); $gender = $faker->randomElement(array('male', 'female', 'both', 'any')); $age_from = $faker->numberBetween(0, 90); $age_to = $faker->numberBetween(0, 90); while ($age_from > $age_to) { $age_from = $faker->numberBetween(0, 90); $age_to = $faker->numberBetween(0, 90); } $ethnicity = $faker->randomElement(array('african', 'african_american', 'black', 'brazilian', 'chinese', 'caucasian', 'east_asian', 'hispanic', 'japanese', 'middle_eastern', 'native_american', 'pacific_islander', 'south_asian', 'southeast_asian', 'other', 'any')); $number_people = $faker->numberBetween(0, 10); $editorial = $faker->numberBetween(0, 1); $type_id = $faker->numberBetween(1, 3); $artist = $faker->name; $author_id = $faker->numberBetween(1, 15); VIImage::create(['name' => $name, 'short_name' => Str::slug($name), 'description' => $faker->paragraph, 'keywords' => $keywords, 'type_id' => $type_id, 'gender' => $gender, 'age_from' => $age_from, 'age_to' => $age_to, 'ethnicity' => $ethnicity, 'number_people' => $number_people, 'editorial' => $editorial, 'artist' => $artist, 'author_id' => $author_id]); } }
public function get_user_info(Token_Access $token) { $request = Request::make('resource', 'GET', 'https://identity.x.com/xidentity/resources/profile/me', array('oauth_token' => $token->access_token)); $response = json_decode($request->execute()); $user = $response->identity; return array('uid' => $user->userId, 'nickname' => \Str::slug($user->fullName, '-'), 'name' => $user->fullName, 'first_name' => $user->firstName, 'last_name' => $user->lastName, 'email' => $user->emails[0], 'location' => isset($user->addresses) ? $user->addresses[0] : '', 'image' => null, 'description' => null, 'urls' => array('paypal' => null)); }
function getPhotoAttribute() { if (File::exists(public_path() . '/assets/images/team/' . Str::slug($this->name) . '.jpg')) { return asset('assets/images/team/' . Str::slug($this->name) . '.jpg'); } return false; }
public function update($object_name, $field_id) { $field = DB::table(DB_FIELDS)->where('id', $field_id)->first(); $object = DB::table(DB_OBJECTS)->where('name', $object_name)->first(); $field_name = Str::slug(Input::get('name'), '_'); $required = Input::has('required') ? 1 : 0; //rename column if necessary if ($field->name != $field_name) { Schema::table($object_name, function ($table) use($field, $field_name) { $table->renameColumn($field->name, $field_name); }); //update object sort order if necessary if ($object->order_by == $field->name) { DB::table(DB_OBJECTS)->where('name', $object_name)->update(array('order_by' => $field_name)); } } //change nullability if necessary if ($field->required != $required) { //can't decide whether to attempt with DB::statement() or to use schema builder to //make a new column and then copy. schema seems more appropriate but would require //a refactor of the column-adding above to avoid too much repetition } //related field and object DB::table(DB_FIELDS)->where('id', $field_id)->update(['title' => Input::get('title'), 'name' => $field_name, 'visibility' => Input::get('visibility'), 'width' => Input::has('width') ? Input::get('width') : null, 'height' => Input::has('height') ? Input::get('height') : null, 'related_field_id' => Input::has('related_field_id') ? Input::get('related_field_id') : null, 'related_object_id' => Input::has('related_object_id') ? Input::get('related_object_id') : null, 'required' => $required, 'updated_by' => Auth::user()->id, 'updated_at' => new DateTime()]); ObjectController::saveSchema(); return Redirect::action('FieldController@index', $object_name)->with('field_id', $field_id); }
public function run() { $genres = ['Action', 'Comedy', 'Family', 'History', 'Mystery', 'Sci-Fi']; foreach ($genres as $genre) { Genre::create(['name' => $genre, 'slug' => Str::slug($genre)]); } }
/** * Make changes to the database. * * @return void */ public function up() { Schema::create('items', function ($table) { $table->increments('id'); $table->string('name', 128); $table->string('slug', 128); $table->string('code', 128); $table->text('features'); $table->text('short_description'); $table->text('full_description'); $table->decimal('price', 10, 4); $table->decimal('rrp', 10, 4); $table->boolean('status'); $table->integer('votes'); $table->integer('points'); $table->string('template', 255); $table->boolean('taxfree'); $table->string('meta_title', 255); $table->string('meta_description', 255); $table->string('meta_keywords', 255); $table->integer('click_counter'); $table->timestamps(); }); DB::table('items')->insert(array('name' => 'Item Name', 'slug' => Str::slug('Item Name'), 'code' => '1', 'features' => '', 'short_description' => '', 'full_description' => '', 'price' => 99.9999, 'rrp' => 99.9999, 'status' => TRUE, 'votes' => 0, 'points' => 0, 'template' => '', 'taxfree' => FALSE, 'meta_title' => '', 'meta_description' => '', 'meta_keywords' => '', 'click_counter' => 0)); }
function postUpdate($id = 0, &$data) { // check validate $validate = Validator::make(Input::all(), $this->model->getUpdateRules(), $this->model->getUpdateLangs()); if ($validate->passes()) { $slug = Str::slug(Input::get('title')); $updateData = array('status' => (int) Input::get('status'), 'is_promotion' => (int) Input::get('is_promotion'), 'title' => Input::get('title'), 'slug' => $slug); if ($id == 0) { // INSERT if ($item = $this->model->create($updateData)) { $data['id'] = $item->id; return TRUE; } } else { // UPDATE // GET CURRENT ITEM $item = $this->model->find($id); if ($item) { if ($this->model->where("id", $id)->update($updateData)) { return TRUE; } } } } else { $data['validate'] = $validate->messages(); } return FALSE; }
public function postIndex($id = 0) { $input = (object) Input::only('title', 'content', 'tags', 'category_id'); // ToDo !! User Input Validation ! $post = new TalkPost(); $post->title = $input->title; $post->content = $input->content; $post->category_id = $input->category_id; $post->parent_id = 0; $post->user_id = Auth::user()->id; if ($post->save()) { $post->slug = $post->id . '-' . Str::slug($input->title); if ($post->save()) { // ToDo !! Do something with the tags! $tags = Input::only('tags'); if (is_array($tags)) { foreach ($tags['tags'] as $tag_id) { $postTag = new TalkPostTag(); $postTag->post_id = $post->id; $postTag->tag_id = $tag_id; $postTag->save(); } } return Redirect::to(Config::get('talk::routes.base') . '/read/' . $post->slug); } } }
public function setTitleAttribute($value) { $this->attributes['title'] = $value; if (!$this->exists) { $this->attributes['slug'] = Str::slug($value); } }
public function beforeValidate() { // Generate a URL slug for this model if (!$this->exists && !$this->slug) { $this->slug = Str::slug($this->name); } }
/** * Attempts to upload a file, adds it to the database and removes other database entries for that file type if they are asked to be removed * @param string $field The name of the $_FILES field you want to upload * @param boolean $upload_type The type of upload ('news', 'gallery', 'section') etc * @param boolean $type_id The ID of the item (above) that the upload is linked to * @param boolean $remove_existing Setting this to true will remove all existing uploads of the passed in type (useful for replacing news article images when a new one is uploaded for example) * @return object Returns the upload object so we can work with the uploaded file and details */ public static function upload($field = 'image', $upload_type = false, $type_id = false, $remove_existing = false) { if (!$field || !$upload_type || !$type_id) { return false; } $input = Input::file($field); if ($input && $input['error'] == UPLOAD_ERR_OK) { if ($remove_existing) { static::remove($upload_type, $type_id); } $ext = File::extension($input['name']); $filename = Str::slug(Input::get('title'), '-'); Input::upload('image', './uploads/' . $filename . '.' . $ext); $upload = new Upload(); $upload->link_type = $upload_type; $upload->link_id = $type_id; $upload->filename = $filename . '.' . $ext; if (Koki::is_image('./uploads/' . $filename . '.' . $ext)) { $upload->small_filename = $filename . '_small' . '.' . $ext; $upload->thumb_filename = $filename . '_thumb' . '.' . $ext; $upload->image = 1; } $upload->extension = $ext; $upload->user_id = Auth::user()->id; $upload->save(); return $upload; } }
/** * Make a new Keyword Value Object. * * @param \Orchestra\Support\Keyword|string $value */ public function __construct($value) { $this->value = $value; if (is_string($value)) { $this->slug = trim(Str::slug($value, '-')); } }
/** * Return a slug for a web page path */ function pageSlug($path) { if ($path != '/') { return 'page-' . Str::slug(str_replace('/', '-', $path)); } return 'page-home'; }