コード例 #1
1
ファイル: Product.php プロジェクト: JhonatanH/laravel1
 public function setUrlAttribute($value)
 {
     if ($value == '') {
         $value = $this->attributes['title'];
     }
     $this->attributes['url'] = str_slug($value);
 }
コード例 #2
0
 /**
  * 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;
 }
コード例 #3
0
ファイル: ImageUpload.php プロジェクト: Abdulhmid/wecando
 protected function nameFile()
 {
     $extension = $this->request['image']->getClientOriginalExtension();
     $originName = $this->request['image']->getClientOriginalName();
     $this->name = str_slug($originName) . "." . $extension;
     return $this;
 }
コード例 #4
0
ファイル: Sluggable.php プロジェクト: nightdiraven/amari
 /**
  * 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;
 }
コード例 #5
0
ファイル: ItemRepository.php プロジェクト: jekinney/gypsy-v-3
 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;
 }
 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'));
 }
コード例 #7
0
ファイル: AuthController.php プロジェクト: jargij/culinologie
 /**
  * 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
0
 /**
  * @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;
 }
コード例 #9
0
 /**
  * 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
0
 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
0
 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
0
ファイル: PostController.php プロジェクト: unbolt/imp
 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
0
ファイル: PhotoEvents.php プロジェクト: Krato/kgallery
 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
0
ファイル: AdminForm.php プロジェクト: marcoax/laraCms
 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
0
ファイル: Photo.php プロジェクト: wachap/imagic-api
 /**
  * The filable value of Name.
  *
  * @var string
  */
 public function setNameAttribute($valor)
 {
     if (!empty($valor)) {
         $this->attributes['name'] = $valor;
         $this->attributes['slug'] = str_slug($valor);
     }
 }
コード例 #16
0
    /**
    *   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');
        }

       
    }
コード例 #17
0
ファイル: RolesTableSeeder.php プロジェクト: baconfy/skeleton
 /**
  * Run the database seeds.
  *
  * @return void
  */
 public function run()
 {
     $role = new Role();
     $role->name = 'Admin';
     $role->slug = str_slug('admin');
     $role->save();
 }
コード例 #18
0
ファイル: Agenda.php プロジェクト: pramitafirnanda/cdc
 public function setJudulAttribute($value)
 {
     $this->attributes['judul'] = $value;
     if (!$this->exists) {
         $this->attributes['slug'] = str_slug($value);
     }
 }
コード例 #19
0
ファイル: PlayersController.php プロジェクト: kbiyo/ARTTv2
 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')));
 }
コード例 #20
0
ファイル: Attachment.php プロジェクト: sidis405/KP
 public function makeName($file)
 {
     $filename = $file->getClientOriginalName();
     $extension = $file->getClientOriginalExtension();
     $filename = str_replace($extension, '', $filename);
     return Hashids::encode(time()) . '-' . str_slug(strtolower($filename)) . '.' . $extension;
 }
コード例 #21
0
ファイル: Content.php プロジェクト: NgoDucHai/BlogLaravel5.1
 public function setTitleAttribute($value)
 {
     $this->attributes['title'] = $value;
     if (!$this->exists) {
         $this->attributes['slug'] = str_slug($value);
     }
 }
コード例 #22
0
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store()
 {
     $a = new \App\Popups();
     $a->judul = Input::get('judul');
     $a->slug = str_slug(Input::get('judul'));
     $a->deskripsi = Input::get('keterangan');
     $a->tipe_valid = Input::get('type_valid');
     if ($a->tipe_valid == "by_datetime" or $a->tipe_valid == "by_date") {
         $a->date_valid_start = date_format(date_create(Input::get('date_valid_start')), "Y-m-d");
         $a->date_valid_end = date_format(date_create(Input::get('date_valid_end')), "Y-m-d");
     }
     if ($a->tipe_valid == "by_datetime" or $a->tipe_valid == "by_time") {
         $a->time_valid_start = date_format(date_create(Input::get('time_valid_start')), "H:i:s");
         $a->time_valid_end = date_format(date_create(Input::get('time_valid_end')), "H:i:s");
     }
     if (Input::hasFile('image') and Input::file('image')->isValid()) {
         $image = date("YmdHis") . uniqid() . "." . Input::file('image')->getClientOriginalExtension();
         Input::file('image')->move(storage_path() . '/popup_image', $image);
         $a->image = $image;
     }
     $a->keep_open = Input::get('keep_open');
     $a->hotlink = Input::get('hotlink');
     $a->idpengguna = Auth::user()->id;
     $a->save();
     return redirect(url('admin/popups'));
 }
