Advanced Forum ب laravel 5.8 الجزء الأول


فهاد projet الجديد ب laravel 5.8 غادي نشوفوا كيفاش نقادو forum لي فيه المستخدم كيزيد أسئلة وكيتلقى إجابات ممكن يختار منها أفضل جواب فل projet غادي يكون mini stackoverflow.

فهاد الجزء الأول غادي نزيدو قاعدة البيانات و ل models.

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

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

أول حاجة غادي نزيدو قاعدة بيانات جديدة سميها لي بغيتي فيها ,les tables users, replies, categories questions بغيتي تزيدها راسك زيدها بغيتي تديرلها ل import وتزيدها عندك ممكن تزيد الكود ف fichier ومنبعد ديرلو ل import.

الكود  هو :

                                //
-- phpMyAdmin SQL Dump
-- version 4.8.4
-- https://www.phpmyadmin.net/
--
-- Hôte : 127.0.0.1
-- Généré le :  mer. 11 sep. 2019 à 13:11
-- Version du serveur :  10.1.37-MariaDB
-- Version de PHP :  7.2.13

SET SQL_MODE = "NO_AUTO_VALUE_ON_ZERO";
SET AUTOCOMMIT = 0;
START TRANSACTION;
SET time_zone = "+00:00";


/*!40101 SET @OLD_CHARACTER_SET_CLIENT=@@CHARACTER_SET_CLIENT */;
/*!40101 SET @OLD_CHARACTER_SET_RESULTS=@@CHARACTER_SET_RESULTS */;
/*!40101 SET @OLD_COLLATION_CONNECTION=@@COLLATION_CONNECTION */;
/*!40101 SET NAMES utf8mb4 */;

--
-- Base de données :  `laravelstackchannel`
--

-- --------------------------------------------------------

--
-- Structure de la table `categories`
--

CREATE TABLE `categories` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `slug` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Déchargement des données de la table `categories`
--

