Example #1
0
 /**
  * Update the specified resource in storage.
  *
  * Mark: Because the relation is hasOne, info returns an Object not a Collection,
  * So it works, or if the relation is hasMany, info returns a Collection Object,
  * It will not work
  *
  * Mark: If it is not an object,Calling update will ignore fillable variable.
  *
  * @param  int $id
  * @return Response
  */
 public function update(InfoRequest $request, User $user)
 {
     if ($this->isMe($user)) {
         if ($user->info->update($request->all())) {
             Flash::success('修改成功!');
             return View::make($this->getView('edit'))->withUser($user);
         } else {
             Flash::error('修改失败!');
             return Redirect::back()->withInput();
         }
     }
 }
 /**
  * Store a newly created resource in storage.
  *
  * @return Response
  */
 public function store(PersonatRequest $person, InfoRequest $info, KontaktRequest $kontakt)
 {
     $vendlindja = Qytet::firstOrCreate(['qyteti' => $person->get('vendlindja')]);
     $profesioni = Profesioni::firstOrCreate(['profesioni' => $person->get('profesioni')]);
     $gjendja_civile = GjendjaCivile::firstOrCreate(['statusi' => $person->get('gjendja_civile')]);
     Personat::create(['emer' => $person->get('emer'), 'mbiemer' => $person->get('mbiemer'), 'datelindja' => $person->get('datelindja'), 'vendlindja' => $vendlindja->id, 'profesioni' => $profesioni->id, 'gjinia' => $person->get('gjinia'), 'gjendja_civile' => $gjendja_civile->id]);
     $personi = Personat::where('emer', $person->get('emer'))->where('mbiemer', $person->get('mbiemer'))->where('datelindja', $person->get('datelindja'))->first();
     Pozicioni::firstOrCreate(['pozicioni' => $info->get('pozicioni')]);
     $pozicioni = Pozicioni::where(['pozicioni' => $info->get('pozicioni')])->first();
     Gatishmeria::firstOrCreate(['gatishmeria' => $info->get('gatishmeria')]);
     $gatishmeria = Gatishmeria::where(['gatishmeria' => $info->get('gatishmeria')])->first();
     $qendra = Dega::where(['dega' => $info->get('qendra')])->first();
     $programi = Programi::where(['programi' => $info->get('programi')])->first();
     Info::create(['personi' => $personi->id, 'qendra' => $qendra->id, 'pozicioni' => $pozicioni->id, 'programi' => $programi->id, 'disponimi' => $info->get('disponimi'), 'gatishmeria' => $gatishmeria->id, 'koha' => $info->get('koha'), 'rregjistrimi' => $info->get('rregjistrimi'), 'viti_i_fundit' => $info->get('viti_i_fundit')]);
     Kontakt::create(['personi' => $personi->id, 'email' => $kontakt->get('email'), 'telefon' => $kontakt->get('telefon'), 'celular' => $kontakt->get('celular')]);
     //		foreach(Input::get('njohuri_te_tjera[]') as $key => $njohuri){
     NjohuriShtese::firstOrCreate(['njohuri_shtese' => Input::get('njohuri_te_tjera')]);
     $njohuri = NjohuriShtese::where(['njohuri_shtese' => Input::get('njohuri_te_tjera')])->first();
     //		}
     $personi->njohuri_shtese()->attach($njohuri->id);
     return $personi;
 }