/** * Run the migrations. * * @return void */ public function up() { $admin = new \App\Models\Users\User(["email" => "*****@*****.**", "password" => bcrypt("admin")]); $admin->save(); $admin->roles()->save(Role::find(1)); $student = new \App\Models\Users\User(["email" => "*****@*****.**", "password" => bcrypt("student")]); $student->save(); $student->roles()->save(Role::find(2)); }
public static function usersof($role) { return Role::where("title", "student")->get()->first()->users; }
/** * Remove the specified resource from storage. * * @param int $id * @return Response */ public function destroy($id) { // $role = Role::find($id); if ($role->delete()) { return response()->json(['success' => TRUE]); } }
/** * Display a listing of the resource. * * @return \Illuminate\Http\Response */ public function index() { return view('admin.index.student', ["students" => Role::usersof('student'), "trainings" => Training::all()]); }
/** * Show the form for editing the specified resource. * * @param int $id * @return Response */ public function edit($id) { // if (!Entrust::can('user-update')) { return redirect(''); } $this->data['sub_title'] = 'Edit User'; $this->data['user'] = User::find($id); $this->data['roles'] = Role::lists('name', 'id'); return view('backend.user.edit', $this->data); }
/** * Update the specified resource in storage. * * @param \Illuminate\Http\Request $request * @param int $id * @return \Illuminate\Http\Response */ public function update(Request $request, $id) { $rules = array('role' => 'required', 'email' => 'required|email', 'password' => '', 'lastname' => 'required', 'firstname' => 'required'); $validator = \Validator::make(\Input::all(), $rules); if ($validator->fails()) { return redirect()->back()->withInput()->withErrors($validator); } $user = User::find($id); if ($request->has('password')) { $user->password = bcrypt($request->input('password')); } $user->email = $request->input('email'); $user->last_name = $request->input('lastname'); $user->first_name = $request->input('firstname'); $user->roles()->detach(); $user->roles()->save(Role::find($request->input('role'))); $user->save(); return redirect()->back(); }