Cài đặt các thư viện && migrate
Last updated
Last updated
composer require spatie/laravel-permission
C:\xampp8\htdocs\lvasample\database\factories\MenuroleFactory.php
<?php
/** @var \Illuminate\Database\Eloquent\Factory $factory */
namespace Database\Factories;
use App\Models\Menurole;
use Faker\Generator as Faker;
use Illuminate\Support\Str;
$factory->define(Menurole::class, function (Faker $faker) {
return [
'role_name' => 'guest',
'menus_id' => factory(App\Models\Menus::class)->create()->id,
];
});
C:\xampp8\htdocs\lvasample\database\factories\MenusFactory.php
<?php
/** @var \Illuminate\Database\Eloquent\Factory $factory */
namespace Database\Factories;
use App\Models\Menus;
use Faker\Generator as Faker;
use Illuminate\Support\Str;
$factory->define(Menus::class, function (Faker $faker) {
return [
'name' => $faker->sentence(4, true),
'href' => '/href',
'icon' => NULL,
'slug' => 'link',
'parent_id' => NULL,
'menu_id' => 1,
'sequence' => 1
];
});
C:\xampp8\htdocs\lvasample\database\factories\UserFactory.php
<?php
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
use Illuminate\Support\Str;
/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\User>
*/
class UserFactory extends Factory
{
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition()
{
return [
'name' => fake()->name(),
'email' => fake()->unique()->safeEmail(),
'email_verified_at' => now(),
'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password
'remember_token' => Str::random(10),
'menuroles' => 'user'
];
}
/**
* Indicate that the model's email address should be unverified.
*
* @return static
*/
public function unverified()
{
return $this->state(fn (array $attributes) => [
'email_verified_at' => null,
]);
}
public function admin()
{
return $this->state(function (array $attributes) {
return [
'menuroles' => 'user,admin',
];
});
}
}
C:\xampp8\htdocs\lvasample\database\migrations\2014_10_12_000000_create_users_table.php
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('users', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('email')->unique();
$table->timestamp('email_verified_at')->nullable();
$table->string('password');
$table->string('menuroles');
$table->rememberToken();
$table->timestamps();
$table->softDeletes();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('users');
}
};
C:\xampp8\htdocs\lvasample\database\migrations\2019_10_11_085455_create_notes_table.php
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateNotesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('notes', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('title');
$table->text('content');
$table->string('note_type');
$table->date('applies_to_date');
$table->integer('users_id')->unsigned();
$table->integer('status_id')->unsigned();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('notes');
}
}
C:\xampp8\htdocs\lvasample\database\migrations\2019_10_12_115248_create_status_table.php
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateStatusTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('status', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('name');
$table->string('class');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('status');
}
}
C:\xampp8\htdocs\lvasample\database\migrations\2019_11_08_102827_create_menus_table.php
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateMenusTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('menus', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('name');
$table->string('href')->nullable();
$table->string('icon')->nullable();
$table->string('slug');
$table->integer('parent_id')->unsigned()->nullable();
$table->integer('menu_id')->unsigned();
$table->integer('sequence');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('menus');
}
}
C:\xampp8\htdocs\lvasample\database\migrations\2019_11_13_092213_create_menurole_table.php
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateMenuroleTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('menu_role', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('role_name');
$table->integer('menus_id')->unsigned();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('menu_role');
}
}
C:\xampp8\htdocs\lvasample\database\migrations\2019_12_11_091036_create_menulist_table.php
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateMenulistTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('menulist', function (Blueprint $table) {
$table->bigIncrements('id');
$table->string('name');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('menulist');
}
}
C:\xampp8\htdocs\lvasample\database\migrations\2019_12_18_092518_create_role_hierarchy_table.php
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateRoleHierarchyTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('role_hierarchy', function (Blueprint $table) {
$table->bigIncrements('id');
$table->integer('role_id')->unsigned();
$table->integer('hierarchy');
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('role_hierarchy');
}
}
C:\xampp8\htdocs\lvasample\database\migrations\2023_03_04_022446_create_permission_tables.php
<?php
use Illuminate\Support\Facades\Schema;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;
use Spatie\Permission\PermissionRegistrar;
class CreatePermissionTables extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
$tableNames = config('permission.table_names');
$columnNames = config('permission.column_names');
$teams = config('permission.teams');
if (empty($tableNames)) {
throw new \Exception('Error: config/permission.php not loaded. Run [php artisan config:clear] and try again.');
}
if ($teams && empty($columnNames['team_foreign_key'] ?? null)) {
throw new \Exception('Error: team_foreign_key on config/permission.php not loaded. Run [php artisan config:clear] and try again.');
}
Schema::create($tableNames['permissions'], function (Blueprint $table) {
$table->bigIncrements('id'); // permission id
$table->string('name'); // For MySQL 8.0 use string('name', 125);
$table->string('guard_name'); // For MySQL 8.0 use string('guard_name', 125);
$table->timestamps();
$table->unique(['name', 'guard_name']);
});
Schema::create($tableNames['roles'], function (Blueprint $table) use ($teams, $columnNames) {
$table->bigIncrements('id'); // role id
if ($teams || config('permission.testing')) { // permission.testing is a fix for sqlite testing
$table->unsignedBigInteger($columnNames['team_foreign_key'])->nullable();
$table->index($columnNames['team_foreign_key'], 'roles_team_foreign_key_index');
}
$table->string('name'); // For MySQL 8.0 use string('name', 125);
$table->string('guard_name'); // For MySQL 8.0 use string('guard_name', 125);
$table->timestamps();
if ($teams || config('permission.testing')) {
$table->unique([$columnNames['team_foreign_key'], 'name', 'guard_name']);
} else {
$table->unique(['name', 'guard_name']);
}
});
Schema::create($tableNames['model_has_permissions'], function (Blueprint $table) use ($tableNames, $columnNames, $teams) {
$table->unsignedBigInteger(PermissionRegistrar::$pivotPermission);
$table->string('model_type');
$table->unsignedBigInteger($columnNames['model_morph_key']);
$table->index([$columnNames['model_morph_key'], 'model_type'], 'model_has_permissions_model_id_model_type_index');
$table->foreign(PermissionRegistrar::$pivotPermission)
->references('id') // permission id
->on($tableNames['permissions'])
->onDelete('cascade');
if ($teams) {
$table->unsignedBigInteger($columnNames['team_foreign_key']);
$table->index($columnNames['team_foreign_key'], 'model_has_permissions_team_foreign_key_index');
$table->primary(
[$columnNames['team_foreign_key'], PermissionRegistrar::$pivotPermission, $columnNames['model_morph_key'], 'model_type'],
'model_has_permissions_permission_model_type_primary'
);
} else {
$table->primary(
[PermissionRegistrar::$pivotPermission, $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, $teams) {
$table->unsignedBigInteger(PermissionRegistrar::$pivotRole);
$table->string('model_type');
$table->unsignedBigInteger($columnNames['model_morph_key']);
$table->index([$columnNames['model_morph_key'], 'model_type'], 'model_has_roles_model_id_model_type_index');
$table->foreign(PermissionRegistrar::$pivotRole)
->references('id') // role id
->on($tableNames['roles'])
->onDelete('cascade');
if ($teams) {
$table->unsignedBigInteger($columnNames['team_foreign_key']);
$table->index($columnNames['team_foreign_key'], 'model_has_roles_team_foreign_key_index');
$table->primary(
[$columnNames['team_foreign_key'], PermissionRegistrar::$pivotRole, $columnNames['model_morph_key'], 'model_type'],
'model_has_roles_role_model_type_primary'
);
} else {
$table->primary(
[PermissionRegistrar::$pivotRole, $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->unsignedBigInteger(PermissionRegistrar::$pivotPermission);
$table->unsignedBigInteger(PermissionRegistrar::$pivotRole);
$table->foreign(PermissionRegistrar::$pivotPermission)
->references('id') // permission id
->on($tableNames['permissions'])
->onDelete('cascade');
$table->foreign(PermissionRegistrar::$pivotRole)
->references('id') // role id
->on($tableNames['roles'])
->onDelete('cascade');
$table->primary([PermissionRegistrar::$pivotPermission, PermissionRegistrar::$pivotRole], 'role_has_permissions_permission_id_role_id_primary');
});
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');
if (empty($tableNames)) {
throw new \Exception('Error: config/permission.php not found and defaults could not be merged. Please publish the package configuration before proceeding, or drop the tables manually.');
}
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']);
}
}
C:\xampp8\htdocs\lvasample\database\seeders\DatabaseSeeder.php
<?php
namespace Database\Seeders;
// use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use App\Models\User;
use Illuminate\Database\Seeder;
class DatabaseSeeder extends Seeder
{
/**
* Seed the application's database.
*
* @return void
*/
public function run()
{
User::factory(12)->create();
$this->call([
UsersAndNotesSeeder::class,
MenusTableSeeder::class
]);
}
}
C:\xampp8\htdocs\lvasample\database\seeders\MenusTableSeeder.php
<?php
namespace Database\Seeders;
use Illuminate\Database\Seeder;
use Spatie\Permission\Models\Role;
use Spatie\Permission\Models\Permission;
use Illuminate\Support\Facades\DB;
class MenusTableSeeder extends Seeder
{
private $menuId = null;
private $dropdownId = array();
private $dropdown = false;
private $sequence = 1;
private $joinData = array();
private $adminRole = null;
private $userRole = null;
private $subFolder = '';
public function join($roles, $menusId)
{
$roles = explode(',', $roles);
foreach ($roles as $role) {
array_push($this->joinData, array('role_name' => $role, 'menus_id' => $menusId));
}
}
/*
Function assigns menu elements to roles
Must by use on end of this seeder
*/
public function joinAllByTransaction()
{
DB::beginTransaction();
foreach ($this->joinData as $data) {
DB::table('menu_role')->insert([
'role_name' => $data['role_name'],
'menus_id' => $data['menus_id'],
]);
}
DB::commit();
}
public function insertLink($roles, $name, $href, $icon = null)
{
$href = $this->subFolder . $href;
if ($this->dropdown === false) {
DB::table('menus')->insert([
'slug' => 'link',
'name' => $name,
'icon' => $icon,
'href' => $href,
'menu_id' => $this->menuId,
'sequence' => $this->sequence
]);
} else {
DB::table('menus')->insert([
'slug' => 'link',
'name' => $name,
'icon' => $icon,
'href' => $href,
'menu_id' => $this->menuId,
'parent_id' => $this->dropdownId[count($this->dropdownId) - 1],
'sequence' => $this->sequence
]);
}
$this->sequence++;
$lastId = DB::getPdo()->lastInsertId();
$this->join($roles, $lastId);
$permission = Permission::where('name', '=', $name)->get();
if (empty($permission)) {
$permission = Permission::create(['name' => 'visit ' . $name]);
}
$roles = explode(',', $roles);
if (in_array('user', $roles)) {
$this->userRole->givePermissionTo($permission);
}
if (in_array('admin', $roles)) {
$this->adminRole->givePermissionTo($permission);
}
return $lastId;
}
public function insertTitle($roles, $name)
{
DB::table('menus')->insert([
'slug' => 'title',
'name' => $name,
'menu_id' => $this->menuId,
'sequence' => $this->sequence
]);
$this->sequence++;
$lastId = DB::getPdo()->lastInsertId();
$this->join($roles, $lastId);
return $lastId;
}
public function beginDropdown($roles, $name, $icon = '')
{
if (count($this->dropdownId)) {
$parentId = $this->dropdownId[count($this->dropdownId) - 1];
} else {
$parentId = null;
}
DB::table('menus')->insert([
'slug' => 'dropdown',
'name' => $name,
'icon' => $icon,
'menu_id' => $this->menuId,
'sequence' => $this->sequence,
'parent_id' => $parentId
]);
$lastId = DB::getPdo()->lastInsertId();
array_push($this->dropdownId, $lastId);
$this->dropdown = true;
$this->sequence++;
$this->join($roles, $lastId);
return $lastId;
}
public function endDropdown()
{
$this->dropdown = false;
array_pop($this->dropdownId);
}
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
/* Get roles */
$this->adminRole = Role::where('name', '=', 'admin')->first();
$this->userRole = Role::where('name', '=', 'user')->first();
/* Create Sidebar menu */
DB::table('menulist')->insert([
'name' => 'sidebar menu'
]);
$this->menuId = DB::getPdo()->lastInsertId(); //set menuId
$this->insertLink('guest,user,admin', 'Dashboard', '/', 'cil-speedometer');
$this->beginDropdown('admin', 'Settings', 'cil-calculator');
$this->insertLink('admin', 'Notes', '/notes');
$this->insertLink('admin', 'Users', '/users');
$this->insertLink('admin', 'Edit menu', '/menu/menu');
$this->insertLink('admin', 'Edit menu elements', '/menu/element');
$this->insertLink('admin', 'Edit roles', '/roles');
$this->insertLink('admin', 'Media', '/media');
$this->insertLink('admin', 'BREAD', '/bread');
$this->insertLink('admin', 'Email', '/mail');
$this->endDropdown();
$this->insertLink('guest', 'Login', '/login', 'cil-account-logout');
$this->insertLink('guest', 'Register', '/register', 'cil-account-logout');
$this->insertTitle('user,admin', 'Theme');
$this->insertLink('user,admin', 'Colors', '/colors', 'cil-drop1');
$this->insertLink('user,admin', 'Typography', '/typography', 'cil-pencil');
$this->beginDropdown('user,admin', 'Base', 'cil-puzzle');
$this->insertLink('user,admin', 'Breadcrumb', '/base/breadcrumb');
$this->insertLink('user,admin', 'Cards', '/base/cards');
$this->insertLink('user,admin', 'Carousel', '/base/carousel');
$this->insertLink('user,admin', 'Collapse', '/base/collapse');
$this->insertLink('user,admin', 'Forms', '/base/forms');
$this->insertLink('user,admin', 'Jumbotron', '/base/jumbotron');
$this->insertLink('user,admin', 'List group', '/base/list-group');
$this->insertLink('user,admin', 'Navs', '/base/navs');
$this->insertLink('user,admin', 'Pagination', '/base/pagination');
$this->insertLink('user,admin', 'Popovers', '/base/popovers');
$this->insertLink('user,admin', 'Progress', '/base/progress');
$this->insertLink('user,admin', 'Scrollspy', '/base/scrollspy');
$this->insertLink('user,admin', 'Switches', '/base/switches');
$this->insertLink('user,admin', 'Tables', '/base/tables');
$this->insertLink('user,admin', 'Tabs', '/base/tabs');
$this->insertLink('user,admin', 'Tooltips', '/base/tooltips');
$this->endDropdown();
$this->beginDropdown('user,admin', 'Buttons', 'cil-cursor');
$this->insertLink('user,admin', 'Buttons', '/buttons/buttons');
$this->insertLink('user,admin', 'Buttons Group', '/buttons/button-group');
$this->insertLink('user,admin', 'Dropdowns', '/buttons/dropdowns');
$this->insertLink('user,admin', 'Brand Buttons', '/buttons/brand-buttons');
$this->endDropdown();
$this->insertLink('user,admin', 'Charts', '/charts', 'cil-chart-pie');
$this->beginDropdown('user,admin', 'Icons', 'cil-star');
$this->insertLink('user,admin', 'CoreUI Icons', '/icon/coreui-icons');
$this->insertLink('user,admin', 'Flags', '/icon/flags');
$this->insertLink('user,admin', 'Brands', '/icon/brands');
$this->endDropdown();
$this->beginDropdown('user,admin', 'Notifications', 'cil-bell');
$this->insertLink('user,admin', 'Alerts', '/notifications/alerts');
$this->insertLink('user,admin', 'Badge', '/notifications/badge');
$this->insertLink('user,admin', 'Modals', '/notifications/modals');
$this->endDropdown();
$this->insertLink('user,admin', 'Widgets', '/widgets', 'cil-calculator');
$this->insertTitle('user,admin', 'Extras');
$this->beginDropdown('user,admin', 'Pages', 'cil-star');
$this->insertLink('user,admin', 'Login', '/login');
$this->insertLink('user,admin', 'Register', '/register');
$this->insertLink('user,admin', 'Error 404', '/404');
$this->insertLink('user,admin', 'Error 500', '/500');
$this->endDropdown();
$this->insertLink('guest,user,admin', 'Download CoreUI', 'https://coreui.io', 'cil-cloud-download');
$this->insertLink('guest,user,admin', 'Try CoreUI PRO', 'https://coreui.io/pro/', 'cil-layers');
/* Create top menu */
DB::table('menulist')->insert([
'name' => 'top menu'
]);
$this->menuId = DB::getPdo()->lastInsertId(); //set menuId
$this->beginDropdown('guest,user,admin', 'Pages');
$id = $this->insertLink('guest,user,admin', 'Dashboard', '/');
$id = $this->insertLink('user,admin', 'Notes', '/notes');
$id = $this->insertLink('admin', 'Users', '/users');
$this->endDropdown();
$id = $this->beginDropdown('admin', 'Settings');
$id = $this->insertLink('admin', 'Edit menu', '/menu/menu');
$id = $this->insertLink('admin', 'Edit menu elements', '/menu/element');
$id = $this->insertLink('admin', 'Edit roles', '/roles');
$id = $this->insertLink('admin', 'Media', '/media');
$id = $this->insertLink('admin', 'BREAD', '/bread');
$this->endDropdown();
$this->joinAllByTransaction(); /// <===== Must by use on end of this seeder
}
}
C:\xampp8\htdocs\lvasample\database\seeders\UsersAndNotesSeeder.php
<?php
namespace Database\Seeders;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
use Faker\Factory as Faker;
use Illuminate\Support\Str;
use Spatie\Permission\Models\Role;
use App\Models\User;
use App\Models\RoleHierarchy;
class UsersAndNotesSeeder extends Seeder
{
/**
* Run the database seeds.
*
* @return void
*/
public function run()
{
$numberOfUsers = 10;
$numberOfNotes = 100;
$usersIds = array();
$statusIds = array();
$faker = Faker::create();
/* Create roles */
$adminRole = Role::create(['name' => 'admin']);
RoleHierarchy::create([
'role_id' => $adminRole->id,
'hierarchy' => 1,
]);
$userRole = Role::create(['name' => 'user']);
RoleHierarchy::create([
'role_id' => $userRole->id,
'hierarchy' => 2,
]);
$guestRole = Role::create(['name' => 'guest']);
RoleHierarchy::create([
'role_id' => $guestRole->id,
'hierarchy' => 3,
]);
/* insert status */
DB::table('status')->insert([
'name' => 'ongoing',
'class' => 'badge badge-pill badge-primary',
]);
array_push($statusIds, DB::getPdo()->lastInsertId());
DB::table('status')->insert([
'name' => 'stopped',
'class' => 'badge badge-pill badge-secondary',
]);
array_push($statusIds, DB::getPdo()->lastInsertId());
DB::table('status')->insert([
'name' => 'completed',
'class' => 'badge badge-pill badge-success',
]);
array_push($statusIds, DB::getPdo()->lastInsertId());
DB::table('status')->insert([
'name' => 'expired',
'class' => 'badge badge-pill badge-warning',
]);
array_push($statusIds, DB::getPdo()->lastInsertId());
/* insert users */
$user = User::create([
'name' => 'admin',
'email' => 'admin@admin.com',
'email_verified_at' => now(),
'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password
'remember_token' => Str::random(10),
'menuroles' => 'user,admin'
]);
$user->assignRole('admin');
$user->assignRole('user');
for ($i = 0; $i < $numberOfUsers; $i++) {
$user = User::create([
'name' => $faker->name(),
'email' => $faker->unique()->safeEmail(),
'email_verified_at' => now(),
'password' => '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', // password
'remember_token' => Str::random(10),
'menuroles' => 'user'
]);
$user->assignRole('user');
array_push($usersIds, $user->id);
}
/* insert notes */
for ($i = 0; $i < $numberOfNotes; $i++) {
$noteType = $faker->word();
if (random_int(0, 1)) {
$noteType .= ' ' . $faker->word();
}
DB::table('notes')->insert([
'title' => $faker->sentence(4, true),
'content' => $faker->paragraph(3, true),
'status_id' => $statusIds[random_int(0, count($statusIds) - 1)],
'note_type' => $noteType,
'applies_to_date' => $faker->date(),
'users_id' => $usersIds[random_int(0, $numberOfUsers - 1)]
]);
}
}
}
C:\xampp8\htdocs\lvasample\app\Models\Menulist.php
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Menulist extends Model
{
protected $table = 'menulist';
public $timestamps = false;
}
C:\xampp8\htdocs\lvasample\app\Models\Menurole.php
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Menurole extends Model
{
protected $table = 'menu_role';
public $timestamps = false;
}
C:\xampp8\htdocs\lvasample\app\Models\Menus.php
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class Menus extends Model
{
protected $table = 'menus';
public $timestamps = false;
}
C:\xampp8\htdocs\lvasample\app\Models\RoleHierarchy.php
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Model;
class RoleHierarchy extends Model
{
protected $table = 'role_hierarchy';
public $timestamps = false;
}
C:\xampp8\htdocs\lvasample\app\Models\User.php
<?php
namespace App\Models;
// use Illuminate\Contracts\Auth\MustVerifyEmail;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Foundation\Auth\User as Authenticatable;
use Illuminate\Notifications\Notifiable;
use Laravel\Sanctum\HasApiTokens;
use Illuminate\Database\Eloquent\SoftDeletes;
use Spatie\Permission\Traits\HasRoles;
class User extends Authenticatable
{
use HasApiTokens, HasFactory, Notifiable, SoftDeletes, HasRoles;
/**
* The attributes that are mass assignable.
*
* @var array<int, string>
*/
protected $fillable = [
'name',
'email',
'password',
];
/**
* The attributes that should be hidden for serialization.
*
* @var array<int, string>
*/
protected $hidden = [
'password',
'remember_token',
];
/**
* The attributes that should be cast to native types.
*
* @var array
*/
protected $casts = [
'email_verified_at' => 'datetime',
];
protected $dates = [
'deleted_at'
];
protected $attributes = [
'menuroles' => 'user',
];
}