Working on ResourceController.php again..
This commit is contained in:
parent
903341c1ec
commit
a755fd9680
|
@ -3,6 +3,7 @@
|
|||
namespace App\Http\Controllers;
|
||||
|
||||
use App\Resource;
|
||||
use App\ResourceExtension;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Http\Response;
|
||||
|
||||
|
@ -49,13 +50,31 @@ class ResourceController extends Controller
|
|||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
$data = $request->validate([
|
||||
"" => ""
|
||||
]);
|
||||
// $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 = new Resource($data);
|
||||
|
||||
$resource->save();
|
||||
}
|
||||
|
||||
return Response::detect("resources.store");
|
||||
}
|
||||
|
|
|
@ -6,5 +6,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");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,5 +6,7 @@ use Illuminate\Database\Eloquent\Model;
|
|||
|
||||
class ResourceCategory extends Model
|
||||
{
|
||||
//
|
||||
public function resourceExtensions() {
|
||||
return $this->hasMany("App\ResourceExtension");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -6,5 +6,7 @@ use Illuminate\Database\Eloquent\Model;
|
|||
|
||||
class ResourceExtension extends Model
|
||||
{
|
||||
//
|
||||
public function resources() {
|
||||
return $this->hasMany("App\Resource");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -0,0 +1,34 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateResourceCategory extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('resource_categories', function (Blueprint $table) {
|
||||
$table->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');
|
||||
}
|
||||
}
|
|
@ -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");
|
||||
});
|
||||
}
|
||||
|
|
@ -0,0 +1,35 @@
|
|||
<?php
|
||||
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
|
||||
class CreateResource extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('resources', function (Blueprint $table) {
|
||||
$table->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');
|
||||
}
|
||||
}
|
File diff suppressed because one or more lines are too long
File diff suppressed because one or more lines are too long
Loading…
Reference in New Issue