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)
42 $this->validate($request, [
43 'attributes.*.name' => 'required|min:3|max:250',
44 'attributes.*.value' => 'max:250'
47 $entity = $this->attributeRepo->getEntity($entityType, $entityId, 'update');
48 if ($entity === null) return $this->jsonError("Entity not found", 404);
50 $inputAttributes = $request->input('attributes');
51 $attributes = $this->attributeRepo->saveAttributesToEntity($entity, $inputAttributes);
52 return response()->json($attributes);
56 * Get attribute name suggestions from a given search term.
57 * @param Request $request
59 public function getNameSuggestions(Request $request)
61 $searchTerm = $request->get('search');
62 $suggestions = $this->attributeRepo->getNameSuggestions($searchTerm);
63 return response()->json($suggestions);