コード例 #23
0
 /**
  * Handle the command.
  *
  * @param  UpdateStaffCommand  $command
  * @return void
  */
 public function handle(UpdateStaffCommand $command)
 {
     $staff_object = Staff::edit($command->staff_id, $command->name, str_slug($command->name, '-'), $command->intro, $command->description, $command->featured_image_id, $command->email);
     $staff = $this->repo->save($staff_object);
     Event::fire(new StaffWasUpdated($staff));
     return $staff;
 }
コード例 #24
0
 public function save(PostRequest $request, $forum, $topic, $post = null)
 {
     $url = \DB::transaction(function () use($request, $forum, $topic, $post) {
         // parsing text and store it in cache
         $text = app()->make('Parser\\Post')->parse($request->text);
         // post has been modified...
         if ($post !== null) {
             $this->authorize('update', [$post, $forum]);
             $data = $request->only(['text', 'user_name']) + ['edit_count' => $post->edit_count + 1, 'editor_id' => auth()->id()];
             $post->fill($data)->save();
             $activity = Stream_Update::class;
             // user want to change the subject. we must update topics table
             if ($post->id === $topic->first_post_id) {
                 $path = str_slug($request->get('subject'), '_');
                 $topic->fill($request->all() + ['path' => $path])->save();
                 $this->topic->setTags($topic->id, $request->get('tag', []));
             }
         } else {
             $activity = Stream_Create::class;
             // create new post and assign it to topic. don't worry about the rest: trigger will do the work
             $post = $this->post->create($request->all() + ['user_id' => auth()->id(), 'topic_id' => $topic->id, 'forum_id' => $forum->id, 'ip' => request()->ip(), 'browser' => request()->browser(), 'host' => request()->server('SERVER_NAME')]);
             // get id of users that were mentioned in the text
             $usersId = (new Ref_Login())->grab($text);
             if ($usersId) {
                 app()->make('Alert\\Post\\Login')->with(['users_id' => $usersId, 'sender_id' => auth()->id(), 'sender_name' => $request->get('user_name', auth()->user()->name), 'subject' => excerpt($topic->subject, 48), 'excerpt' => excerpt($text), 'url' => route('forum.topic', [$forum->path, $topic->id, $topic->path], false)])->notify();
             }
         }
         $url = route('forum.topic', [$forum->path, $topic->id, $topic->path], false);
         $url .= '?p=' . $post->id . '#id' . $post->id;
         $object = (new Stream_Post(['url' => $url]))->map($post);
         stream($activity, $object, (new Stream_Topic())->map($topic, $forum));
         return $url;
     });
     return redirect()->to($url);
 }
コード例 #25
0
ファイル: PageController.php プロジェクト: kholidfu/gludhag
 function detail($imgtitle, $id)
 {
     // get single image
     $image = DB::table('wallpaper')->find($id);
     // find the title, if not match return 404
     if ($imgtitle !== $image->wallslug) {
         abort(404);
     }
     $short_title = str_slug($this->shortTitle($image->walltitle), '-');
     $vav = DB::table('wallpaper')->orderByRaw("RAND()")->take(mt_rand(3, 5))->get();
     // get related images (abal2)
     $relateds1 = DB::table('wallpaper')->orderBy('id', 'DESC')->skip(1)->take(3)->get();
     $relateds2 = DB::table('wallpaper')->orderBy('id', 'DESC')->skip(4)->take(3)->get();
     $relateds3 = DB::table('wallpaper')->orderBy('id', 'DESC')->skip(7)->take(3)->get();
     $recents = DB::table('wallpaper')->orderBy('id', 'DESC')->take(5)->get();
     $randimg = DB::table('wallpaper')->orderByRaw("RAND()")->take(3)->get();
     $randimg1 = DB::table('wallpaper')->orderByRaw("RAND()")->take(3)->skip(3)->get();
     $images = DB::table('wallpaper')->orderBy('wallview', 'DESC')->take(7)->get();
     $tags = DB::table('wallpaper')->orderByRaw("RAND()")->take(mt_rand(7, 11))->get();
     $alp = range('A', 'Z');
     $num = range(0, 9);
     // get categories
     $categories = $this->getCategory();
     return view('arkitekt.detail', compact('image', 'vav', 'vavsqq', 'short_title', 'short_title1', 'relateds1', 'relateds2', 'relateds3', 'recents', 'randimg', 'randimg1', 'images', 'tags', 'categories', 'alp', 'num'));
 }
