Application de gestion des employés ب Laravel 8 Darija الجزء الأول
فهاد ل projet الجديد غادي نقادو application de gestion des employés ب Laravel 8 Darija المستخدم كيزيد des employés كيدير التعديل والحذف, أيضا ممكن ي générer des pdf & شهادة العمل و طلب العطلة.
هنا غادي نخدموا بل Adminlte باش نزيدو ل backend و Laravel Fortify باش نديرو Login & Logout.
نظرة سريعة بالفيديو
1- إضافة قاعدة البيانات
غادي تزيد base de données سميها لي بغيتي فيها غادي تكون عندنا table employés بالإضافة ل users و les tables لي كيجيو مع Laravel.
الكود ديال table employés هو :
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
class CreateEmployesTable extends Migration
{
/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create('employes', function (Blueprint $table) {
$table->id();
$table->string('registration_number');
$table->string('fullname');
$table->string('depart');
$table->date('hire_date');
$table->integer('phone');
$table->string('address');
$table->string('city');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists('employes');
}
}
2- إضافة معلومات عشوائية ف table employés
من بعد غادي نزيدو معلومات عشوائية ف table ديالنا بإستعمال ل factory.
أول حاجة زيد factory سميها EmployeFactory بال commande :
php artisan make:factory EmployeFactory
الكود لي غادي تزيد فيها هو :
<?php
namespace Database\Factories;
use App\Models\Employe;
use Illuminate\Database\Eloquent\Factories\Factory;
class EmployeFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = Employe::class;
/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
return [
//
'registration_number' => $this->faker->randomNumber(9, true),
'fullname' => $this->faker->name(),
'depart' => $this->faker->word(),
'hire_date' => $this->faker->date(),
'phone' => $this->faker->randomNumber(9, true),
'address' => $this->faker->address(),
'city' => $this->faker->state(),
];
}
}
3- إضافة ل admin
منبعد غادي نزيدو ل admin حتى هو ب Laravel Factory غير هنا غادي نخدموا بل UserFactory لي عندنا فقط غادي نديرو عليها تعديل.
الكود لي غادي تزيد فيها هو هذا :
<?php
namespace Database\Factories;
use App\Models\User;
use Illuminate\Support\Str;
use Illuminate\Support\Facades\Hash;
use Illuminate\Database\Eloquent\Factories\Factory;
class UserFactory extends Factory
{
/**
* The name of the factory's corresponding model.
*
* @var string
*/
protected $model = User::class;
/**
* Define the model's default state.
*
* @return array
*/
public function definition()
{
return [
'name' => 'admin',
'email' => 'admin@email.com',
'email_verified_at' => now(),
'password' => Hash::make('admin'), // password
'remember_token' => Str::random(10),
];
}
/**
* Indicate that the model's email address should be unverified.
*
* @return \Illuminate\Database\Eloquent\Factories\Factory
*/
public function unverified()
{
return $this->state(function (array $attributes) {
return [
'email_verified_at' => null,
];
});
}
}
4- إضافة ل admin ول les employés لقاعدة البيانات
باش نزيد ل admin و les employés لي زدنا فل factories غادي نخدموا ب Laravel Seeder.
غادي نمشي ل fichier DatabaseSeeder.php وغادي نزيد عليه هاد التعديلات :
<?php
namespace Database\Seeders;
use Illuminate\Database\Seeder;
class DatabaseSeeder extends Seeder
{
/**
* Seed the application's database.
*
* @return void
*/
public function run()
{
\App\Models\User::factory(1)->create();
\App\Models\Employe::factory(10)->create();
}
}
5- إضافة ل admin ول les employés لقاعدة البيانات تتمة
باش نزيدوا ل admin و les employés فقاعدة البيانات غادي نفدوا هاد ال commande :
//
php artisan db:seed