Как * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *.
приложение / Http / Контроллеры / SomeCoolController.php
public function index(Request $request)
{
// get your users
$users = User::all();
// get your target types
$targetTypes = TargetType::all();
// return them to your front-end
return response([
'data' => [
'users' => $users,
'target_types' => $targetTypes
]
], 200);
// or in case you have a view
// return view('my_cool_view', ['users' => $users, 'targetTypes' => $targetTypes]);
}
Альтернативный
Вы говорите, что targetTypes
будет одинаковым для всех пользователей. В случае, если эти типы не меняются очень часто. Почему бы не хранить их внутри модели?
приложение / User.php
public function getTargetTypesAttribute()
{
return ['my', 'list', 'of, 'target', 'types'];
}
Тогда вы можете использовать его при запросах для ваших пользователей:
$user = User::first();
dd($user->target_types);
// this will output the list of target types.