Mini Stack Overflow ب Laravel 8 Darija & Vuejs 2 Darija الجزء الأول

imadbelasri Laravel
LA

فهاد ل projet الجديد غادي نقادو Mini Stack Overflow ب Laravel 8 Darija & Vuejs 2 Darija المستخدم كيزيد أسئلة من بعد ممكن للمستخدمين يجاوبوه مع إمكانية التصويت على السؤال المطروح. 


نظرة سريعة بالفيديو


1- إضافة قاعدة البيانات

غادي تزيد base de données سميها لي بغيتي فيها غادي تكون عندنا:

  • table categories
  • table collectives
  • table questions
  • table comments

لتحت غادي تلقى Laravel Migrations باش تزيد les tables فل base de données :

                                                    
                                                        //
//categories
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateCategoriesTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('categories', function (Blueprint $table) {
            $table->id();
            $table->string('name');
            $table->string('slug');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('categories');
    }
}

//collectives
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateCollectivesTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('collectives', function (Blueprint $table) {
            $table->id();
            $table->foreignId('user_id')->constrainted();
            $table->foreignId('category_id')->constrained();
            $table->string('title');
            $table->string('slug');
            $table->text('description');
            $table->softDeletes();
            $table->integer('members')->default(0);
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('collectives');
    }
}

//questions
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateQuestionsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('questions', function (Blueprint $table) {
            $table->id();
            $table->foreignId('user_id')->constrainted();
            $table->foreignId('category_id')->constrained();
            $table->unsignedBigInteger('collective_id')->nullable();
            $table->string('title');
            $table->string('slug');
            $table->text('body');
            $table->softDeletes();
            $table->integer('votes')->default(0);
            $table->foreign('collective_id')->references('id')
                ->on('collectives')->onDelete('cascade');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('questions');
    }
}

//comments
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateCommentsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('comments', function (Blueprint $table) {
            $table->id();
            $table->foreignId('user_id')->constrainted();
            $table->foreignId('question_id')->constrained();
            $table->text('body');
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::dropIfExists('comments');
    }
}
                                                    
                                                

2- الإتصال بقاعدة البيانات

من بعد فل fichier .env غادي نديروا la connexion مع ل base de données انا سميتها mini_stack_channel نتا دير الإسم لي اختاريتي.

الكود ديال الملف بعد التعديل:

                                                        
                                                            //
DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=mini_stack_channel
DB_USERNAME=root
DB_PASSWORD=
                                                        
                                                    

3- إضافة معلومات عشوائية ف table catégories

من بعد غادي نزيدو معلومات عشوائية ف table catégories بإستعمال Laravel Seeder.

أول حاجة زيد seeder سميها CategorySeeder بال commande :

php artisan make:seeder CategorySeeder 

الكود لي غادي تزيد فيها هو :

                                                        
                                                            //
<?php

namespace Database\Seeders;

use App\Models\Category;
use Illuminate\Support\Str;
use Illuminate\Database\Seeder;

class CategorySeeder extends Seeder
{
    /**
     * Run the database seeds.
     *
     * @return void
     */
    public function run()
    {
        //
        Category::create(
            [
                'name' => 'Web Design',
                'slug' => Str::slug('Web Design')
            ]
        );
        Category::create(
            [
                'name' => 'Web Dev',
                'slug' => Str::slug('Web Dev')
            ]
        );
        Category::create(
            [
                'name' => 'Programming',
                'slug' => Str::slug('programming')
            ]
        );
        Category::create(
            [
                'name' => 'Mobile Apps',
                'slug' => Str::slug('Mobile Apps')
            ],
        );
        Category::create(
            [
                'name' => 'Frontend Dev',
                'slug' => Str::slug('Frontend Dev')
            ],
        );
    }
}
                                                        
                                                    

4- إضافة les catégories لقاعدة البيانات

باش نزيد les catégories لي زدنا ف CategorySeeder غادي نمشي ل 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(10)->create();
        $this->call(CategorySeeder::class);
    }
}
                                                        
                                                    

5- إضافة les catégories لقاعدة البيانات تتمة

أخير حاجة غادي نفدوا هاد ال commande :

                                                        
                                                            //
php artisan db:seed
                                                        
                                                    

دروس ذات صلة

LA

Mini Stack Overflow ب Laravel 8 Darija & Vuejs 2 Darija الجزء الثاني

فهاد الجزء الثاني من Mini Stack Overflow ب Laravel 8 Darija & Vuejs 2 Darija غادي نزيدو Login & Logo...


LA

Mini Stack Overflow ب Laravel 8 Darija & Vuejs 2 Darija الجزء الثالت

فهاد الجزء الثالت من Mini Stack Overflow ب Laravel 8 Darija & Vuejs 2 Darija غادي نكملوا الجزء الخاص...


LA

Mini Stack Overflow ب Laravel 8 Darija & Vuejs 2 Darija الجزء الرابع

فهاد الجزء الجديد من Mini Stack Overflow ب Laravel 8 Darija & Vuejs 2 Darija غادي نزيدوا الصفحة الرئ...


LA

Mini Stack Overflow ب Laravel 8 Darija & Vuejs 2 Darija الجزء الخامس

فهاد الجزء الخامس من Mini Stack Overflow ب Laravel 8 Darija & Vuejs 2 Darija غادي نزيدوا ل models دي...


LA

Mini Stack Overflow ب Laravel 8 Darija & Vuejs 2 Darija الجزء السادس

فهاد الجزء السادس من Mini Stack Overflow ب Laravel 8 Darija & Vuejs 2 Darija غادي نزيدو ل collective...


LA

Mini Stack Overflow ب Laravel 8 Darija & Vuejs 2 Darija الجزء السابع

فهاد الجزء السابع من Mini Stack Overflow ب Laravel 8 Darija & Vuejs 2 Darija غادي نزيدو ل questions...


LA

Mini Stack Overflow ب Laravel 8 Darija & Vuejs 2 Darija الجزء الثامن

فهاد الجزء الثامن من Mini Stack Overflow ب Laravel 8 Darija & Vuejs 2 Darija غادي نزيدوا Vuejs ل pro...


LA

Mini Stack Overflow ب Laravel 8 Darija & Vuejs 2 Darija الجزء التاسع

فهاد الجزء التاسع والأخير من Mini Stack Overflow ب Laravel 8 Darija & Vuejs 2 Darija غادي نشارجيو ل...