mirror of
https://git.meshkee.com/cssd/cssd-back.git
synced 2026-10-10 19:51:07 +03:30
add cycle
This commit is contained in:
@@ -0,0 +1,19 @@
|
||||
<?php
|
||||
|
||||
namespace App;
|
||||
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Cycle extends Model
|
||||
{
|
||||
public $fillable = ['name', 'unique_id', 'user_id', 'result', 'description'];
|
||||
public function user()
|
||||
{
|
||||
return $this->belongsTo('App\User');
|
||||
}
|
||||
public function packages()
|
||||
{
|
||||
return $this->belongsToMany('App\Package', 'cycle_package');
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,86 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use App\Http\Requests\StoreCycleRequest;
|
||||
use App\Cycle;
|
||||
|
||||
class CycleController extends Controller
|
||||
{
|
||||
public function index(Request $request)
|
||||
{
|
||||
$Cycles = Cycle::when($request->has('name') && $request->name, function($query) use($request){
|
||||
$query->where('name', 'LIKE', '%'.$request->name.'%');
|
||||
})
|
||||
->when($request->has('result') && $request->result, function($query) use($request){
|
||||
$query->where('result', $request->result);
|
||||
})
|
||||
->when($request->has('unique_id') && $request->unique_id, function($query) use($request){
|
||||
$query->where('unique_id', $request->unique_id);
|
||||
})
|
||||
->with('user')->paginate(10);
|
||||
return \MessageResponse::data($Cycles);
|
||||
}
|
||||
public function create()
|
||||
{
|
||||
|
||||
}
|
||||
public function show(Cycle $Cycle)
|
||||
{
|
||||
$Cycle->load('user', 'packages');
|
||||
return \MessageResponse::data($Cycle);
|
||||
}
|
||||
public function store(StoreCycleRequest $request)
|
||||
{
|
||||
$UniqueID = substr(base_convert(sha1(uniqid(mt_rand())), 16, 36), 0, 10);
|
||||
$CycleData = [
|
||||
'name' => $request->name,
|
||||
'unique_id' => $UniqueID,
|
||||
'result' => $request->result,
|
||||
'description' => $request->description,
|
||||
'user_id' => auth('api')->user()->id,
|
||||
'verified' => 'NotVerified',
|
||||
];
|
||||
$CycleObj = Cycle::create($CycleData);
|
||||
$CycleObj->packages()->attach($request->packages);
|
||||
return \MessageResponse::success(trans('messages.success'));
|
||||
}
|
||||
public function edit(Cycle $Cycle)
|
||||
{
|
||||
$Cycle->load('user', 'packages');
|
||||
return \MessageResponse::data($Cycle);
|
||||
}
|
||||
public function update(StoreCycleRequest $request, Cycle $Cycle)
|
||||
{
|
||||
$Cycle->update($request->except(['packages']));
|
||||
$Cycle->packages()->sync($request->packages);
|
||||
return \MessageResponse::success(trans('messages.success'));
|
||||
}
|
||||
public function destroy(Cycle $Cycle)
|
||||
{
|
||||
if (auth('api')->user()->cant('delete', $Cycle)) {
|
||||
return \MessageResponse::error(trans('messages.access_denied'));
|
||||
}
|
||||
if(count($Cycle->packages))
|
||||
{
|
||||
$Cycle->packages()->detach();
|
||||
}
|
||||
$Cycle->delete();
|
||||
return \MessageResponse::success(trans('messages.success'));
|
||||
}
|
||||
public function verifyCycle(Cycle $Cycle)
|
||||
{
|
||||
if (auth('api')->user()->cant('verifyCycle', $Cycle)) {
|
||||
return \MessageResponse::error(trans('You dont have permission'));
|
||||
}
|
||||
if ($Cycle->verified == 'Verified') {
|
||||
$Cycle->verified = 'NotVerified';
|
||||
} else {
|
||||
$Cycle->verified = 'Verified';
|
||||
}
|
||||
$Cycle->save();
|
||||
$Cycle = $Cycle->load('user');
|
||||
return \MessageResponse::success(trans('messages.success'), null, $Cycle);
|
||||
}
|
||||
}
|
||||
@@ -47,7 +47,6 @@ class ItemController extends Controller
|
||||
}
|
||||
public function update(StoreItemRequest $request, Item $Item)
|
||||
{
|
||||
// dd($request->all());
|
||||
$Item->update($request->all());
|
||||
return \MessageResponse::success(trans('messages.success'));
|
||||
}
|
||||
|
||||
@@ -59,13 +59,17 @@ class PackageController extends Controller
|
||||
}
|
||||
public function destroy(Package $Package)
|
||||
{
|
||||
if (!auth('api')->user()->can('delete', $Package)) {
|
||||
if (auth('api')->user()->cant('delete', $Package)) {
|
||||
return \MessageResponse::error(trans('messages.access_denied'));
|
||||
}
|
||||
if(count($Package->items))
|
||||
{
|
||||
$Package->items()->detach();
|
||||
}
|
||||
if(count($Package->cycles))
|
||||
{
|
||||
$Package->cycles()->detach();
|
||||
}
|
||||
$Package->delete();
|
||||
return \MessageResponse::success(trans('messages.success'));
|
||||
}
|
||||
|
||||
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Requests;
|
||||
|
||||
use App\Cycle;
|
||||
use Illuminate\Validation\Rule;
|
||||
use Illuminate\Foundation\Http\FormRequest;
|
||||
use Illuminate\Contracts\Validation\Validator;
|
||||
|
||||
|
||||
class StoreCycleRequest extends FormRequest
|
||||
{
|
||||
public function authorize()
|
||||
{
|
||||
if ($this->method() == 'POST') {
|
||||
return auth('api')->check() && auth('api')->user()->can('store', Cycle::class);
|
||||
} else {
|
||||
$Cycle = $this->route('Cycle');
|
||||
return auth('api')->check() && $Cycle && auth('api')->user()->can('update', $Cycle);
|
||||
}
|
||||
}
|
||||
|
||||
public function rules()
|
||||
{
|
||||
switch ($this->method()) {
|
||||
case 'POST': {
|
||||
return [
|
||||
'name' => 'required|max:100|unique:cycles',
|
||||
'result' => 'required',
|
||||
'packages' => 'required',
|
||||
];
|
||||
break;
|
||||
}
|
||||
case 'PUT':
|
||||
case 'PATCH': {
|
||||
$Cycle = $this->route('Cycle');
|
||||
return [
|
||||
'name' => 'required|max:100|unique:cycles,id,'.$Cycle->id,
|
||||
// 'unique_id' => 'required|max:100|unique:cycles,id,'.$Cycle->id,
|
||||
'result' => 'required',
|
||||
'packages' => 'required',
|
||||
];
|
||||
break;
|
||||
|
||||
}
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -15,5 +15,9 @@ class Package extends Model
|
||||
{
|
||||
return $this->belongsToMany('App\Item', 'item_package');
|
||||
}
|
||||
public function cycles()
|
||||
{
|
||||
return $this->belongsToMany('App\Cycle', 'cycle_package');
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
namespace App\Policies;
|
||||
|
||||
use App\User;
|
||||
use App\Cycle;
|
||||
use Doctrine\Tests\Common\Inflector\InflectorTest;
|
||||
|
||||
class CyclePolicy
|
||||
{
|
||||
public function delete(User $User, Cycle $Cycle)
|
||||
{
|
||||
// if($User->hasRole('Admin') && $Cycle->users->count() == 0)
|
||||
return true;
|
||||
}
|
||||
|
||||
public function update(User $User, Cycle $Cycle)
|
||||
{
|
||||
// if($User->hasRole('Admin'))
|
||||
return true;
|
||||
}
|
||||
|
||||
public function store(User $User)
|
||||
{
|
||||
// if($User->hasRole('Admin'))
|
||||
return true;
|
||||
}
|
||||
public function verifyCycle(User $User, Cycle $Cycle)
|
||||
{
|
||||
// if($User->hasRole('Admin'))
|
||||
return true;
|
||||
}
|
||||
|
||||
}
|
||||
@@ -18,7 +18,6 @@ class CreateTestTypesTable extends Migration
|
||||
$table->string('name')->unique();
|
||||
$table->string('unique_code')->unique();
|
||||
$table->string('bar_code');
|
||||
$table->string('device_label');
|
||||
$table->unsignedBigInteger('user_id');
|
||||
$table->foreign('user_id')->references('id')->on('users');
|
||||
$table->timestamps();
|
||||
|
||||
@@ -21,7 +21,7 @@ class CreateTestResultsTable extends Migration
|
||||
$table->text('description');
|
||||
$table->smallInteger('verified');
|
||||
$table->string('device_id');
|
||||
// $table->string('device_label');
|
||||
$table->string('device_label');
|
||||
$table->integer('autoclave_id');
|
||||
$table->unsignedBigInteger('user_id');
|
||||
$table->foreign('user_id')->references('id')->on('users');
|
||||
|
||||
+5
-5
@@ -4,7 +4,7 @@ use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class CreateItemPackageTable extends Migration
|
||||
class CreateCyclePackageTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
@@ -13,11 +13,11 @@ class CreateItemPackageTable extends Migration
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('item_package', function (Blueprint $table) {
|
||||
Schema::create('cycle_package', function (Blueprint $table) {
|
||||
$table->bigIncrements('id');
|
||||
$table->integer('item_id')->unsigned();
|
||||
$table->integer('cycle_id')->unsigned();
|
||||
$table->integer('package_id')->unsigned();
|
||||
$table->foreign('item_id')->references('id')->on('items');
|
||||
$table->foreign('cycle_id')->references('id')->on('cycles');
|
||||
$table->foreign('package_id')->references('id')->on('packages');
|
||||
$table->timestamps();
|
||||
});
|
||||
@@ -30,6 +30,6 @@ class CreateItemPackageTable extends Migration
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('item_package');
|
||||
Schema::dropIfExists('cycle_package');
|
||||
}
|
||||
}
|
||||
+5
-5
@@ -4,7 +4,7 @@ use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class CreatePackagesTable extends Migration
|
||||
class CreateCyclesTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
@@ -13,13 +13,13 @@ class CreatePackagesTable extends Migration
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('packages', function (Blueprint $table) {
|
||||
Schema::create('cycles', function (Blueprint $table) {
|
||||
$table->bigIncrements('id');
|
||||
$table->string('name');
|
||||
$table->string('unique_id');
|
||||
$table->enum('result',array('Pass', 'Fail'));
|
||||
$table->enum('result',['Pass', 'Fail']);
|
||||
$table->text('description');
|
||||
$table->enum('verified',array('Verified', 'NotVerified'));
|
||||
$table->enum('verified',['Verified', 'NotVerified']);
|
||||
$table->unsignedBigInteger('user_id');
|
||||
$table->foreign('user_id')->references('id')->on('users');
|
||||
$table->timestamps();
|
||||
@@ -33,6 +33,6 @@ class CreatePackagesTable extends Migration
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('packages');
|
||||
Schema::dropIfExists('cycles');
|
||||
}
|
||||
}
|
||||
@@ -1,32 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class CreateMedicalCentersTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('medical_centers', function (Blueprint $table) {
|
||||
$table->bigIncrements('id');
|
||||
$table->string('name');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('medical_centers');
|
||||
}
|
||||
}
|
||||
@@ -1,42 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class CreateUsersTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('users', function (Blueprint $table) {
|
||||
$table->bigIncrements('id');
|
||||
$table->string('name');
|
||||
$table->string('email')->nullable();
|
||||
$table->string('cell_number');
|
||||
$table->enum('gender', ['Male','FeMale'])->default('Male');
|
||||
$table->enum('verified', ['Verified','NotVerified'])->default('NotVerified');
|
||||
$table->enum('status', ['Active','Suspended'])->default('Active');
|
||||
$table->unsignedBigInteger('medical_center_id');
|
||||
$table->foreign('medical_center_id')->references('id')->on('medical_centers');
|
||||
$table->string('password');
|
||||
$table->string('address')->nullable();
|
||||
$table->rememberToken();
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('users');
|
||||
}
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class CreateTestTypesTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('test_types', function (Blueprint $table) {
|
||||
$table->bigIncrements('id');
|
||||
$table->string('name')->unique();
|
||||
$table->string('unique_code')->unique();
|
||||
$table->string('bar_code');
|
||||
$table->unsignedBigInteger('user_id');
|
||||
$table->foreign('user_id')->references('id')->on('users');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('test_types');
|
||||
}
|
||||
}
|
||||
@@ -1,43 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class CreateTestResultsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('test_results', function (Blueprint $table) {
|
||||
$table->bigIncrements('id');
|
||||
$table->string('info');
|
||||
$table->string('cycle_number');
|
||||
$table->string('result');
|
||||
$table->text('description');
|
||||
$table->smallInteger('verified');
|
||||
$table->string('device_id');
|
||||
$table->string('device_label');
|
||||
$table->integer('autoclave_id');
|
||||
$table->unsignedBigInteger('user_id');
|
||||
$table->foreign('user_id')->references('id')->on('users');
|
||||
$table->unsignedBigInteger('test_type_id');
|
||||
$table->foreign('test_type_id')->references('id')->on('test_types');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('test_results');
|
||||
}
|
||||
}
|
||||
@@ -1,39 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class CreateInputsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('inputs', function (Blueprint $table) {
|
||||
$table->bigIncrements('id');
|
||||
$table->string('name');
|
||||
$table->string('type');
|
||||
$table->unsignedBigInteger('test_type_id');
|
||||
$table->foreign('test_type_id')->references('id')->on('test_types');
|
||||
$table->unsignedBigInteger('parent_id')->nullable();
|
||||
$table->foreign('parent_id')->references('id')->on('inputs');
|
||||
$table->string('size');
|
||||
$table->string('value');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('inputs');
|
||||
}
|
||||
}
|
||||
@@ -1,38 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class CreateInputValuesTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('input_values', function (Blueprint $table) {
|
||||
$table->bigIncrements('id');
|
||||
$table->string('value');
|
||||
$table->unsignedBigInteger('input_id');
|
||||
$table->foreign('input_id')->references('id')->on('inputs');
|
||||
$table->unsignedBigInteger('test_result_id');
|
||||
$table->foreign('test_result_id')->references('id')->on('test_results');
|
||||
$table->unsignedBigInteger('option_id');
|
||||
$table->foreign('option_id')->references('id')->on('options');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('input_values');
|
||||
}
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class CreateOptionsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('options', function (Blueprint $table) {
|
||||
$table->bigIncrements('id');
|
||||
$table->string('title');
|
||||
$table->unsignedBigInteger('input_id');
|
||||
$table->foreign('input_id')->references('id')->on('inputs');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('options');
|
||||
}
|
||||
}
|
||||
@@ -1,34 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class CreateGalleriesTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('galleries', function (Blueprint $table) {
|
||||
$table->bigIncrements('id');
|
||||
$table->unsignedBigInteger('user_id');
|
||||
$table->foreign('user_id')->references('id')->on('users');
|
||||
$table->string('path');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('galleries');
|
||||
}
|
||||
}
|
||||
@@ -1,36 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class CreateUploadablesTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('uploadables', function (Blueprint $table) {
|
||||
$table->bigIncrements('id');
|
||||
$table->unsignedBigInteger('uploadable_id');
|
||||
$table->string('uploadable_type');
|
||||
$table->unsignedBigInteger('gallery_id');
|
||||
$table->foreign('gallery_id')->references('id')->on('galleries');
|
||||
$table->string('image_role');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('uploadables');
|
||||
}
|
||||
}
|
||||
@@ -1,102 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class CreatePermissionTables extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
$tableNames = config('permission.table_names');
|
||||
$columnNames = config('permission.column_names');
|
||||
|
||||
Schema::create($tableNames['permissions'], function (Blueprint $table) {
|
||||
$table->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']);
|
||||
}
|
||||
}
|
||||
@@ -1,35 +0,0 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class CreateItemsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::create('items', function (Blueprint $table) {
|
||||
$table->bigIncrements('id');
|
||||
$table->string('name');
|
||||
$table->text('description');
|
||||
$table->unsignedBigInteger('user_id');
|
||||
$table->foreign('user_id')->references('id')->on('users');
|
||||
$table->timestamps();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::dropIfExists('items');
|
||||
}
|
||||
}
|
||||
@@ -52,4 +52,6 @@ Route::middleware('auth:api')->group(function () {
|
||||
Route::delete('Messages/User/{User}', 'MessageController@destroyUserMessages');
|
||||
Route::post('/Package/Verify/{Package}', 'PackageController@verifyPackage');
|
||||
Route::get('/GetItems', 'ItemController@getItems');
|
||||
|
||||
Route::resource('Cycles', 'CycleController');
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user