コード例 #26
0
 /**
  * Update the business service types.
  *
  * @param Business $business
  * @param Request  $request
  *
  * @return Response
  */
 public function update(Business $business, Request $request)
 {
     logger()->info(__METHOD__);
     logger()->info(sprintf('businessId:%s', $business->id));
     $this->authorize('manageServices', $business);
     // BEGIN
     $servicetypeSheet = $request->input('servicetypes');
     $regex = '/(?P<name>[a-zA-Z\\d\\-\\ ]+)\\:(?P<description>[a-zA-Z\\d\\ ]+)/im';
     preg_match_all($regex, $servicetypeSheet, $matches, PREG_SET_ORDER);
     $publishing = collect($matches)->map(function ($item) {
         $data = array_only($item, ['name', 'description']);
         $data['slug'] = str_slug($data['name']);
         return $data;
     });
     foreach ($business->servicetypes as $servicetype) {
         if (!$this->isPublished($servicetype, $publishing)) {
             $servicetype->delete();
         }
     }
     foreach ($publishing as $servicetypeData) {
         $servicetype = ServiceType::firstOrNew($servicetypeData);
         $business->servicetypes()->save($servicetype);
     }
     flash()->success(trans('servicetype.msg.update.success'));
     return redirect()->route('manager.business.service.index', [$business]);
 }
コード例 #27
0
ファイル: User.php プロジェクト: borislemke/kbr
 public function getUsername($firstName)
 {
     $username = str_slug($firstName);
     $userRows = $this->whereRaw("username REGEXP '^{$username}([0-9]*)?\$'")->get();
     $countUser = count($userRows) + 1;
     return $countUser > 1 ? "{$username}{$countUser}" : $username;
 }
コード例 #28
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     if ($request->get('customer_name') == null) {
         return response()->json(['response_order_message' => 'fail', 'response_order_message_detail' => 'Customer name is required']);
     }
     $customer = Customer::where('name', '=', $request->get('customer_name'))->first();
     if ($customer == null) {
         $customer = new Customer();
         $customer->name = $request->get('customer_name');
         $customer->slug = str_slug($customer->name);
         $customer->phone_number = $request->get('customer_phone_number');
         $customer->email = $request->get('customer_email');
         $customer->save();
         $customerAddress = new CustomerAddress();
         $customerAddress->line1 = $request->get('line1');
         $customerAddress->line2 = $request->get('line2');
         $customerAddress->district = $request->get('district');
         $customerAddress->province = $request->get('province');
         $customerAddress->post_code = $request->get('post_code');
         $customerAddress->customer_id = $customer->id;
         $customerAddress->save();
     }
     $order = new Order();
     $order->customer_id = $customer->id;
     $order->status = 0;
     $order->save();
     $orderDetail = new OrderDetail();
     $orderDetail->order_id = $order->id;
     $orderDetail->product_id = $request->get('product_id');
     $orderDetail->amount = $request->get('amount');
     $orderDetail->total_price = Product::findOrNew($orderDetail->product_id)->price * $orderDetail->amount;
     $orderDetail->save();
     return $order->id;
 }
コード例 #29
0
ファイル: Branch.php プロジェクト: kacana/admin
 /**
  * update information
  *
  * @param id
  * @param options = array()
  * @return true or false
  */
 public function updateItem($id, $options)
 {
     $branch = Branch::find($id);
     if (isset($options['image']) && $options['image'] != 'undefined') {
         $image = $options['image'];
         $original_name = explode(".", $image->getClientOriginalName());
         $original_name = $original_name[0];
         $new_name = str_slug($original_name, "-") . '-' . time() . '.' . $image->getClientOriginalExtension();
         $path = public_path(BRANCH_IMAGE . date('Y-m-d', strtotime($branch->created)));
         if (!file_exists($path)) {
             mkdir($path, 0777, true);
         } else {
             chmod($path, 0777);
         }
         Image::make($image->getRealPath())->resize(200, 200)->save($path . '/' . $new_name);
         $options['image'] = $new_name;
     } else {
         $options['image'] = $branch->image;
     }
     $options['updated'] = date('Y-m-d H:i:s');
     if (isset($options['_token'])) {
         unset($options['_token']);
     }
     return $this->where('id', $id)->update($options);
 }
コード例 #30
-1
ファイル: TypeRepository.php プロジェクト: jekinney/gypsy-v-3
 public function submitUpdate($request)
 {
     $type = $this->type->find($request->id);
     $image = $this->uploadImage($request, $type);
     $type->update(['image' => $image, 'title' => $request->title, 'slug' => str_slug($request->title), 'description' => $request->description, 'location' => $request->location]);
     return $type;
 }