";}
+
+ }
+ public function pendings(){
+
+ $countPendings = DB::table('users')->where("status",null)->count();
+ $pendings = DB::table('users')->where('status',null)->get();
+ $roles = DB::table('roles')->get();
+ return view('/users/pendings')->with(['pendings'=>$pendings,"countPendings"=>$countPendings,'roles'=>$roles
+ ]);
+ }
+ public function reject(Request $request){
+ $insertQuery = DB::table('bookings')->insert(['pickup_time'=>$request->input('pickup_time'),
+ 'return_time'=>$request->input('return_time'),'count'=>$request->input('count'),
+ 'description'=>$request->input('description'),'destination'=>$request->input('destination'),'approval'=>false,'driver_id'=>null,'plate_no'=>null,
+ 'user_id'=>$request->input('user_id')]);
+
+ }
+
/**
* Show the form for creating a new resource.
*
@@ -32,6 +105,36 @@ public function create()
public function store(Request $request)
{
//
+ $passRegexMessage = ['password.regex'=>' Password must has 8 letters, at least one letter, one number and one special charecter ',
+ 'phone.regex'=>'phone number must start with 07 and not be greater than 10 numbers'];
+ $rules = array(
+ 'name' => ['required', 'string', 'max:255'],
+ 'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
+ 'password' => ['required', 'string', 'min:6', 'confirmed'],
+ 'position' =>['required','string','min:4'],
+ 'directorate'=>['required','string','min:4'],
+ 'phone' =>['required','regex:/^07[0-9]{8}/'],
+ );
+ $validator = Validator::make($request->all(),$rules,$passRegexMessage);
+
+ if($validator->fails()){
+
+ return $validator->errors()->toArray();
+
+ }
+ else{
+ User::create([
+ 'name' => $request->input('name'),
+ 'email' => $request->input('email'),
+ 'position' =>$request->input('position'),
+ 'directorate' => $request->input('directorate'),
+ 'phone' => $request->input('phone'),
+ 'status' =>$request->input('status'),
+ 'password' => Hash::make($request->input('password')),
+ ]);
+ $id = DB::getPdo()->lastInsertId();
+ return 'successfully done '. $id ;
+ }
}
/**
@@ -55,8 +158,9 @@ public function show($id)
* @param int $id
* @return \Illuminate\Http\Response
*/
- public function edit(Request $request) {
-
+ public function edit($id) {
+ $data = User::find($id);
+ return $data;
}
/**
* Update the specified resource in storage.
@@ -68,6 +172,37 @@ public function edit(Request $request) {
public function update(Request $request, $id)
{
//
+
+ // $passRegexMessage = ['password.regex'=>' Password must has 8 letters, at least one letter, one number and one special charecter ',
+ // 'phone.regex'=>'phone number must start with 07 and not be greater than 10 numbers'];
+ $rules = array(
+ 'position' =>['required','string','min:4'],
+ 'directorate'=>['required','string','min:4'],
+ // 'name' => ['required', 'string', 'max:255'],
+ // 'email' => ['required', 'string', 'email', 'max:255', 'unique:users'],
+ // 'password' => ['required', 'string', 'min:6', 'confirmed'],
+ // 'phone' =>['required','regex:/^07[0-9]{8}/'],
+ );
+ $validator = Validator::make($request->all(),$rules);
+
+ if($validator->fails()){
+
+ return $validator->errors()->toArray();
+
+ }
+ else{
+ $user = User::find($id);
+ $user->position = $request->input('position');
+ $user->directorate =$request->input('directorate');
+ $user->status = $request->input('status');
+ $user->save();
+ // $user->name = $request->input('name');
+ // $user->email = $request->input('email');
+ // $user->phone = $request->input('phone');
+ // $user->password = Hash::make($request->input('password'));
+
+ return 'successfully Updated user with ID: '. $id ;
+ }
}
/**
@@ -76,9 +211,17 @@ public function update(Request $request, $id)
* @param int $id
* @return \Illuminate\Http\Response
*/
- public function destroy($id)
+ public function destroy($id,Request $yesOrNo)
{
//
+ $dataID = DB::table("users")->where('id',$id)->first();
+ $deleteResult = DB::table('users')->where('id',$id)->delete();
+ if($deleteResult ===1){
+ $result = "driver with ID: " .$dataID->id. " successfully deleted from table";
+ return $result; }
+ else{
+ return "Deletion not occured";
+ }
}
}
diff --git a/app/Http/Kernel.php b/app/Http/Kernel.php
index a3d8c48..ff108a4 100644
--- a/app/Http/Kernel.php
+++ b/app/Http/Kernel.php
@@ -60,6 +60,9 @@ class Kernel extends HttpKernel
'signed' => \Illuminate\Routing\Middleware\ValidateSignature::class,
'throttle' => \Illuminate\Routing\Middleware\ThrottleRequests::class,
'verified' => \Illuminate\Auth\Middleware\EnsureEmailIsVerified::class,
+ 'role' => \Spatie\Permission\Middlewares\RoleMiddleware::class,
+ 'permission' => \Spatie\Permission\Middlewares\PermissionMiddleware::class,
+ 'role_or_permission' => \Spatie\Permission\Middlewares\RoleOrPermissionMiddleware::class,
];
/**
diff --git a/app/User.php b/app/User.php
index c410023..c52a7b7 100644
--- a/app/User.php
+++ b/app/User.php
@@ -1,14 +1,14 @@
=7.0"
+ },
+ "require-dev": {
+ "orchestra/testbench": "~3.4.2|~3.5.0|~3.6.0|~3.7.0|~3.8.0",
+ "phpunit/phpunit": "^5.7|6.2|^7.0",
+ "predis/predis": "^1.1"
+ },
+ "type": "library",
+ "extra": {
+ "laravel": {
+ "providers": [
+ "Spatie\\Permission\\PermissionServiceProvider"
+ ]
+ }
+ },
+ "autoload": {
+ "psr-4": {
+ "Spatie\\Permission\\": "src"
+ },
+ "files": [
+ "src/helpers.php"
+ ]
+ },
+ "notification-url": "https://packagist.org/downloads/",
+ "license": [
+ "MIT"
+ ],
+ "authors": [
+ {
+ "name": "Freek Van der Herten",
+ "email": "freek@spatie.be",
+ "homepage": "https://spatie.be",
+ "role": "Developer"
+ }
+ ],
+ "description": "Permission handling for Laravel 5.4 and up",
+ "homepage": "https://github.com/spatie/laravel-permission",
+ "keywords": [
+ "acl",
+ "laravel",
+ "permission",
+ "security",
+ "spatie"
+ ],
+ "time": "2019-02-26T21:25:08+00:00"
+ },
{
"name": "swiftmailer/swiftmailer",
"version": "v6.1.3",
diff --git a/config/permission.php b/config/permission.php
new file mode 100644
index 0000000..fbf9b89
--- /dev/null
+++ b/config/permission.php
@@ -0,0 +1,129 @@
+ [
+
+ /*
+ * When using the "HasPermissions" trait from this package, we need to know which
+ * Eloquent model should be used to retrieve your permissions. Of course, it
+ * is often just the "Permission" model but you may use whatever you like.
+ *
+ * The model you want to use as a Permission model needs to implement the
+ * `Spatie\Permission\Contracts\Permission` contract.
+ */
+
+ 'permission' => Spatie\Permission\Models\Permission::class,
+
+ /*
+ * When using the "HasRoles" trait from this package, we need to know which
+ * Eloquent model should be used to retrieve your roles. Of course, it
+ * is often just the "Role" model but you may use whatever you like.
+ *
+ * The model you want to use as a Role model needs to implement the
+ * `Spatie\Permission\Contracts\Role` contract.
+ */
+
+ 'role' => Spatie\Permission\Models\Role::class,
+
+ ],
+
+ 'table_names' => [
+
+ /*
+ * When using the "HasRoles" trait from this package, we need to know which
+ * table should be used to retrieve your roles. We have chosen a basic
+ * default value but you may easily change it to any table you like.
+ */
+
+ 'roles' => 'roles',
+
+ /*
+ * When using the "HasPermissions" trait from this package, we need to know which
+ * table should be used to retrieve your permissions. We have chosen a basic
+ * default value but you may easily change it to any table you like.
+ */
+
+ 'permissions' => 'permissions',
+
+ /*
+ * When using the "HasPermissions" trait from this package, we need to know which
+ * table should be used to retrieve your models permissions. We have chosen a
+ * basic default value but you may easily change it to any table you like.
+ */
+
+ 'model_has_permissions' => 'model_has_permissions',
+
+ /*
+ * When using the "HasRoles" trait from this package, we need to know which
+ * table should be used to retrieve your models roles. We have chosen a
+ * basic default value but you may easily change it to any table you like.
+ */
+
+ 'model_has_roles' => 'model_has_roles',
+
+ /*
+ * When using the "HasRoles" trait from this package, we need to know which
+ * table should be used to retrieve your roles permissions. We have chosen a
+ * basic default value but you may easily change it to any table you like.
+ */
+
+ 'role_has_permissions' => 'role_has_permissions',
+ ],
+
+ 'column_names' => [
+
+ /*
+ * Change this if you want to name the related model primary key other than
+ * `model_id`.
+ *
+ * For example, this would be nice if your primary keys are all UUIDs. In
+ * that case, name this `model_uuid`.
+ */
+
+ 'model_morph_key' => 'model_id',
+ ],
+
+ /*
+ * When set to true, the required permission/role names are added to the exception
+ * message. This could be considered an information leak in some contexts, so
+ * the default setting is false here for optimum safety.
+ */
+
+ 'display_permission_in_exception' => false,
+
+ 'cache' => [
+
+ /*
+ * By default all permissions are cached for 24 hours to speed up performance.
+ * When permissions or roles are updated the cache is flushed automatically.
+ */
+
+ 'expiration_time' => \DateInterval::createFromDateString('24 hours'),
+
+ /*
+ * The key to use when tagging and prefixing entries in the cache.
+ */
+
+ 'key' => 'spatie.permission.cache',
+
+ /*
+ * When checking for a permission against a model by passing a Permission
+ * instance to the check, this key determines what attribute on the
+ * Permissions model is used to cache against.
+ *
+ * Ideally, this should match your preferred way of checking permissions, eg:
+ * `$user->can('view-posts')` would be 'name'.
+ */
+
+ 'model_key' => 'name',
+
+ /*
+ * You may optionally indicate a specific cache driver to use for permission and
+ * role caching using any of the `store` drivers listed in the cache.php config
+ * file. Using 'default' here means to use the `default` set in cache.php.
+ */
+
+ 'store' => 'default',
+ ],
+];
diff --git a/database/migrations/2019_01_02_071350_create_cars_table.php b/database/migrations/2019_01_02_071350_create_cars_table.php
index 1f47cdb..2962227 100644
--- a/database/migrations/2019_01_02_071350_create_cars_table.php
+++ b/database/migrations/2019_01_02_071350_create_cars_table.php
@@ -14,12 +14,12 @@ class CreateCarsTable extends Migration
public function up()
{
Schema::create('cars', function (Blueprint $table) {
- $table->increments('car_id');
- $table->string('plate_no')->unique();
+ $table->integer('plate_no')->unsigned()->unique();
$table->string('color',15);
$table->string('model',45);
$table->string('type',25);
$table->boolean('status')->default(1);
+
$table->timestamps();
});
}
diff --git a/database/migrations/2019_01_02_071557_create_bookings_table.php b/database/migrations/2019_01_02_071557_create_bookings_table.php
index 78584cd..dd748cc 100644
--- a/database/migrations/2019_01_02_071557_create_bookings_table.php
+++ b/database/migrations/2019_01_02_071557_create_bookings_table.php
@@ -16,11 +16,16 @@ public function up()
Schema::create('bookings', function (Blueprint $table) {
$table->increments('booking_id');
$table->dateTime('pickup_time');
- $table->dateTime('return_time');
- $table->tinyInteger('count');
- $table->longText('description');
- $table->string('destination');
- $table->boolean('approval');
+ $table->dateTime('return_time');
+ $table->tinyInteger('count');
+ $table->longText('description');
+ $table->string('destination');
+ $table->dateTime('book_created_time');
+ $table->dateTime('book_updated_time');
+ $table->boolean('approval')->nullable();
+ $table->longText('approver_description')->nullable();
+ $table->dateTime('approval_pickup_time')->nullable();
+ $table->dateTime('approval_return_time')->nullable();
$table->timestamps();
});
}
diff --git a/database/migrations/2019_01_03_080034_add_foreign_keys_to_bookings_table.php b/database/migrations/2019_01_03_080034_add_foreign_keys_to_bookings_table.php
index 3f8b340..9a6d949 100644
--- a/database/migrations/2019_01_03_080034_add_foreign_keys_to_bookings_table.php
+++ b/database/migrations/2019_01_03_080034_add_foreign_keys_to_bookings_table.php
@@ -18,16 +18,18 @@ public function up()
$table->foreign('driver_id')->references('driver_id')->on('drivers')->onDelete('no action');
});
-
Schema::table('bookings',function (Blueprint $table){
- $table->integer('car_id')->unsigned()->nullable();
- $table->foreign('car_id')->references('car_id')->on('cars')->onDelete('no action');
+ $table->integer('plate_no')->nullable();
+ $table->foreign('plate_no')->references('plate_no')->on('cars')->onDelete('no action');
});
-
Schema::table('bookings',function (Blueprint $table){
$table->integer('user_id')->unsigned();
$table->foreign('user_id')->references('id')->on('users')->onDelete('no action');
});
+ Schema::table('bookings',function (Blueprint $table){
+ $table->integer('approver_user_id')->unsigned()->nullable();
+ $table->foreign('approver_user_id')->references('id')->on('users')->onDelete('no action');
+ });
}
/**
diff --git a/database/migrations/2019_02_12_050329_book_vehicals.php b/database/migrations/2019_02_12_050329_book_vehicals.php
deleted file mode 100644
index 4913fd9..0000000
--- a/database/migrations/2019_02_12_050329_book_vehicals.php
+++ /dev/null
@@ -1,39 +0,0 @@
-integer('user_id');
- $table->tinyInteger('count');
- $table->dateTime('pickup_time');
- $table->dateTime('return_time');
- $table->longText('description');
- $table->string('destination',255);
- $table->timestamps();
- });
- }
-
-
- /**
- * Reverse the migrations.
- *
- * @return void
- */
- public function down()
- {
- //
- Schema::dropIfExists('bookACar');
- }
-}
diff --git a/database/migrations/2019_02_14_065338_add_null_conditional_constraint.php b/database/migrations/2019_02_14_065338_add_null_conditional_constraint.php
deleted file mode 100644
index 4b3fa7b..0000000
--- a/database/migrations/2019_02_14_065338_add_null_conditional_constraint.php
+++ /dev/null
@@ -1,35 +0,0 @@
-increments('id');
+ $table->string('name');
+ $table->string('guard_name');
+ $table->timestamps();
+ });
+
+ Schema::create($tableNames['roles'], function (Blueprint $table) {
+ $table->increments('id');
+ $table->string('name');
+ $table->string('guard_name');
+ $table->timestamps();
+ });
+
+ Schema::create($tableNames['model_has_permissions'], function (Blueprint $table) use ($tableNames, $columnNames) {
+ $table->unsignedInteger('permission_id');
+
+ $table->string('model_type');
+ $table->unsignedBigInteger($columnNames['model_morph_key']);
+ $table->index([$columnNames['model_morph_key'], 'model_type', ]);
+
+ $table->foreign('permission_id')
+ ->references('id')
+ ->on($tableNames['permissions'])
+ ->onDelete('cascade');
+
+ $table->primary(['permission_id', $columnNames['model_morph_key'], 'model_type'],
+ 'model_has_permissions_permission_model_type_primary');
+ });
+
+ Schema::create($tableNames['model_has_roles'], function (Blueprint $table) use ($tableNames, $columnNames) {
+ $table->unsignedInteger('role_id');
+
+ $table->string('model_type');
+ $table->unsignedBigInteger($columnNames['model_morph_key']);
+ $table->index([$columnNames['model_morph_key'], 'model_type', ]);
+
+ $table->foreign('role_id')
+ ->references('id')
+ ->on($tableNames['roles'])
+ ->onDelete('cascade');
+
+ $table->primary(['role_id', $columnNames['model_morph_key'], 'model_type'],
+ 'model_has_roles_role_model_type_primary');
+ });
+
+ Schema::create($tableNames['role_has_permissions'], function (Blueprint $table) use ($tableNames) {
+ $table->unsignedInteger('permission_id');
+ $table->unsignedInteger('role_id');
+
+ $table->foreign('permission_id')
+ ->references('id')
+ ->on($tableNames['permissions'])
+ ->onDelete('cascade');
+
+ $table->foreign('role_id')
+ ->references('id')
+ ->on($tableNames['roles'])
+ ->onDelete('cascade');
+
+ $table->primary(['permission_id', 'role_id']);
+
+ app('cache')
+ ->store(config('permission.cache.store') != 'default' ? config('permission.cache.store') : null)
+ ->forget(config('permission.cache.key'));
+ });
+ }
+
+ /**
+ * Reverse the migrations.
+ *
+ * @return void
+ */
+ public function down()
+ {
+ $tableNames = config('permission.table_names');
+
+ Schema::drop($tableNames['role_has_permissions']);
+ Schema::drop($tableNames['model_has_roles']);
+ Schema::drop($tableNames['model_has_permissions']);
+ Schema::drop($tableNames['roles']);
+ Schema::drop($tableNames['permissions']);
+ }
+}
diff --git a/database/migrations/2019_03_02_141023_add_status_user.php b/database/migrations/2019_03_02_141023_add_status_user.php
new file mode 100644
index 0000000..0947757
--- /dev/null
+++ b/database/migrations/2019_03_02_141023_add_status_user.php
@@ -0,0 +1,33 @@
+boolean('status')->nullable();
+ });
+ }
+
+ /**
+ * Reverse the migrations.
+ *
+ * @return void
+ */
+ public function down()
+ {
+ Schema::table('users', function (Blueprint $table) {
+ //
+ });
+ }
+}
diff --git a/public/js/crud.js b/public/js/crud.js
index e1d5bb9..ceb5b38 100644
--- a/public/js/crud.js
+++ b/public/js/crud.js
@@ -19,13 +19,13 @@ $("#insertButton, .updateBtn").click(function(){
//load update data and validation of insert and update form
var loc = window.location.href;
-ApprovalBooking();
-function ApprovalBooking(){
+insertBooking();
+function insertBooking(){
$(".pending_table").submit(function(e){
e.preventDefault();
var dataForm = ($(this).serialize());
- var element =$(this);
+
$.ajax({
method: "post",
url: "/bookings/",
@@ -49,13 +49,35 @@ $("#bookACar").submit(function(e){
$.ajax({
method: 'POST',
- url: "/book vehical",
+ url: "/bookings",
data: data,
success: function(data){
- $("#carBooking").modal('hide');
- $("#sucDiv").html(data);
- $("#sucDiv").fadeIn();
- $("#sucDiv").fadeOut(2000);
+ console.log(data);
+ // $("#carBooking").modal('hide');
+ // $("#sucDiv").html(data);
+ // $("#sucDiv").fadeIn();
+ // $("#sucDiv").fadeOut(2000);
+ }
+ });
+ $.ajax({
+ method: 'POST',
+ url: "/bookings/freeCar",
+ data: data,
+ success: function(data){
+ for (var i = 0; i < data.length; i++) {
+ $("select#plate_no").append("");
+ }
+ // $("select#plate_no").append("");
+ $("#approval").find('option').remove().end().append("")
+ $("#driver_id").find('option').remove().end().append("")
+ if(data['bookings']['approval']==null){
+ $("#approval").append("");
+ $("#approval").append("");
+ }
+ if(data['bookings']['approval']==true){
+
+ $("#approval").append("");
+ }
+ if(data['bookings']['approval']==false){
+ $("#approval").append("");
+
+ }
+
+ var i;
+
+ for (i = 0; i < countOfCars; i++) {
+
+ $('.plate_no').append("");
+
+ }
+ for (i = 0; i < countOfDrivers; i++) {
+ $('.driver_id').append("");
+ }
+
+ // $("#plate_no").val(data['plate_no']);
+ // $("#plate_no").append("");
+ $("#approval_pickup_time").val(data['bookings']['approval_pickup_time']);
+ $("#approval_return_time").val(data['bookings']['approval_return_time']);
+ $("#approver_description").val(data['bookings']['approver_description']);
+
+ }
+ });
+ $("#updateModal").modal('show');
+ });
+}
});
//end of jqery
\ No newline at end of file
diff --git a/resources/views/bookings/index.blade.php b/resources/views/bookings/index.blade.php
index 3ca570d..449a21c 100644
--- a/resources/views/bookings/index.blade.php
+++ b/resources/views/bookings/index.blade.php
@@ -1,225 +1,173 @@
@extends("layouts.app")
@section('content')
-
-
-
-
+
-
-
-
-
-
-
-
Update
-
-
-
-
-
-
PENDINGS BOOKS
-
-@if($countOfRows==0)
-
There is no booking wait for approval
-@else
-
there are {{ $countOfRows }} bookings wait for approvement