map(function ($brand) { return [ 'id' => $brand->id, 'name' => $brand->name, 'models' => $brand->carModels()->get() ->map(function ($carModel) { return [ 'id' => $carModel->id, 'name' => $carModel->name, ]; }), ]; }); } /** * Show the form for creating a new resource. * * @return \Illuminate\Http\Response */ public function create() { // } /** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request */ public function store(Request $request) { $brand = Brand::create( $request->validate([ 'name' => ['required', 'string', 'max:255'], ]) )->only('id', 'name'); return $brand; } /** * Display the specified resource. * * @param \App\Models\Brand $brand * @return \Illuminate\Http\Response */ public function show(Brand $brand) { // } /** * Show the form for editing the specified resource. * * @param \App\Models\Brand $brand * @return \Illuminate\Http\Response */ public function edit(Brand $brand) { // } /** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param \App\Models\Brand $brand * @return \Illuminate\Http\Response */ public function update(Request $request, Brand $brand) { // } /** * Remove the specified resource from storage. * * @param \App\Models\Brand $brand * @return \Illuminate\Http\Response */ public function destroy(Brand $brand) { // } }