public function addDeliverable(Request $request) { $messages = ['not_in' => "You have to choose a client.", 'url' => "Your url must be in the form http://domain.com"]; $this->validate($request, ['deliverable_name' => 'required|max:25', 'client_id' => 'not_in:0', 'deliverable_url' => 'url'], $messages); $deliverable = new \p4\Deliverable(); $user = \Auth::user(); $client = \p4\Client::find($request->client_id); $file = \Request::file('deliverable_file'); if ($file) { $extension = $file->getClientOriginalExtension(); $filename = $file->getClientOriginalName(); $file->move(public_path() . '/uploads/', $filename); $location = '/uploads/' . $filename; $deliverable->attachment = $location; } $deliverable->url = \Request::get('deliverable_url'); $deliverable->name = \Request::get('deliverable_name'); $deliverable->created_by = $user->id; $deliverable->date_delivered = Date('Y-m-d H:i:s'); $deliverable->client_id = \Request::get('client_id'); $deliverable->status = \Request::get('status'); $deliverable->client()->associate($client); $deliverable->save(); $data = array('client' => $client, 'deliverable' => $deliverable); /**sends email confirmation to client after deliverable is added**/ \Mail::send('emails.deliverable-available', $data, function ($message) use($client, $deliverable) { $recepient_email = $client->email; $recepient_name = $client->name; $subject = 'Your deliverable is now ready for you to review'; $message->to($recepient_email, $recepient_name)->subject($subject); }); \Session::flash('message', 'Your Deliverable Has Been Uploaded'); return redirect()->back(); }
public function addUser(Request $request) { $messages = ['client.not_in' => "You have to choose a client.", 'role.not_in' => "You have to choose a role."]; $this->validate($request, ['user_name' => 'required|max:25', 'user_email' => 'required', 'client' => 'not_in:0', 'role' => 'not_in:0'], $messages); $admin = \Request::get('admin'); $client_id = \Request::get('client'); $role_id = \Request::get('role'); $client = \p4\Client::find($client_id); $role = \p4\Role::find($role_id); $user = new \p4\User(); if ($admin == 'true') { $user->admin = '1'; } $user->name = \Request::get('user_name'); $user->email = \Request::get('user_email'); $user->client_id = $client->id; $user->role_id = $role->id; $user->role()->associate($role); $user->client()->associate($client); $user->save(); \Session::flash('message', 'User has been successfully created'); return redirect()->back(); }