1 <?php namespace BookStack\Http\Controllers;
3 use BookStack\Repos\AttributeRepo;
4 use Illuminate\Http\Request;
5 use BookStack\Http\Requests;
7 class AttributeController extends Controller
10 protected $attributeRepo;
13 * AttributeController constructor.
14 * @param $attributeRepo
16 public function __construct(AttributeRepo $attributeRepo)
18 $this->attributeRepo = $attributeRepo;
22 * Get all the Attributes for a particular entity
26 public function getForEntity($entityType, $entityId)
28 $attributes = $this->attributeRepo->getForEntity($entityType, $entityId);
29 return response()->json($attributes);
33 * Update the attributes for a particular entity.
36 * @param Request $request
39 public function updateForEntity($entityType, $entityId, Request $request)
41 $entity = $this->attributeRepo->getEntity($entityType, $entityId, 'update');
42 if ($entity === null) return $this->jsonError("Entity not found", 404);
44 $inputAttributes = $request->input('attributes');
45 $attributes = $this->attributeRepo->saveAttributesToEntity($entity, $inputAttributes);
46 return response()->json([
47 'attributes' => $attributes,
48 'message' => 'Attributes successfully updated'
53 * Get attribute name suggestions from a given search term.
54 * @param Request $request
56 public function getNameSuggestions(Request $request)
58 $searchTerm = $request->get('search');
59 $suggestions = $this->attributeRepo->getNameSuggestions($searchTerm);
60 return response()->json($suggestions);