/** * Store a newly created resource in storage. * * @param \Illuminate\Http\Request $request * @return \Illuminate\Http\Response */ public function store(Requests\Prospect $request) { $activity = Activity::find($request->get('activity_id')); $prospect = new Prospect($request->all()); $activity->prospects()->save($prospect); if ($request->has('links')) { foreach ($request->get('links') as $link) { $type = LinkType::findOrFail($link['type_id']); $link = new Link(['url' => $link['url']]); $link->prospect()->associate($prospect); $link->type()->associate($type); $link->save(); } } return response()->json($prospect); }