diff --git a/skolehjem/app/Http/Controllers/ResourceController.php b/skolehjem/app/Http/Controllers/ResourceController.php
index 0563f52..7fe829d 100644
--- a/skolehjem/app/Http/Controllers/ResourceController.php
+++ b/skolehjem/app/Http/Controllers/ResourceController.php
@@ -2,6 +2,8 @@
namespace App\Http\Controllers;
+use App\Resource;
+use App\ResourceExtension;
use Illuminate\Http\Request;
use Illuminate\Http\Response;
@@ -23,9 +25,11 @@ class ResourceController extends Controller
*
* @return \Illuminate\Http\Response
*/
- public function index()
+ public function index(Request $request)
{
+ $resources = Resource::query()->paginate($request->input("limit", 20));
+ return Response::detect("resources.index", [ "resources" => $resources ]);
}
/**
@@ -35,7 +39,7 @@ class ResourceController extends Controller
*/
public function create()
{
- //
+ return Response::detect("resources.create");
}
/**
@@ -46,7 +50,33 @@ class ResourceController extends Controller
*/
public function store(Request $request)
{
- //
+// $data = $request->validate([
+// "" => ""
+// ]);
+
+// $resource = new Resource($data);
+
+ $file = $request->file("resource");
+
+
+
+ $resourceExtension = ResourceExtension::where("extension", "=", $file->extension())->first();
+
+ if($resourceExtension === null) {
+ //TODO: Create new resourceExtension!
+ }
+ else {
+
+ $resource = new Resource();
+
+ $resource->resourceExtension()->save($resourceExtension);
+
+
+
+ $resource->save();
+ }
+
+ return Response::detect("resources.store");
}
/**
diff --git a/skolehjem/app/Http/Controllers/UserController.php b/skolehjem/app/Http/Controllers/UserController.php
index 6a0ce84..1a5bf7b 100644
--- a/skolehjem/app/Http/Controllers/UserController.php
+++ b/skolehjem/app/Http/Controllers/UserController.php
@@ -76,6 +76,7 @@ class UserController extends Controller
// Log::debug("CREATED USER [NOT PERSISTED YET]");
+ $user->assignRole([ "R1", "R2" ]);
$user->save();
// Log::debug("SAVED USER");
diff --git a/skolehjem/app/Http/Middleware/CheckAuth.php b/skolehjem/app/Http/Middleware/CheckAuth.php
index 2c5df81..7256fae 100644
--- a/skolehjem/app/Http/Middleware/CheckAuth.php
+++ b/skolehjem/app/Http/Middleware/CheckAuth.php
@@ -10,9 +10,11 @@ class CheckAuth
/**
* Handle an incoming request.
*
- * @param \Illuminate\Http\Request $request
- * @param \Closure $next
+ * @param \Illuminate\Http\Request $request
+ * @param \Closure $next
+ * @param $permissions
* @return mixed
+ * @throws \Exception
*/
public function handle($request, Closure $next, $permissions)
{
diff --git a/skolehjem/app/Resource.php b/skolehjem/app/Resource.php
index 1594cee..97431b9 100644
--- a/skolehjem/app/Resource.php
+++ b/skolehjem/app/Resource.php
@@ -11,5 +11,11 @@ use Illuminate\Database\Eloquent\Model;
class Resource extends Model
{
- //
+ public function resourceExtension() {
+ return $this->belongsTo("App\ResourceExtension");
+ }
+
+ public function resourceCategory() {
+ return $this->hasOneThrough("App\ResourceCategory", "App\ResourceExtension");
+ }
}
diff --git a/skolehjem/app/ResourceCategory.php b/skolehjem/app/ResourceCategory.php
index 8869761..7d88dda 100644
--- a/skolehjem/app/ResourceCategory.php
+++ b/skolehjem/app/ResourceCategory.php
@@ -11,5 +11,7 @@ use Illuminate\Database\Eloquent\Model;
class ResourceCategory extends Model
{
- //
+ public function resourceExtensions() {
+ return $this->hasMany("App\ResourceExtension");
+ }
}
diff --git a/skolehjem/app/ResourceExtension.php b/skolehjem/app/ResourceExtension.php
index fb7ee37..9651943 100644
--- a/skolehjem/app/ResourceExtension.php
+++ b/skolehjem/app/ResourceExtension.php
@@ -11,5 +11,7 @@ use Illuminate\Database\Eloquent\Model;
class ResourceExtension extends Model
{
- //
+ public function resources() {
+ return $this->hasMany("App\Resource");
+ }
}
diff --git a/skolehjem/database/migrations/2020_07_01_061911_create_resource_category.php b/skolehjem/database/migrations/2020_07_01_061911_create_resource_category.php
new file mode 100644
index 0000000..4d797bb
--- /dev/null
+++ b/skolehjem/database/migrations/2020_07_01_061911_create_resource_category.php
@@ -0,0 +1,34 @@
+id();
+ $table->string("name", 60)->unique();
+ $table->text("description");
+ $table->string("slug", 255)->unique();
+ $table->timestamps();
+ });
+ }
+
+ /**
+ * Reverse the migrations.
+ *
+ * @return void
+ */
+ public function down()
+ {
+ Schema::dropIfExists('resource_categories');
+ }
+}
diff --git a/skolehjem/database/migrations/2020_06_30_092130_create_resource_extensions.php b/skolehjem/database/migrations/2020_07_01_062112_create_resource_extension.php
similarity index 69%
rename from skolehjem/database/migrations/2020_06_30_092130_create_resource_extensions.php
rename to skolehjem/database/migrations/2020_07_01_062112_create_resource_extension.php
index 3f1abb5..ddba508 100644
--- a/skolehjem/database/migrations/2020_06_30_092130_create_resource_extensions.php
+++ b/skolehjem/database/migrations/2020_07_01_062112_create_resource_extension.php
@@ -4,7 +4,7 @@ use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
-class CreateResourceExtensions extends Migration
+class CreateResourceExtension extends Migration
{
/**
* Run the migrations.
@@ -15,9 +15,12 @@ class CreateResourceExtensions extends Migration
{
Schema::create('resource_extensions', function (Blueprint $table) {
$table->id();
- $table->string("extension")->unique();
+ $table->string("extension", 60)->unique();
$table->text("description");
+ $table->unsignedInteger("resource_category_id");
$table->timestamps();
+
+ $table->foreign("resource_category_id")->references("id")->on("resource_categories");
});
}
diff --git a/skolehjem/database/migrations/2020_07_01_062544_create_resource.php b/skolehjem/database/migrations/2020_07_01_062544_create_resource.php
new file mode 100644
index 0000000..0176e1b
--- /dev/null
+++ b/skolehjem/database/migrations/2020_07_01_062544_create_resource.php
@@ -0,0 +1,35 @@
+id();
+ $table->string("filename")->unique();
+ $table->unsignedInteger("extension_id");
+ $table->timestamps();
+
+ $table->foreign("extension_id")->references("id")->on("resource_extensions");
+ });
+ }
+
+ /**
+ * Reverse the migrations.
+ *
+ * @return void
+ */
+ public function down()
+ {
+ Schema::dropIfExists('resources');
+ }
+}
diff --git a/skolehjem/database/seeds/PermissionSeeder.php b/skolehjem/database/seeds/PermissionSeeder.php
index 53de434..befed63 100644
--- a/skolehjem/database/seeds/PermissionSeeder.php
+++ b/skolehjem/database/seeds/PermissionSeeder.php
@@ -17,6 +17,7 @@ class PermissionSeeder extends Seeder
/**
* The USER specific permissions
*/
+ "user.create" => "Creation of new user",
"user.list" => "Access to list the users.",
"user.show" => "Shows another user profile.",
"user.edit" => "Allows editing of other users.",
diff --git a/skolehjem/resources/views/admin/users/edit.blade.php b/skolehjem/resources/views/admin/users/edit.blade.php
index 73ae118..af0348c 100644
--- a/skolehjem/resources/views/admin/users/edit.blade.php
+++ b/skolehjem/resources/views/admin/users/edit.blade.php
@@ -19,7 +19,7 @@
-
+