Example #1
0
 /**
  * Category Update test
  *
  * @return void
  */
 public function testUpdateCategory()
 {
     $category = Category::first();
     $toUpdate = ['name' => $this->faker->word . '777'];
     $endpoint = $this->getEndpointWithToken($this->endpoint . '/' . $category->id);
     $this->call('PATCH', $endpoint, $toUpdate);
     //fetch inserted category
     $updated_category = Category::whereId($category->id)->first();
     $this->assertEquals($toUpdate['name'], $updated_category->name);
 }
Example #2
0
 public function edit($id)
 {
     $Category = Category::whereId($id)->firstOrFail();
     $levelOnes = Category::all()->where('status', 1)->where('parent_id', null);
     return view('admin.category.edit', compact('Category', 'levelOnes'));
 }
Example #3
0
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     $category = Category::whereId($id)->firstOrFail();
     $name = $category->name;
     $category->delete();
     return redirect()->route('categories.index')->with('status', 'The category ' . $name . ' has been deleted!');
 }
 /**
  * Delete category
  *
  * @param $id
  */
 public function delete($id)
 {
     Category::whereId($id)->delete();
 }
Example #5
0
File: Ad.php Project: elberd/maoh
 public function setTitleAttribute($value)
 {
     $autoCategories = ['transport', 'cars', 'motorcycles'];
     $realtyCategories = ['apartment', 'houses', 'land', 'commercial_realty'];
     $request = Request::all();
     $categorySlug = Category::whereId($request['category_id'])->first()->slug;
     if (in_array($categorySlug, $autoCategories)) {
         $autoModel = AutoModel::whereId(Request::input('model'))->first();
         $value = sprintf('%s %s, %d', $autoModel->parent->title, $autoModel->title, $request['year']);
     }
     if (in_array($categorySlug, $realtyCategories)) {
         switch ($categorySlug) {
             case 'apartment':
                 $value = sprintf("%s %d-к квартиру, %s м², %d/%d эт.", $request['type_of_ad'], $request['num_of_rooms'], $request['square'], $request['floor'], $request['num_of_floors']);
                 break;
             case 'houses':
                 $value = sprintf("%s дом, %s м²", $request['type_of_ad'], $request['square']);
                 break;
             case 'land':
                 $value = sprintf("%s участок, %s сот.", $request['type_of_ad'], $request['square'] / 100);
                 break;
             case 'commercial_realty':
                 $value = sprintf("%s помещение, %s м²", $request['type_of_ad'], $request['square']);
                 break;
         }
     }
     $this->attributes['title'] = $value;
 }