From 600bbe7746899d8ba08d770a456dac2abfd6ce42 Mon Sep 17 00:00:00 2001 From: Anders Date: Mon, 29 Jun 2020 12:29:23 +0200 Subject: [PATCH] Fixed routing and backend to staff section --- .../app/Http/Controllers/StaffController.php | 38 +++++++++---------- skolehjem/app/Staff.php | 37 +++++++++++++++++- .../views/admin/layout/base.blade.php | 9 +++++ .../views/admin/staff/index.blade.php | 6 +-- 4 files changed, 67 insertions(+), 23 deletions(-) diff --git a/skolehjem/app/Http/Controllers/StaffController.php b/skolehjem/app/Http/Controllers/StaffController.php index 38b2821..c5fbf78 100644 --- a/skolehjem/app/Http/Controllers/StaffController.php +++ b/skolehjem/app/Http/Controllers/StaffController.php @@ -16,10 +16,10 @@ class StaffController extends Controller // $this->middleware([ "auth" ])->only("logout"); // $this->middleware([ "guest" ])->only("login"); // -// $this->middleware([ "permission:user.list", "role:admin" ])->only("index"); -// $this->middleware([ "permission:user.show", "role:admin" ])->only("show"); -// $this->middleware([ "permission:user.edit", "role:admin" ])->only([ "edit", "update" ]); -// $this->middleware([ "permission:user.delete", "role:admin" ])->only("delete"); +// $this->middleware([ "permission:staff.list", "role:admin" ])->only("index"); +// $this->middleware([ "permission:staff.show", "role:admin" ])->only("show"); +// $this->middleware([ "permission:staff.edit", "role:admin" ])->only([ "edit", "update" ]); +// $this->middleware([ "permission:staff.delete", "role:admin" ])->only("delete"); } /** @@ -30,9 +30,9 @@ class StaffController extends Controller */ public function index(Request $request) { - $staff = Staff::query()->paginate($request->query("page", 20)); + $staffs = Staff::query()->paginate($request->query("page", 20)); - return Response::detect("staff.index", [ "staff" => $staff ]); + return Response::detect("staff.index", [ "staffs" => $staffs ]); } /** @@ -58,9 +58,9 @@ class StaffController extends Controller $data = $request->validate([ "name_first" => "required|max:255", "name_last" => "required|max:255", - "email" => "required|email|unique:users", + "email" => "required|email|unique:staff", "password" => "required|max:60", - "phone" => "required|unique:users", + "phone" => "required|unique:staff", ]); @@ -68,7 +68,7 @@ class StaffController extends Controller $staff = new Staff($data); - Log::debug("CREATED USER [NOT PERSISTED YET]"); + Log::debug("CREATED STAFF [NOT PERSISTED YET]"); $staff->save(); @@ -121,25 +121,25 @@ class StaffController extends Controller // $data = $request->validate([ // "name_first" => "max:255", // "name_last" => "max:255", -// "email" => "email|unique:users", +// "email" => "email|unique:staff", // "password" => "max:60", -// "phone" => "unique:users", +// "phone" => "unique:staff", // ]); - // Validates if the user is updating itself or another user. + // Validates if the staff is updating itself or another staff. // if($id === Auth::id()) { -// $user = Auth::user(); +// $staff = Auth::staff(); // -// $user->update($data); +// $staff->update($data); // -// $user->save(); -// return Response::detect("users.edit", [ -// "user" => $user +// $staff->save(); +// return Response::detect("staff.edit", [ +// "staff" => $staff // ]); // } //TODO: Implement when security's ready!!! -// else if(Auth::user()->hasPermissionTo("user.edit")) { +// else if(Auth::staff()->hasPermissionTo("staff.edit")) { $staff = Staff::find($id); /** @var Staff $staff */ @@ -150,7 +150,7 @@ class StaffController extends Controller $staffs = Staff::query()->paginate(20); - return Response::detect("users.index", [ + return Response::detect("staff.index", [ "staffs" => $staffs ]); } diff --git a/skolehjem/app/Staff.php b/skolehjem/app/Staff.php index 23fc501..841134d 100644 --- a/skolehjem/app/Staff.php +++ b/skolehjem/app/Staff.php @@ -3,8 +3,43 @@ namespace App; use Illuminate\Database\Eloquent\Model; +use Illuminate\Notifications\Notifiable; +use Illuminate\Support\Facades\Hash; +use Spatie\Permission\Traits\HasRoles; class Staff extends Model { - // + use Notifiable; + use HasRoles; + + /** + * The attributes that are mass assignable. + * + * @var array + */ + protected $fillable = [ + 'name_first', "name_last", 'email', 'password', "phone" + ]; + + /** + * The attributes that should be hidden for arrays. + * + * @var array + */ + protected $hidden = [ + 'password', 'remember_token', + ]; + + /** + * The attributes that should be cast to native types. + * + * @var array + */ + protected $casts = [ + 'email_verified_at' => 'datetime', + ]; + + public function setPasswordAttribute($password) { + $this->attributes["password"] = Hash::make($password); + } } diff --git a/skolehjem/resources/views/admin/layout/base.blade.php b/skolehjem/resources/views/admin/layout/base.blade.php index e9ee9cb..e3398e2 100644 --- a/skolehjem/resources/views/admin/layout/base.blade.php +++ b/skolehjem/resources/views/admin/layout/base.blade.php @@ -58,6 +58,15 @@ CreateOpret Kontakt +
+

Personale

+ + +
diff --git a/skolehjem/resources/views/admin/staff/index.blade.php b/skolehjem/resources/views/admin/staff/index.blade.php index e206090..88f80ff 100644 --- a/skolehjem/resources/views/admin/staff/index.blade.php +++ b/skolehjem/resources/views/admin/staff/index.blade.php @@ -25,9 +25,9 @@ {{ $staff->name_last }} {{ $staff->email }} {{ $staff->phone }} - $staff->id ]) }}">Update + $staff->id ]) }}">Update -
$staff ]) }}" class="w-100"> + $staff ]) }}" class="w-100"> @csrf @method("delete") @@ -38,5 +38,5 @@ @endforeach - {{ $staff->links() }} + {{ $staffs->links() }} @endsection