1 | <?php namespace Mascame\Artificer\Http\Controllers; |
||
14 | class ModelController extends BaseModelController |
||
15 | { |
||
16 | |||
17 | /** |
||
18 | * Show the form for creating a new resource. |
||
19 | * |
||
20 | * @return Response |
||
21 | */ |
||
22 | public function create() |
||
23 | { |
||
24 | $this->handleData($this->modelObject->schema->getInstance()); |
||
25 | |||
26 | $form = array( |
||
27 | 'form_action_route' => 'admin.model.store', |
||
28 | 'form_method' => 'post' |
||
29 | ); |
||
30 | |||
31 | return View::make($this->getView('edit'))->with('items', $this->data)->with($form); |
||
32 | } |
||
33 | |||
34 | /** |
||
35 | * @param $modelName |
||
36 | * @return $this |
||
37 | */ |
||
38 | public function filter($modelName) |
||
60 | |||
61 | /** |
||
62 | * Todo: rethink the way relations are made |
||
63 | * |
||
64 | * Store a newly created resource in storage. |
||
65 | * |
||
66 | * @return Response |
||
67 | */ |
||
68 | public function store() |
||
69 | { |
||
70 | $data = $this->filterInputData(); |
||
71 | |||
72 | $validator = $this->validator($data); |
||
73 | if ($validator->fails()) { |
||
74 | return $this->redirect($validator, 'admin.model.create'); |
||
75 | } |
||
76 | |||
77 | $this->handleData($data); |
||
78 | |||
79 | $this->model->guard($this->modelObject->getOption('guarded', array())); |
||
80 | |||
81 | $item = $this->model->create(with($this->handleFiles($data))); |
||
82 | |||
83 | $relation_on_create = '_set_relation_on_create'; |
||
84 | if (Input::has($relation_on_create)) { |
||
85 | $relateds = array( |
||
86 | 'id' => $item->id, |
||
87 | 'modelClass' => $this->modelObject->class, |
||
88 | 'foreign' => Input::get('_set_relation_on_create_foreign') |
||
89 | ); |
||
90 | |||
91 | Session::push($relation_on_create . '_' . Input::get($relation_on_create), $relateds); |
||
92 | } |
||
93 | |||
94 | if (Session::has($relation_on_create . '_' . $this->modelObject->name)) { |
||
95 | $relations = Session::get($relation_on_create . '_' . $this->modelObject->name); |
||
96 | |||
97 | foreach ($relations as $relation) { |
||
98 | $related_item = $relation['modelClass']::find($relation['id']); |
||
99 | $related_item->$relation['foreign'] = $item->id; |
||
100 | $related_item->save(); |
||
101 | } |
||
102 | |||
103 | Session::forget($relation_on_create . '_' . $this->modelObject->name); |
||
104 | } |
||
105 | |||
106 | if (Request::ajax()) { |
||
107 | return $this->handleAjaxResponse($item); |
||
108 | } |
||
109 | |||
110 | return Redirect::route('admin.model.all', array('slug' => $this->modelObject->getRouteName())); |
||
111 | } |
||
112 | |||
113 | /** |
||
114 | * Display the specified resource. |
||
115 | * |
||
116 | * @param int $id |
||
117 | * @return Response |
||
118 | */ |
||
119 | public function show($modelName, $id) |
||
120 | { |
||
121 | $this->handleData($this->model->findOrFail($id)); |
||
122 | |||
123 | return View::make($this->getView('show'))->with('item', $this->data); |
||
124 | } |
||
125 | |||
126 | /** |
||
127 | * Display the specified post. |
||
128 | * |
||
129 | * @return Response |
||
130 | */ |
||
131 | public function all($modelName, $data = null, $sort = null) |
||
132 | { |
||
133 | $sort = $this->getSort(); |
||
134 | |||
135 | $data = $this->model->with($this->modelObject->getRelations())->orderBy($sort['column'], |
||
136 | $sort['direction'])->get(); |
||
137 | |||
138 | return parent::all($modelName, $data, $sort); |
||
139 | } |
||
140 | |||
141 | /** |
||
142 | * Show the form for editing the specified post. |
||
143 | * |
||
144 | * @param int $id |
||
145 | * @return Response |
||
146 | */ |
||
147 | public function edit($modelName, $id) |
||
162 | |||
163 | public function field($modelName, $id, $field) |
||
164 | { |
||
165 | $this->handleData($this->model->with($this->modelObject->getRelations())->findOrFail($id)); |
||
166 | |||
171 | |||
172 | protected function handleAjaxResponse($item) |
||
184 | |||
185 | /** |
||
186 | * Update the specified resource in storage. |
||
187 | * |
||
188 | * @param int $id |
||
189 | * @return Response |
||
190 | */ |
||
191 | |||
192 | public function update($modelName, $id) |
||
211 | |||
212 | /** |
||
213 | * Remove the specified resource from storage. |
||
214 | * |
||
215 | * @param int $id |
||
216 | * @return Response |
||
217 | */ |
||
218 | public function destroy($modelName, $id) |
||
245 | |||
246 | } |
This check looks for a call to a parent method whose name is different than the method from which it is called.
Consider the following code:
The
getFirstName()
method in theSon
calls the wrong method in the parent class.