示例#1
0
 /**
  * Process request to create new relationship
  *
  * @param Request request
  * @return Response
  */
 public function postCreateRelationship(Request $request)
 {
     $this->validate($request, ['magazine_id' => 'required|numeric', 'agent_id' => 'required|numeric']);
     $agent_id = $request->agent_id;
     $magazine_id = $request->magazine_id;
     // Get current agent
     try {
         $agent = Agent::findOrFail($agent_id);
         $magazine = Magazine::findOrFail($magazine_id);
     } catch (ModelNotFoundException $e) {
         $errMsg = "Cannot find agent/magazine! Error on `CreateRelationship` with agent ID={$agent_id} and magazine ID={$magazine_id}";
         return redirect('masterdata/agent')->with('errMsg', $errMsg);
     }
     $agent = $agent->magazine()->save($magazine);
     // Add new entry
     return redirect("masterdata/agent/relationship/{$agent_id}")->with('message', 'Added new relationship!');
 }
 /**
  * Remove the specified resource from storage.
  *
  * @param  int  $id
  * @return Response
  */
 public function destroy($id)
 {
     try {
         $magz = Magazine::findOrFail($id);
         $magz->delete();
         //Set result message as flashdata
         $execMsg = "Deletion successful!";
     } catch (ModelNotFoundException $e) {
         //In case of failure on deletion/finding data, set errMsg
         $execMsg = "Cannot delete record. Data not found.";
         return redirect('masterdata/magazine')->with('errMsg', $execMsg);
     }
     return redirect('masterdata/magazine')->with('message', $execMsg);
 }