diff --git a/skolehjem/app/Http/Controllers/ResourceController.php b/skolehjem/app/Http/Controllers/ResourceController.php index 20fe0ed..4982335 100644 --- a/skolehjem/app/Http/Controllers/ResourceController.php +++ b/skolehjem/app/Http/Controllers/ResourceController.php @@ -51,28 +51,23 @@ 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 { + $data = [ + "extension" => $file->extension(), + "description" => "" + ]; + $resourceExtension = new ResourceExtension($data); + $resourceExtension->save(); + } else { $resource = new Resource(); - $resource->resourceExtension()->save($resourceExtension); - - + $resource->extension_id = $resourceExtension->id; + $resource->filename = substr(md5($file->getFilename() . rand()), 0, 7); $resource->save(); } diff --git a/skolehjem/app/Http/Controllers/settingsController.php b/skolehjem/app/Http/Controllers/settingsController.php new file mode 100644 index 0000000..c4d4290 --- /dev/null +++ b/skolehjem/app/Http/Controllers/settingsController.php @@ -0,0 +1,14 @@ +belongsTo("App\ResourceExtension"); } diff --git a/skolehjem/app/ResourceExtension.php b/skolehjem/app/ResourceExtension.php index 8936f7f..abc8dd5 100644 --- a/skolehjem/app/ResourceExtension.php +++ b/skolehjem/app/ResourceExtension.php @@ -12,6 +12,10 @@ use Illuminate\Database\Eloquent\Model; //Class of which should extend Model Library class ResourceExtension extends Model { + protected $fillable = [ + 'extension', 'description' + ]; + public function resources() { return $this->hasMany("App\Resource"); } diff --git a/skolehjem/routes/web.php b/skolehjem/routes/web.php index efa654a..d76ebc9 100644 --- a/skolehjem/routes/web.php +++ b/skolehjem/routes/web.php @@ -30,6 +30,7 @@ Route::get("/events/accountsignups", "EventController@accountsignups")->name("ev Route::get("phones", "PhoneController@index")->name("phones.index"); Route::get("/washing-reservationsapi", "WashingReservationController@api")->name("washing-reservations.api"); Route::get("/app/washing-reservations", "WashingReservationController@appindex")->name("washing-reservations.appindex"); +Route::get("/settings", "settingsController@settings")->name("settings.index"); //Search/Filter Route::get("/contactsapi", "ContactController@search")->name("contacts.search");