title = "Edit Blog" url = "/blog/:id?/edit" layout = "Dashboard" is_hidden = 0 [session] security = "user" allowedUserGroups[] = "admin" allowedUserGroups[] = "supplier" redirect = "dashboard/login" == get(); $this['location'] = Location::orderBy('created_at', 'desc')->get(); $this['blogs'] = Blog::where('id', $this->param('id'))->first(); } $this['blog'] = Blog::make(); } function onSave() { date_default_timezone_set('Asia/Singapore'); $dateNow = date('Y-m-d H:i:s'); $query = Blog::where('id', $this->param('id'))->first(); $query->location_id = Input::get('location'); $query->activity_id = Input::get('activity_id'); $query->title = Input::get('title'); $query->slug = Input::get('slug'); $query->age_requirements = Input::get('age_requirements'); $query->duration = Input::get('duration'); $query->description = Input::get('description'); $query->highlight = Input::get('highlight'); $query->category = Input::get('category'); $query->images = Input::file('images'); $query->other_img = Input::file('other_img'); $query->updated_at = $dateNow; //published if(Input::get('published') == 'on'){ $query->published = 1; } else { $query->published = 0; } //guides if(Input::get('guides') == 'on'){ $query->guides = 1; } else { $query->guides = 0; } //lunch if(Input::get('lunch') == 'on'){ $query->lunch = 1; } else { $query->lunch = 0; } $lists = Input::get('Blog')['inclusion']; // Mengubah array menjadi format yang diinginkan $formattedItems = []; foreach ($lists as $list) { $formattedItems[] = ['list' => $list['list']]; } $query->inclusion = $formattedItems; $names = Input::get('Blog')['facilities']; // Mengubah array menjadi format yang diinginkan $formattedItems = []; foreach ($names as $name) { $formattedItems[] = ['name' => $name['name']]; } $query->facilities = $formattedItems; $query->save(); Session::flash('success', 'Blog has been update successfully.'); return redirect('/blog'); } public function onDeleteImg() { // Get the image ID from the post data $imageId = post('id_img'); // Find the image and delete it $image = File::find($imageId); if ($image) { $image->delete(); } // Re-fetch the images $blog = Blog::find($this->param('id')); if (Input::post('type') == 'main'){ $images = $blog->images; } elseif (Input::post('type') == 'other'){ $images = $blog->other_img; } // Return the updated partial if (Input::post('type') == 'main'){ return ['#main-img-container' => $this->renderPartial('blog/main_images', ['images' => $images])]; } elseif (Input::post('type') == 'other'){ return ['#other-img-container' => $this->renderPartial('blog/other_images', ['images' => $images])]; } } ?> ==
Edit Blog
    {% for category in category %}
  • {{ category.name }}
  • {% endfor %}
{{ blogs.description|raw }}
{{ blogs.highlight|raw }}
{% for key, list in blogs.inclusion %}
{% endfor %}
{% for key, list in blogs.facilities %}
{% endfor %}
{% partial 'blog/main_images' images=blogs.images %}

{% partial 'blog/other_images' images=blogs.other_img %}
{% for key, img in blogs.other_img %} {% endfor %}
{% put scripts %} {% endput %}