public function postUpdate(Request $request)
 {
     $cek_kat = Kategori::where('nama_kategori', $request->kategori)->where('id', '!=', $request->id)->count();
     if ($cek_kat > 0) {
         echo "0";
     } else {
         $Kat = Kategori::find($request->id);
         $Kat->nama_kategori = $request->kategori;
         $Kat->slug = str_slug($request->kategori, "-");
         $Kat->save();
         echo $Kat->id;
     }
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($jenis, $id)
 {
     if ($jenis == "artikel") {
         $data = Artikel::find($id);
         $data->delete();
         return redirect('/bos/artikel');
     }
     if ($jenis == "kategori") {
         $data = Kategori::find($id);
         $data->delete();
         return redirect('/bos/kategori');
     }
 }
    /**
     * Show the form for creating a new resource.
     *
     * @return Response
     */
    public function postSimpan(Request $request)
    {
        $jenis = $request->tipe;
        $Max_urut = Menu::where('parent_id', $request->parent_id)->where('lokasi', $request->lokasi)->max('urutan');
        $urutan = $Max_urut + 1;
        $id_arr = [];
        $judul_arr = [];
        $link_arr = [];
        if ($jenis == "Kategori" || $jenis == "Halaman") {
            foreach ($request->arr_value as $Val) {
                if ($jenis == "Kategori") {
                    $Data = Kategori::find($Val);
                    $link = url('/blog/Kategori') . "/" . $Data->slug;
                    $judul = $Data->nama_kategori;
                    $judul_arr[] = $judul;
                    $link_arr[] = $link;
                } else {
                    $Data = Page::find($Val);
                    $link = url('/page') . "/" . $Data->slug;
                    $judul = $Data->judul;
                    $judul_arr[] = $judul;
                    $link_arr[] = $link;
                }
                $Menu = new Menu();
                $Menu->judul = $judul;
                $Menu->link = $link;
                $Menu->parent_id = $request->parent_id;
                $Menu->urutan = $urutan;
                $Menu->lokasi = $request->lokasi;
                $Menu->jenis = $jenis;
                $Menu->save();
                $id_arr[] = $Menu->id;
            }
        } else {
            $Menu = new Menu();
            $Menu->judul = $request->judul;
            $Menu->link = $request->link;
            $Menu->parent_id = $request->parent_id;
            $Menu->urutan = $urutan;
            $Menu->lokasi = $request->lokasi;
            $Menu->jenis = $jenis;
            $Menu->save();
            $id_arr[] = $Menu->id;
        }
        ?>

        <?php 
        $no = 0;
        ?>

        <?php 
        foreach ($id_arr as $id) {
            ?>


            <?php 
            $judul_ = $jenis == "Kategori" || $jenis == "Halaman" ? $judul_arr[$no] : $request->judul;
            ?>
            <?php 
            $link_ = $jenis == "Kategori" || $jenis == "Halaman" ? $link_arr[$no] : $request->link;
            ?>
            <?php 
            $selector_id = $request->parent_id == 0 ? "" : "2";
            ?>

            <div class="panel panel-default" id="arrayOrder<?php 
            echo $selector_id;
            ?>
-<?php 
            echo $id;
            ?>
" style="margin-bottom:5px;color:#000">
                <div class="panel-heading" style="border:none;background:#eee;">
                    <h4 class="panel-title">
                            <a data-toggle="collapse" data-parent="#primary-menu" href="#menu-<?php 
            echo $id;
            ?>
">
                            <span class='judul'><?php 
            echo $judul_;
            ?>
 <?php 
            echo $request->parent_id == 0 ? "" : "<small> &nbsp; Sub Menu</small>";
            ?>
</span>
                            <label class="pull-right">
                                <small><?php 
            echo $jenis;
            ?>
</small>
                            </label>
                        </a>
                    </h4>

                </div>

                <div id="menu-<?php 
            echo $id;
            ?>
" class="panel-collapse collapse">
                    <div class="panel-body" style="background:#fff;height:auto;max-height:200px;overflow-y:scroll;color:#444">
                        
                        <input type="hidden" name="id" value="<?php 
            echo $id;
            ?>
">

                        <?php 
            if ($jenis == "Kategori" || $jenis == "Halaman") {
                ?>
                         
                            <label>Nama Menu</label>
                            <input type="text" class="form-control" name="nama_menu" value="<?php 
                echo $judul_;
                ?>
">
                            <input type="hidden" name="link" value="<?php 
                echo $link_;
                ?>
">

                        <?php 
            } else {
                ?>

                            <label>Nama Menu</label>
                            <input type="text" class="form-control" name="nama_menu" value="<?php 
                echo $judul_;
                ?>
">
                            <br>
                            <label>Link/Url</label>
                            <input type="text" class="form-control" name="link" value="<?php 
                echo $link_;
                ?>
">
                        
                        <?php 
            }
            ?>
                        
                        <br>

                        <a href="javascript:;" class="update-menu-item" style="color:green">Simpan</a>
                        <label class="pull-right">
                            <a href="javascript:;" class="hapus-menu-item" style="color:#a00">Hapus</a>
                        </label>
                    </div>

                </div>
            </div>

            <?php 
            $no++;
            ?>

        <?php 
        }
        ?>

    <?php 
    }
Example #4
0
 /**
  * Show the form for creating a new resource.
  *
  * @return Response
  */
 public function create($id_1)
 {
     if (Auth::user()->role_id == 1 || Auth::user()->role_id == 2) {
         if (Request::isMethod('get')) {
             $this->data = array();
             $this->data['kategori'] = Kategori::find($id_1);
             return View::make('admin.article.create', $this->data);
         } else {
             if (Request::isMethod('post')) {
                 $data = Input::all();
                 date_default_timezone_set('Asia/Jakarta');
                 // CDT
                 $current_date = date('Y-m-d');
                 $name = $_FILES['imginp']['name'];
                 $test = pathinfo($name, PATHINFO_FILENAME);
                 $target_dir = "artikel/";
                 $original_name = $test;
                 $imageFileType = pathinfo($name, PATHINFO_EXTENSION);
                 //$target_file = $target_dir . basename($_FILES["imginp"]["name"]);
                 $uploadOk = 1;
                 // Check if image file is a actual image or fake image
                 if (isset($_POST["submit"])) {
                     $check = getimagesize($_FILES["imginp"]["tmp_name"]);
                     if ($check !== false) {
                         echo "File is an image - " . $check["mime"] . ".";
                         $uploadOk = 1;
                     } else {
                         echo "File is not an image.";
                         $uploadOk = 0;
                     }
                 }
                 if ($imageFileType != "jpg" && $imageFileType != "png" && $imageFileType != "jpeg" && $imageFileType != "gif") {
                     echo "Sorry, only JPG, JPEG, PNG & GIF files are allowed.";
                     $uploadOk = 0;
                 }
                 // Check if file already exists
                 $i = 1;
                 while (file_exists($target_dir . $test . "." . $imageFileType)) {
                     $test = (string) $original_name . $i;
                     $name = $test . "." . $imageFileType;
                     $i++;
                 }
                 $target_file = $target_dir . $name;
                 // Check file size
                 if ($_FILES["imginp"]["size"] > 500000) {
                     echo "Sorry, your file is too large.";
                     $uploadOk = 0;
                 }
                 // Allow certain file formats
                 // Check if $uploadOk is set to 0 by an error
                 if ($uploadOk == 0) {
                     echo "Sorry, your file was not uploaded.";
                     // if everything is ok, try to upload file
                 } else {
                     if (move_uploaded_file($_FILES["imginp"]["tmp_name"], $target_file)) {
                         echo "The file " . basename($_FILES["imginp"]["name"]) . " has been uploaded.";
                     } else {
                         echo "Sorry, there was an error uploading your file.";
                     }
                 }
                 $target_file_final = "../../" . $target_file;
                 Artikel::insertGetId(array('judul' => $data['judul'], 'konten' => $data['konten'], 'tanggal' => $current_date, 'gambar' => $target_file_final, 'users_id' => Auth::user()->id, 'kategori_id' => $id_1));
                 return redirect('admin/artikel/' . $id_1);
             }
         }
     }
 }