INSERT INTO `categories` (`id`, `name`, `slug`, `created_at`, `updated_at`) VALUES
(1, 'Amet quod magni voluptatibus sed.', 'amet-quod-magni-voluptatibus-sed', '2019-08-26 23:46:36', '2019-08-26 23:46:36'),
(2, 'Non dolorum itaque et delectus.', 'non-dolorum-itaque-et-delectus', '2019-08-26 23:46:36', '2019-08-26 23:46:36'),
(3, 'Qui praesentium et eos.', 'qui-praesentium-et-eos', '2019-08-26 23:46:36', '2019-08-26 23:46:36'),
(4, 'Et minima blanditiis reiciendis facilis.', 'et-minima-blanditiis-reiciendis-facilis', '2019-08-26 23:46:36', '2019-08-26 23:46:36'),
(5, 'Et molestias recusandae aut nihil voluptatem eligendi.', 'et-molestias-recusandae-aut-nihil-voluptatem-eligendi', '2019-08-26 23:46:36', '2019-08-26 23:46:36'),
(6, 'Officia error minima accusamus similique nobis.', 'officia-error-minima-accusamus-similique-nobis', '2019-08-26 23:46:36', '2019-08-26 23:46:36'),
(7, 'Facere quod et consequatur laborum.', 'facere-quod-et-consequatur-laborum', '2019-08-26 23:46:37', '2019-08-26 23:46:37'),
(8, 'Rerum aut quam repellendus aut quisquam.', 'rerum-aut-quam-repellendus-aut-quisquam', '2019-08-26 23:46:37', '2019-08-26 23:46:37'),
(9, 'Dolor esse omnis ducimus temporibus itaque et fugiat.', 'dolor-esse-omnis-ducimus-temporibus-itaque-et-fugiat', '2019-08-26 23:46:37', '2019-08-26 23:46:37'),
(10, 'Ut alias autem inventore enim est a nam quos.', 'ut-alias-autem-inventore-enim-est-a-nam-quos', '2019-08-26 23:46:37', '2019-08-26 23:46:37'),
(11, 'Dolorum maiores necessitatibus rem ut.', 'dolorum-maiores-necessitatibus-rem-ut', '2019-08-26 23:46:37', '2019-08-26 23:46:37'),
(12, 'Laboriosam aut blanditiis ipsam debitis aut odio nulla.', 'laboriosam-aut-blanditiis-ipsam-debitis-aut-odio-nulla', '2019-08-26 23:46:37', '2019-08-26 23:46:37'),
(13, 'Dolores soluta porro quas est veritatis necessitatibus provident.', 'dolores-soluta-porro-quas-est-veritatis-necessitatibus-provident', '2019-08-26 23:46:37', '2019-08-26 23:46:37'),
(14, 'Harum enim ea non quia nemo quia ab.', 'harum-enim-ea-non-quia-nemo-quia-ab', '2019-08-26 23:46:37', '2019-08-26 23:46:37'),
(15, 'Voluptate aut est voluptatum inventore dolorem et.', 'voluptate-aut-est-voluptatum-inventore-dolorem-et', '2019-08-26 23:46:37', '2019-08-26 23:46:37'),
(16, 'Numquam consequuntur porro omnis nesciunt natus.', 'numquam-consequuntur-porro-omnis-nesciunt-natus', '2019-08-26 23:46:37', '2019-08-26 23:46:37'),
(17, 'Laborum error perspiciatis et.', 'laborum-error-perspiciatis-et', '2019-08-26 23:46:37', '2019-08-26 23:46:37'),
(18, 'Quibusdam ut quo enim aut alias.', 'quibusdam-ut-quo-enim-aut-alias', '2019-08-26 23:46:37', '2019-08-26 23:46:37'),
(19, 'Voluptatem qui sed adipisci ad occaecati eligendi illo.', 'voluptatem-qui-sed-adipisci-ad-occaecati-eligendi-illo', '2019-08-26 23:46:37', '2019-08-26 23:46:37'),
(20, 'Qui eos corrupti et recusandae numquam et unde.', 'qui-eos-corrupti-et-recusandae-numquam-et-unde', '2019-08-26 23:46:37', '2019-08-26 23:46:37');

-- --------------------------------------------------------

--
-- Structure de la table `migrations`
--

