示例#1
0
 /**
  * Store a newly created resource in storage.
  *
  * @param  \Illuminate\Http\Request  $request
  * @return \Illuminate\Http\Response
  */
 public function store(Request $request)
 {
     //validate request
     $this->validate($request, ['name' => 'required|min:5', 'gender' => 'required', 'alignment' => 'required']);
     $character = new Character();
     foreach (\Request::all() as $key => $value) {
         switch ($key) {
             case '_token':
                 break;
             case '_method':
                 break;
             case 'labels':
                 break;
             case 'values':
                 break;
             case 'birthdate':
                 $date = \Carbon\Carbon::parse($value);
                 $character->birthdate = $date->toDateString();
                 break;
             default:
                 $character->{$key} = $value;
         }
     }
     $labels = $request->get('labels');
     $values = $request->get('values');
     //Construct the json array for stats
     foreach ($labels as $key => $value) {
         $stats[$value] = $values[$key];
     }
     $character->stats = json_encode($stats);
     //        $content = str_ireplace('\r\n', '<br />', $request->get('notes'));
     if ($request->has('image')) {
         foreach ($request->files as $file) {
             $ext = $file->getClientOriginalExtension();
             $name = sha1($file->getClientOriginalName());
             $file->move(storage_path() . '/app/uploads/campaign_' . \Session::get('campaign')->id, $name . '.' . $ext);
             $character->image = \URL::to('/images/' . \Session::get('campaign')->id . '/' . $name . '.' . $ext);
         }
     }
     $character->save();
     //Create the relationship with the Campaign
     $relationship = new Relationship();
     $relationship->campaign_id = \Session::get('campaign')->id;
     $relationship->source_type = 'App\\Campaign';
     $relationship->source_id = \Session::get('campaign')->id;
     $relationship->sibling_type = 'App\\Character';
     $relationship->sibling_id = $character->id;
     $relationship->save();
     return redirect(action('CharactersController@index'));
 }
 /**
  * Store a newly created resource in storage.
  *
  * @param $name
  * @param $realm
  * @return \Illuminate\Http\Response
  */
 public function store($name, $realm)
 {
     if (empty(Auth::user()->battlenet_characters)) {
         abort(500, 'Character data not found');
     }
     $characters = json_decode(Auth::user()->battlenet_characters);
     $found = null;
     foreach ($characters as $character) {
         if ($character->name == $name && $character->realm == $realm) {
             $found = $character;
             break;
         }
     }
     if ($found == null) {
         abort(500, 'No character named that associated to logged in user');
     }
     $character = new Character(array_only((array) $found, ['name', 'realm', 'class', 'race', 'level', 'thumbnail']));
     $character->gender = $found->gender === 1 ? 'FEMALE' : 'MALE';
     $character->user_id = Auth::user()->id;
     $character->save();
     Flash::success($character->name . ' added to your account!');
     return redirect()->route('characters.index');
 }