mirror of
https://git.meshkee.com/cssd/cssd-back.git
synced 2026-10-10 19:51:07 +03:30
fix some problems 2
This commit is contained in:
@@ -0,0 +1,34 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class UpdateItemsTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('items', function (Blueprint $table) {
|
||||
$table->string('udi')->nullable();
|
||||
$table->tinyInteger('status')->default(0);
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('items', function (Blueprint $table) {
|
||||
$table->dropColumn('udi');
|
||||
$table->dropColumn('status');
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
<?php
|
||||
|
||||
use Illuminate\Support\Facades\Schema;
|
||||
use Illuminate\Database\Schema\Blueprint;
|
||||
use Illuminate\Database\Migrations\Migration;
|
||||
|
||||
class UpdatePackagesTable extends Migration
|
||||
{
|
||||
/**
|
||||
* Run the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function up()
|
||||
{
|
||||
Schema::table('packages', function (Blueprint $table) {
|
||||
$table->string('uid')->nullable();
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* Reverse the migrations.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function down()
|
||||
{
|
||||
Schema::table('packages', function (Blueprint $table) {
|
||||
$table->dropColumn('uid');
|
||||
});
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
<?php
|
||||
|
||||
use App\User;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Spatie\Permission\Models\Permission;
|
||||
use Spatie\Permission\Models\Role;
|
||||
|
||||
class AccessSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
if ( $this->assignAllRoleToAdministrator() ) {
|
||||
dump( 'Success.' );
|
||||
} else {
|
||||
dump( 'Error: Please Check And Run Again.' );
|
||||
}
|
||||
}
|
||||
|
||||
private function assignAllRoleToAdministrator()
|
||||
{
|
||||
$roleModel = new Role();
|
||||
if ( $roleModel->where( 'name' , 'administrator' )->first() == null ) {
|
||||
Role::create( [
|
||||
'name' => 'administrator'
|
||||
] );
|
||||
}
|
||||
|
||||
// assign role to user id 1
|
||||
$user = User::find( 1 );
|
||||
$user->assignRole( 'administrator' );
|
||||
|
||||
// get all permission
|
||||
$permissions = [];
|
||||
foreach ( Permission::all() as $item ) {
|
||||
$permissions[ 'permissions' ][ $item ] = "1";
|
||||
}
|
||||
|
||||
// assign all permissions to role administrator
|
||||
foreach ($permissions['permissions'] as $permission) {
|
||||
$role = Role::where('id', 1)->first();
|
||||
$role->syncPermissions(array_keys($permission));
|
||||
}
|
||||
return true;
|
||||
}
|
||||
}
|
||||
@@ -11,6 +11,6 @@ class DatabaseSeeder extends Seeder
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
// $this->call(UsersTableSeeder::class);
|
||||
$this->call(UserTableSeeder::class);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -0,0 +1,61 @@
|
||||
<?php
|
||||
|
||||
use App\Models\User;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\DB;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Modules\Permission\App\Helper\AccessMain;
|
||||
use Modules\Permission\App\Helper\PermissionMain;
|
||||
use Modules\Permission\App\Helper\RoleMain;
|
||||
use Spatie\Permission\Models\Role;
|
||||
|
||||
class PermissionSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
|
||||
// assign all permissions to role administrator
|
||||
$permissionMain = New AccessMain();
|
||||
if($permissionMain->assignAllRoleToAdministrator()){
|
||||
dump('Success: Created Role Administrator');
|
||||
|
||||
// create roles default - admin
|
||||
$roleMain = new RoleMain();
|
||||
if($roleMain->getItems()->where('name', 'admin')->first() == null){
|
||||
if(!$roleMain->storeToDB(['name' => 'admin'])){
|
||||
dump('Error: Can Not Create Role Admin');
|
||||
}else{
|
||||
dump('Success: Created Role Admin');
|
||||
}
|
||||
}
|
||||
|
||||
// create roles default - user
|
||||
$roleMain = new RoleMain();
|
||||
if($roleMain->getItems()->where('name','user')->first() == null){
|
||||
if(!$roleMain->storeToDB(['name' => 'user'])){
|
||||
dump('Error: Can Not Create Role User');
|
||||
}else{
|
||||
dump('Success: Created Role User');
|
||||
}
|
||||
}
|
||||
|
||||
// create roles default - caller
|
||||
$roleMain = new RoleMain();
|
||||
if($roleMain->getItems()->where('name','caller')->first() == null){
|
||||
if(!$roleMain->storeToDB(['name' => 'caller'])){
|
||||
dump('Error: Can Not Create Role Caller');
|
||||
}else{
|
||||
dump('Success: Created Role Caller');
|
||||
}
|
||||
}
|
||||
|
||||
}else{
|
||||
dump('Error: Please Check And Run Again.');
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,98 @@
|
||||
<?php
|
||||
|
||||
use App\User;
|
||||
use Faker\Factory;
|
||||
use Illuminate\Database\Seeder;
|
||||
use Illuminate\Support\Facades\Hash;
|
||||
use Ybazli\Faker\Facades\Faker;
|
||||
|
||||
class UserTableSeeder extends Seeder
|
||||
{
|
||||
/**
|
||||
* Run the database seeds.
|
||||
*
|
||||
* @return void
|
||||
*/
|
||||
public function run()
|
||||
{
|
||||
if ( ! User::count() )
|
||||
return $this->registerData();
|
||||
}
|
||||
|
||||
public function registerData()
|
||||
{
|
||||
$faker = Factory::create();
|
||||
|
||||
$user = User::create( [
|
||||
'is_admin' => 1 ,
|
||||
'department_id' => 1 ,
|
||||
'first_name' => 'سیداحمد' ,
|
||||
'last_name' => 'موسوی' ,
|
||||
'name_en' => 'Seyyed Ahmad Mousavi' ,
|
||||
'tel' => '09214309687' ,
|
||||
'national_code' => '0371661773' ,
|
||||
'password' => Hash::make( '12345678' ) ,
|
||||
'birth_date' => '1998/05/22' ,
|
||||
'marriage_date' => '1998/05/22' ,
|
||||
] );
|
||||
if ( $permissions = Department::find( $user->department_id )->permissionsArray ) {
|
||||
foreach ( $permissions as $permission ) {
|
||||
UserPermission::create( [
|
||||
'user_id' => $user->id ,
|
||||
'permission_id' => $permission ,
|
||||
] );
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
UserPhone::create( [
|
||||
'user_id' => $user->id ,
|
||||
'type' => 1 ,
|
||||
'phone' => '09214309687' ,
|
||||
] );
|
||||
|
||||
$user = User::create( [
|
||||
'is_admin' => 1 ,
|
||||
'department_id' => 1 ,
|
||||
'first_name' => 'حسین' ,
|
||||
'last_name' => 'بایگان' ,
|
||||
'name_en' => 'Hossein Bayegan' ,
|
||||
'tel' => '09021950725' ,
|
||||
'national_code' => '0371661773' ,
|
||||
'password' => Hash::make( '12345678' ) ,
|
||||
'birth_date' => '1998/05/22' ,
|
||||
'marriage_date' => '1998/05/22' ,
|
||||
] );
|
||||
if ( $permissions = Department::find( $user->department_id )->permissionsArray ) {
|
||||
foreach ( $permissions as $permission ) {
|
||||
UserPermission::create( [
|
||||
'user_id' => $user->id ,
|
||||
'permission_id' => $permission ,
|
||||
] );
|
||||
};
|
||||
}
|
||||
|
||||
for ( $i = 0 ; $i < 15 ; $i++ ) {
|
||||
$tel = Faker::mobile();
|
||||
$user = User::create( [
|
||||
'is_admin' => 0 ,
|
||||
'department_id' => Department::where( 'id' , '!=' , 1 )->inRandomOrder()->first()->id ,
|
||||
'first_name' => Faker::firstName() ,
|
||||
'last_name' => Faker::lastName() ,
|
||||
'tel' => $tel ,
|
||||
'code' => random_int( 1000 , 9999 ) ,
|
||||
'national_code' => Faker::melliCode() ,
|
||||
'password' => Hash::make( '12345678' ) ,
|
||||
'birth_date' => $faker->date() ,
|
||||
'marriage_date' => $faker->date() ,
|
||||
] );
|
||||
UserPhone::create( [
|
||||
'user_id' => $user->id ,
|
||||
'type' => 1 ,
|
||||
'phone' => $tel ,
|
||||
] );
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
+1
-1
@@ -24,7 +24,6 @@ Route::group(['namespace' => 'Api'],function () {
|
||||
|
||||
Route::middleware('auth:api')->group(function () {
|
||||
|
||||
|
||||
Route::get('/TestResults/ListFilterItems', 'TestResultController@listFilterItems');
|
||||
Route::post('/TestResults/Verify/{TestResult}/{Value}', 'TestResultController@verifyTestResult');
|
||||
Route::get('TestTypes/ListNames', 'TestTypeController@listNames');
|
||||
@@ -49,6 +48,7 @@ Route::middleware('auth:api')->group(function () {
|
||||
|
||||
|
||||
Route::resource('Items', 'ItemController');
|
||||
Route::post('Items/ChangeStatus/{Item}', 'ItemController@changeStatus');
|
||||
Route::resource('Packages', 'PackageController')->except(['showPackage']);
|
||||
Route::resource('Labels', 'LabelController');
|
||||
|
||||
|
||||
Reference in New Issue
Block a user