CREATE TABLE `migrations` (
  `id` int(10) UNSIGNED NOT NULL,
  `migration` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `batch` int(11) NOT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Déchargement des données de la table `migrations`
--

INSERT INTO `migrations` (`id`, `migration`, `batch`) VALUES
(1, '2014_10_12_000000_create_users_table', 1),
(2, '2014_10_12_100000_create_password_resets_table', 1),
(3, '2019_08_26_213411_create_questions_table', 1),
(4, '2019_08_26_213725_create_categories_table', 1),
(5, '2019_08_26_235856_create_replies_table', 2);

-- --------------------------------------------------------

--
-- Structure de la table `password_resets`
--

CREATE TABLE `password_resets` (
  `email` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL,
  `token` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `created_at` timestamp NULL DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

-- --------------------------------------------------------

--
-- Structure de la table `questions`
--

CREATE TABLE `questions` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `title` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `slug` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `body` text COLLATE utf8mb4_unicode_ci NOT NULL,
  `user_id` int(10) UNSIGNED NOT NULL,
  `category_id` int(10) UNSIGNED NOT NULL,
  `votes` int(11) NOT NULL DEFAULT '0',
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Déchargement des données de la table `questions`
--

INSERT INTO `questions` (`id`, `title`, `slug`, `body`, `user_id`, `category_id`, `votes`, `created_at`, `updated_at`) VALUES
(1, 'Est officiis voluptas et.', 'est-officiis-voluptas-et', 'Exercitationem eaque commodi sed molestiae minima delectus voluptas. Sequi dolores quo et aliquam. Quia fugiat sed perferendis temporibus.', 6, 8, 0, '2019-08-26 23:46:38', '2019-08-26 23:46:38'),
(2, 'Est ut sit laborum eos culpa.', 'est-ut-sit-laborum-eos-culpa', 'Quo corporis fuga animi voluptate explicabo. Sit aliquam rerum cum. Quasi nulla et quia in saepe laudantium voluptatem.', 2, 1, 0, '2019-08-26 23:46:38', '2019-08-26 23:46:38'),
(3, 'Et cum hic iure labore qui corrupti non.', 'et-cum-hic-iure-labore-qui-corrupti-non', 'Itaque natus ut adipisci explicabo nihil accusamus similique odio. Error provident et mollitia nihil sapiente. Excepturi laudantium id aliquam molestiae. Ut qui qui sed.', 3, 8, 0, '2019-08-26 23:46:38', '2019-08-26 23:46:38'),
(4, 'Tempora sapiente est molestiae consequatur possimus et.', 'tempora-sapiente-est-molestiae-consequatur-possimus-et', 'Voluptas ex qui est inventore occaecati id laboriosam. Et accusantium magnam velit dolorem.', 6, 3, 1, '2019-08-26 23:46:38', '2019-08-27 00:19:24'),
(5, 'Cumque neque porro non maxime.', 'cumque-neque-porro-non-maxime', 'Consequatur qui consequuntur incidunt voluptatem ipsam dignissimos ut. Voluptatem maiores nemo exercitationem voluptas.', 3, 4, 0, '2019-08-26 23:46:38', '2019-08-26 23:46:38'),
(6, 'Voluptatem error quo rerum ullam vel laudantium.', 'voluptatem-error-quo-rerum-ullam-vel-laudantium', 'Illo sit error ab possimus magni ipsa cum veniam. Fugiat enim voluptatum qui praesentium. Necessitatibus quibusdam aliquid voluptates error nemo. Impedit rerum temporibus eligendi accusamus minus qui.', 9, 4, 0, '2019-08-26 23:46:38', '2019-08-26 23:46:38'),
(7, 'Praesentium sunt voluptatem nam sit aut.', 'praesentium-sunt-voluptatem-nam-sit-aut', 'Consectetur esse nesciunt dicta quae et et voluptatem. Dolores nemo optio incidunt qui alias omnis.', 5, 5, 0, '2019-08-26 23:46:38', '2019-08-26 23:46:38'),
(8, 'Est eius aut rerum a placeat consequatur.', 'est-eius-aut-rerum-a-placeat-consequatur', 'Dolorem quasi quod ut ullam error libero. Non saepe impedit quia et nulla. Facere iste aut qui dolorem. Optio ipsa laudantium quidem voluptatem rerum nostrum. Autem qui ullam possimus.', 4, 4, 0, '2019-08-26 23:46:38', '2019-08-26 23:46:38'),
(9, 'Odio officiis aut vel aut aut et nihil.', 'odio-officiis-aut-vel-aut-aut-et-nihil', 'Natus ut doloribus qui ut iste molestiae. Ipsa inventore similique autem minima provident occaecati. Libero aperiam sed est quia nulla dicta non.', 2, 9, 0, '2019-08-26 23:46:38', '2019-08-26 23:46:38'),
(10, 'Sit veritatis ut ut optio quia hic optio.', 'sit-veritatis-ut-ut-optio-quia-hic-optio', 'Commodi suscipit ex molestiae omnis labore consequatur. Quia ipsum ea dolorum ullam. Soluta est quia quasi et. Quibusdam atque accusantium vitae sit animi id. Labore dolor nulla distinctio dolor aut illum dicta.', 4, 4, 0, '2019-08-26 23:46:38', '2019-08-26 23:46:38'),
(11, 'Repellat qui laudantium necessitatibus.', 'repellat-qui-laudantium-necessitatibus', 'Soluta in nemo omnis iste. Repellat doloremque consequatur nisi omnis quam asperiores voluptas iure. Dolorem quisquam reiciendis voluptates aut ratione. Dolores quisquam asperiores quam voluptas quam quo.', 1, 1, 0, '2019-08-26 23:46:38', '2019-08-26 23:46:38'),
(12, 'Iste dolorum in dignissimos.', 'iste-dolorum-in-dignissimos', 'Esse cupiditate ipsa voluptatibus vel amet. Temporibus deserunt repellendus et quibusdam explicabo. Aperiam in error ab ea perferendis autem asperiores.', 4, 1, 0, '2019-08-26 23:46:38', '2019-08-26 23:46:38'),
(13, 'Voluptate et quasi at facere et.', 'voluptate-et-quasi-at-facere-et', 'Nam dolor magnam quas ut eum. Consequuntur excepturi ut harum ea odio. Id qui neque sed cupiditate facilis. Sunt atque incidunt quidem tempora eos.', 2, 4, 0, '2019-08-26 23:46:38', '2019-08-26 23:46:38'),
(14, 'Nulla ab debitis corrupti architecto et quia beatae.', 'nulla-ab-debitis-corrupti-architecto-et-quia-beatae', 'Quidem optio eum ad exercitationem ut et. Vel deserunt laborum nobis quaerat. Sapiente alias maiores cum autem rerum illo dolores.', 5, 9, 0, '2019-08-26 23:46:38', '2019-08-26 23:46:38'),
(15, 'Eum odio consequuntur nihil ut.', 'eum-odio-consequuntur-nihil-ut', 'Aut praesentium ab libero consequatur dolores dolore. Deleniti voluptas quia minus aut dolor voluptatem. Et consequuntur voluptatem recusandae placeat dolorem dolor nesciunt.', 4, 2, 0, '2019-08-26 23:46:38', '2019-08-26 23:46:38'),
(16, 'Quidem aut vitae minima.', 'quidem-aut-vitae-minima', 'Unde eaque quidem explicabo aliquid corrupti corporis quia. Occaecati nobis qui possimus dignissimos voluptas. Debitis repellat consequuntur est et. Voluptates optio suscipit dolore provident dolores unde.', 3, 3, 0, '2019-08-26 23:46:39', '2019-08-26 23:46:39'),
(17, 'Et et nostrum at ipsam.', 'et-et-nostrum-at-ipsam', 'Placeat saepe repellendus sequi eveniet quo. Maxime animi sint odit cum itaque omnis nesciunt. Recusandae perferendis optio aut dolorem. Necessitatibus iure iure sunt consectetur culpa quibusdam sit.', 8, 1, -1, '2019-08-26 23:46:39', '2019-08-26 23:49:55'),
(18, 'Quasi mollitia assumenda aut aut magnam.', 'quasi-mollitia-assumenda-aut-aut-magnam', 'Mollitia vel est saepe unde et. Qui voluptatem a non quibusdam nulla animi. Aut ut delectus harum.', 1, 5, 1, '2019-08-26 23:46:39', '2019-08-26 23:49:44'),
(19, 'Nihil repellendus inventore omnis nam eveniet pariatur et.', 'nihil-repellendus-inventore-omnis-nam-eveniet-pariatur-et', 'Vitae molestias delectus optio eum alias quas non. Dolorem libero velit laboriosam molestias dolor. Beatae omnis nisi in eveniet qui possimus.', 2, 5, 0, '2019-08-26 23:46:39', '2019-08-26 23:46:39'),
(20, 'Cumque dignissimos aspernatur perferendis aut praesentium ut voluptate perspiciatis.', 'cumque-dignissimos-aspernatur-perferendis-aut-praesentium-ut-voluptate-perspiciatis', 'Eum consequatur facilis explicabo est incidunt sapiente sed facere. Et quo sunt autem dolore ea. Suscipit est omnis animi modi sint.', 1, 4, 0, '2019-08-26 23:46:39', '2019-08-26 23:46:39'),
(21, 'this is my first question', 'this-is-my-first-question', 'this is my first question here', 21, 10, 1, '2019-08-27 01:01:01', '2019-08-27 01:02:29'),
(22, 'this is my first question', 'this-is-my-first-question', 'this is my first question here', 21, 10, 0, '2019-08-27 01:01:02', '2019-08-27 01:01:02');

-- --------------------------------------------------------

--
-- Structure de la table `replies`
--

CREATE TABLE `replies` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `body` text COLLATE utf8mb4_unicode_ci NOT NULL,
  `user_id` int(10) UNSIGNED NOT NULL,
  `question_id` int(10) UNSIGNED NOT NULL,
  `bestAnswer` tinyint(1) NOT NULL DEFAULT '0',
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Déchargement des données de la table `replies`
--

INSERT INTO `replies` (`id`, `body`, `user_id`, `question_id`, `bestAnswer`, `created_at`, `updated_at`) VALUES
(1, 'salam cava les amis', 21, 4, 0, '2019-08-27 00:09:08', '2019-08-27 00:09:08'),
(2, 'hello there are you here', 21, 4, 0, '2019-08-27 00:23:35', '2019-08-27 00:23:35'),
(3, 'salam ca va va', 21, 18, 0, '2019-08-27 00:39:35', '2019-08-27 01:01:55'),
(4, 'hello there how  you', 21, 18, 0, '2019-08-27 00:41:39', '2019-08-27 00:57:16'),
(5, 'salam ca va', 21, 21, 1, '2019-08-27 01:01:46', '2019-08-27 01:01:55'),
(6, 'sdvsdvsdvsdv', 21, 13, 0, '2019-08-27 01:13:58', '2019-08-27 01:13:58');

-- --------------------------------------------------------

--
-- Structure de la table `users`
--

CREATE TABLE `users` (
  `id` bigint(20) UNSIGNED NOT NULL,
  `name` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `email` varchar(191) COLLATE utf8mb4_unicode_ci NOT NULL,
  `email_verified_at` timestamp NULL DEFAULT NULL,
  `password` varchar(255) COLLATE utf8mb4_unicode_ci NOT NULL,
  `remember_token` varchar(100) COLLATE utf8mb4_unicode_ci DEFAULT NULL,
  `created_at` timestamp NULL DEFAULT NULL,
  `updated_at` timestamp NULL DEFAULT NULL
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci;

--
-- Déchargement des données de la table `users`
--

INSERT INTO `users` (`id`, `name`, `email`, `email_verified_at`, `password`, `remember_token`, `created_at`, `updated_at`) VALUES
(1, 'Blanca Quitzon', 'psimonis@example.org', '2019-08-26 23:46:34', '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', '4l1P5h5Ozd', '2019-08-26 23:46:34', '2019-08-26 23:46:34'),
(2, 'Dr. Jerrell Corkery IV', 'okeefe.mortimer@example.net', '2019-08-26 23:46:34', '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', 'wfZogkxQwn', '2019-08-26 23:46:34', '2019-08-26 23:46:34'),
(3, 'Adolf Ebert', 'gislason.yasmine@example.com', '2019-08-26 23:46:34', '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', '5rJIpE9o1H', '2019-08-26 23:46:34', '2019-08-26 23:46:34'),
(4, 'Addie Koss', 'mayer.desmond@example.net', '2019-08-26 23:46:34', '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', 'XIDGBgVb5t', '2019-08-26 23:46:35', '2019-08-26 23:46:35'),
(5, 'Rollin Beahan', 'rharvey@example.org', '2019-08-26 23:46:34', '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', 'hmFnQi4Cv8', '2019-08-26 23:46:35', '2019-08-26 23:46:35'),
(6, 'Miss Felipa McDermott Jr.', 'gutkowski.katlynn@example.com', '2019-08-26 23:46:34', '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', '4G9YZ6oBi1', '2019-08-26 23:46:35', '2019-08-26 23:46:35'),
(7, 'Alphonso Brekke', 'gregory.damore@example.org', '2019-08-26 23:46:34', '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', 'KNxcQQhkD2', '2019-08-26 23:46:35', '2019-08-26 23:46:35'),
(8, 'Prof. Rowland Rowe', 'kelvin86@example.org', '2019-08-26 23:46:34', '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', 'vH3rqE1zz3', '2019-08-26 23:46:35', '2019-08-26 23:46:35'),
(9, 'Prof. Rahsaan Kris', 'elisa22@example.com', '2019-08-26 23:46:34', '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', '6E2sq3I6NB', '2019-08-26 23:46:35', '2019-08-26 23:46:35'),
(10, 'Loraine Jacobson', 'brook93@example.com', '2019-08-26 23:46:34', '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', 'WvvuFuMDOh', '2019-08-26 23:46:35', '2019-08-26 23:46:35'),
(11, 'Kobe Treutel', 'effertz.cyrus@example.org', '2019-08-26 23:46:34', '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', 'luCN5c6KEg', '2019-08-26 23:46:35', '2019-08-26 23:46:35'),
(12, 'Clare Denesik PhD', 'cpollich@example.com', '2019-08-26 23:46:34', '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', '3SqA9n8JBs', '2019-08-26 23:46:35', '2019-08-26 23:46:35'),
(13, 'Crystel Schultz', 'heaney.mandy@example.org', '2019-08-26 23:46:34', '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', 'PUnXyP7Z0J', '2019-08-26 23:46:35', '2019-08-26 23:46:35'),
(14, 'Mr. Elmo Jones PhD', 'dee.haley@example.net', '2019-08-26 23:46:34', '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', 'zka8scMldv', '2019-08-26 23:46:35', '2019-08-26 23:46:35'),
(15, 'Santa Wintheiser', 'dhahn@example.com', '2019-08-26 23:46:34', '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', 'brjvylc04w', '2019-08-26 23:46:35', '2019-08-26 23:46:35'),
(16, 'Tevin Oberbrunner', 'mariane.gorczany@example.com', '2019-08-26 23:46:34', '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', 'HmvHTwat6O', '2019-08-26 23:46:35', '2019-08-26 23:46:35'),
(17, 'Micheal Dibbert', 'laurence88@example.net', '2019-08-26 23:46:34', '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', 'lZxuwcrYi4', '2019-08-26 23:46:35', '2019-08-26 23:46:35'),
(18, 'Fiona Hamill III', 'jessika.macejkovic@example.org', '2019-08-26 23:46:34', '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', 'nPYhvFfE2w', '2019-08-26 23:46:36', '2019-08-26 23:46:36'),
(19, 'Ashley Hamill', 'efren17@example.com', '2019-08-26 23:46:34', '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', '9dBXushYCY', '2019-08-26 23:46:36', '2019-08-26 23:46:36'),
(20, 'Prof. Ethelyn Altenwerth', 'gordon.legros@example.org', '2019-08-26 23:46:34', '$2y$10$92IXUNpkjO0rOQ5byMi.Ye4oKoEa3Ro9llC/.og/at2.uheWG/igi', 'eb9QgpP5xS', '2019-08-26 23:46:36', '2019-08-26 23:46:36'),
(21, 'samadi', 'samadi@email.com', NULL, '$2y$10$5Cvlh0g1gJvBin0KBu5eTOT013lXRIuMC1uUp7DKDvMf2wEhsXXju', NULL, '2019-08-26 23:47:46', '2019-08-26 23:47:46');

--
-- Index pour les tables déchargées
--

--
-- Index pour la table `categories`
--
ALTER TABLE `categories`
  ADD PRIMARY KEY (`id`);

--
-- Index pour la table `migrations`
--
ALTER TABLE `migrations`
  ADD PRIMARY KEY (`id`);

--
-- Index pour la table `password_resets`
--
ALTER TABLE `password_resets`
  ADD KEY `password_resets_email_index` (`email`);

--
-- Index pour la table `questions`
--
ALTER TABLE `questions`
  ADD PRIMARY KEY (`id`),
  ADD KEY `questions_user_id_index` (`user_id`),
  ADD KEY `questions_category_id_index` (`category_id`);

--
-- Index pour la table `replies`
--
ALTER TABLE `replies`
  ADD PRIMARY KEY (`id`),
  ADD KEY `replies_user_id_index` (`user_id`),
  ADD KEY `replies_question_id_index` (`question_id`);

--
-- Index pour la table `users`
--
ALTER TABLE `users`
  ADD PRIMARY KEY (`id`),
  ADD UNIQUE KEY `users_email_unique` (`email`);

--
-- AUTO_INCREMENT pour les tables déchargées
--

--
-- AUTO_INCREMENT pour la table `categories`
--
ALTER TABLE `categories`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=21;

--
-- AUTO_INCREMENT pour la table `migrations`
--
ALTER TABLE `migrations`
  MODIFY `id` int(10) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=6;

--
-- AUTO_INCREMENT pour la table `questions`
--
ALTER TABLE `questions`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=23;

--
-- AUTO_INCREMENT pour la table `replies`
--
ALTER TABLE `replies`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=7;

--
-- AUTO_INCREMENT pour la table `users`
--
ALTER TABLE `users`
  MODIFY `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT, AUTO_INCREMENT=22;
COMMIT;

/*!40101 SET CHARACTER_SET_CLIENT=@OLD_CHARACTER_SET_CLIENT */;
/*!40101 SET CHARACTER_SET_RESULTS=@OLD_CHARACTER_SET_RESULTS */;
/*!40101 SET COLLATION_CONNECTION=@OLD_COLLATION_CONNECTION */;
                            

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

منبعد غادي نديرو الإتصال بقاعدة البيانات غادي تمشي للملف env. ودير عليه تغييرات فالكود فبلاصت laravel دير إسم قاعدة البيانات لي زدتي أنا سميتها laravelstackchannel.

                                //

DB_CONNECTION=mysql
DB_HOST=127.0.0.1
DB_PORT=3306
DB_DATABASE=laravelstackchannel
DB_USERNAME=root
DB_PASSWORD=
                            

3- إضافة ل model Category

منبعد زيد model جديد  سميه Category فيه كندير العلاقة مع ل model Question لي غادي نزيدو من بعد وأيضا كنبدل القيمة ديال البحث من  id ل slug.

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


                                //
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Category extends Model
{
    //

    protected $guarded = [];
    
    public function questions(){
    	return $this->hasMany(Question::class);
    }
    public function getRouteKeyName(){
    	return 'slug';
    }
}
                            

4- إضافة ل model Question

منبعد زيد model جديد  سميه Question فيه كندير العلاقة مع ل model User و Category و Reply لي غادي نزيدو من بعد وأيضا كنبدل القيمة ديال البحث من id ل slug.

وعندي fonction scope لي كنسترجع بها الأسئلة مرتبين بتاريخ الإضافة غادي نحتاجوها من بعد.

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


                                    //
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Question extends Model
{
    //
    protected $guarded = [];

    public function user(){
    	return $this->belongsTo(User::class);
    }
    public function category(){
    	return $this->belongsTo(Category::class);
    }
    public function replies(){
        return $this->hasMany(Reply::class)->orderBy('created_at','DESC');
    }

    public function getRouteKeyName(){
    	return 'slug';
    }

    public function scopeLatest($query){
        return $query->orderBy('created_at','DESC');
    }
}
                                

5- إضافة ل model Reply

منبعد زيد model جديد  سميه Reply فيه كندير العلاقة مع ل model User و Question.

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

                                    //
<?php

namespace App;

use Illuminate\Database\Eloquent\Model;

class Reply extends Model
{
    //
	protected $guarded = [];
    public function user(){
    	return $this->belongsTo(User::class);
    }
    public function question(){
    	return $this->belongsTo(Question::class);
    }
}
                                


إشترك في قناتنا على اليوتيوب

بحث في الموقع


إشترك للتوصل بالجديد