12345678910111213141516171819202122232425262728293031323334353637383940414243444546 |
- <?php
- namespace App\Admin\Controllers;
- use App\Admin\Repositories\DistAdminDistributor;
- use Illuminate\Http\Request;
- use Illuminate\Routing\Controller;
- class ApiController extends Controller
- {
-
- public function dist(Request $request)
- {
- $q = $request->get('q');
- if ($q != null) {
-
- $obj = new DistAdminDistributor();
- return $obj->model()->where('client_code', 'like', "%$q%")->paginate(null, ['id', 'client_code as text']);
- } else {
-
- $selectOptionsNew = DistAdminDistributor::selectOptionsNew();
- return $this->changeOptions($selectOptionsNew);
- }
- }
-
- private function changeOptions($data) {
-
- $result = [];
-
- foreach ($data as $id => $text) {
- $result[] = [
- 'id' => (int)$id,
- 'text' => $text
- ];
- }
- return $result;
- }
- }
|