/** * Store a newly created resource in storage. * * @param Request $request * @return Response */ public function store(CreateCompanyRequest $request) { $name = $request->get('name'); $information = $request->get('information'); $email = $request->get('email'); $year_estab = $request->get('year_estab'); $address = $request->get('address'); $cat_id = $request->get('category_id'); $user_id = $request->get('user_id'); $category = Category::find($cat_id); $category->companies()->create(['name' => $name, 'information' => $information, 'email' => $email, 'year_estab' => $year_estab, 'address' => $address, 'category_id' => $cat_id, 'user_id' => $user_id]); return redirect('categories_web')->with(['company_created' => 'The Company has been created.']); }
/** * Update the specified resource in storage. * * @param Request $request * @param int $id * @return Response */ public function update(CreateCompanyRequest $request, $id) { $company = Company::find($id); if (!$company) { return response()->json(['message' => 'This company does not exist', 'success' => 0, 'code' => 404], 404); } $name = $request->get('name'); $information = $request->get('information'); $email = $request->get('email'); $year_estab = $request->get('year_estab'); $address = $request->get('address'); $category_id = $request->get('category_id'); $user_id = $request->get('user_id'); $company->name = $name; $company->information = $information; $company->email = $email; $company->year_estab = $year_estab; $company->address = $address; $company->category_id = $category_id; $company->user_id = $user_id; $company->save(); return response()->json(['message' => 'The Company has been updated', 'success' => 1], 200); }