{"id":19844645,"url":"https://github.com/elazzouzihassan/gestion-de-commandes","last_synced_at":"2025-09-18T12:31:05.286Z","repository":{"id":167396877,"uuid":"642920189","full_name":"ElazzouziHassan/Gestion-de-Commandes","owner":"ElazzouziHassan","description":"CRUD Operation Solution 📊 : Explore our robust CRUD operation solution designed for the 'Gestion de Commandes' (Order Management) project. This repository provides a streamlined approach to managing orders with Create, Read, Update, and Delete functionalities.","archived":false,"fork":false,"pushed_at":"2023-05-24T21:45:50.000Z","size":104,"stargazers_count":4,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2024-11-12T13:04:53.698Z","etag":null,"topics":["crud","crud-operation","laravel","laravel-framework","webapp"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/ElazzouziHassan.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2023-05-19T16:44:44.000Z","updated_at":"2024-03-16T01:44:52.000Z","dependencies_parsed_at":"2023-09-09T15:03:06.214Z","dependency_job_id":null,"html_url":"https://github.com/ElazzouziHassan/Gestion-de-Commandes","commit_stats":null,"previous_names":["elazzouzihassan/gestion_commandes_crud_laravel","elazzouzihassan/gestion-de-commandes"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ElazzouziHassan%2FGestion-de-Commandes","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ElazzouziHassan%2FGestion-de-Commandes/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ElazzouziHassan%2FGestion-de-Commandes/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/ElazzouziHassan%2FGestion-de-Commandes/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/ElazzouziHassan","download_url":"https://codeload.github.com/ElazzouziHassan/Gestion-de-Commandes/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":233479133,"owners_count":18682316,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["crud","crud-operation","laravel","laravel-framework","webapp"],"created_at":"2024-11-12T13:05:00.978Z","updated_at":"2025-09-18T12:31:04.831Z","avatar_url":"https://github.com/ElazzouziHassan.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cp align=\"center\"\u003e\u003ca href=\"https://laravel.com\" target=\"_blank\"\u003e\u003cimg src=\"https://raw.githubusercontent.com/laravel/art/master/logo-lockup/5%20SVG/2%20CMYK/1%20Full%20Color/laravel-logolockup-cmyk-red.svg\" width=\"400\" alt=\"Laravel Logo\"\u003e\u003c/a\u003e\u003c/p\u003e\n\n\u003cp align=\"center\"\u003e\n\u003ca href=\"https://github.com/laravel/framework/actions\"\u003e\u003cimg src=\"https://github.com/laravel/framework/workflows/tests/badge.svg\" alt=\"Build Status\"\u003e\u003c/a\u003e\n\u003ca href=\"https://packagist.org/packages/laravel/framework\"\u003e\u003cimg src=\"https://img.shields.io/packagist/dt/laravel/framework\" alt=\"Total Downloads\"\u003e\u003c/a\u003e\n\u003ca href=\"https://packagist.org/packages/laravel/framework\"\u003e\u003cimg src=\"https://img.shields.io/packagist/v/laravel/framework\" alt=\"Latest Stable Version\"\u003e\u003c/a\u003e\n\u003ca href=\"https://packagist.org/packages/laravel/framework\"\u003e\u003cimg src=\"https://img.shields.io/packagist/l/laravel/framework\" alt=\"License\"\u003e\u003c/a\u003e\n\u003c/p\u003e\n\n\n# CRUD Laravel : Gestion Des Commandes\n\nObjectif : Créer une application de gestion de commandes en utilisant Laravel et une base de \ndonnées MySQL.\n\n## 1 - Création de le projet \n\n```git\ncomposer create-project laravel/laravel gestion_commande\n```\n## 2 - Configuration de la base de données\n\n- sous le fichier `.env`\n```git\nDB_CONNECTION=mysql\nDB_HOST=127.0.0.1\nDB_PORT=3306\nDB_DATABASE=gestion_commande_db\nDB_USERNAME=root\nDB_PASSWORD=\n```\n# Commande Controller\n```git\nphp artisan make:controller CommandeController\n```\napp/Http/Controllers/CommandeController.php\n\n\n```php\n\u003c?php\n\nnamespace App\\Http\\Controllers;\n\nuse App\\Models\\Commande;\nuse Illuminate\\Http\\Request;\n\nclass CommandeController extends Controller\n{\n    public function index()\n    {\n        $commandes = Commande::paginate(10);\n        return view ('commandes.index')-\u003ewith('commandes', $commandes);\n    }\n    \n\n    public function create()\n    {\n        $commandes = Commande::paginate(10);\n        return view('commandes.create')-\u003ewith('commandes', $commandes);\n    }\n\n    public function store(Request $request)\n    {\n        $request-\u003evalidate([\n            \n        ]);\n        Commande::create($request-\u003eall());\n        return redirect('commandes.index')-\u003ewith('success', 'Commande Added!');\n    }\n\n    public function edit(string $id)\n    {\n        $commande = Commande::find($id);\n        return view('commandes.edit');\n    }\n\n    public function update(Request $request, string $id)\n    {\n        $commande = Commande::find($id);\n        $input = $request-\u003eall();\n        $commande-\u003eupdate($input);\n        return redirect('commande')-\u003ewith('flash_message', 'Commande Updated!'); \n    }\n\n    public function destroy(string $id)\n    {\n        Commande::destroy($id);\n        return redirect('commande')-\u003ewith('flash_message', 'Commande deleted!');\n    }\n}\n```\n# les routes:\nroutes/web.php\n```php\nuse App\\Http\\Controllers\\CommandeController;\n\nRoute::group([], function () {\n    Route::get('/', [CommandeController::class, 'index']);\n    Route::get('/commandes/create', [CommandeController::class, 'create']);\n    Route::post('/commande', [CommandeController::class, 'store']);\n    Route::get('/commandes/{commande}/edit', [CommandeController::class, 'edit']);\n    Route::put('/commandes/{commande}', [CommandeController::class, 'update']);\n    Route::delete('/commandes/{commande}', [CommandeController::class, 'destroy']);\n});\n```\n## 3 - Création des modèles Eloquent pour chacune des tables\n\n- Pour la table `Client`\n```git\nphp artisan make:model Client\n```\n\napp/Models/Client.php :\n\n```php\n\u003c?php\n\nnamespace App\\Models;\n\nuse Illuminate\\Database\\Eloquent\\Factories\\HasFactory;\nuse Illuminate\\Database\\Eloquent\\Model;\nuse App\\Models\\Commande;\n\nclass Client extends Model\n{\n    use HasFactory;\n    protected $table = 'clients';\n    protected $primaryKey = 'id';\n    protected $fillable = ['nom', 'prenom', 'ville'];\n\n    public function Commandes()\n    {\n        return $this-\u003ehasMany(Commande::class);\n    }\n}\n```\n\n\n- Pour la table `Commande`\n```git\nphp artisan make:model Commande\n```\napp/Models/Commande.php :\n```php\n\u003c?php\n\nnamespace App\\Models;\n\nuse Illuminate\\Database\\Eloquent\\Factories\\HasFactory;\nuse Illuminate\\Database\\Eloquent\\Model;\nuse App\\Models\\Client;\nuse App\\Models\\Produit;\n\nclass Commande extends Model\n{\n    use HasFactory;\n    protected $table = 'commandes';\n    protected $primaryKey = 'id';\n    protected $fillable = [ 'client_id' ];\n\n    public function Clients()\n    {\n        return $this-\u003ebelongsTo(Client::class);\n    }\n\n    public function Produits()\n    {\n        return $this-\u003ebelongsToMany(Produit::class);\n    }\n}\n```\n\n- Pour la table `CommandeProduit`\n```git\nphp artisan make:model CommandeProduit\n```\napp/Models/CommandeProduit.php :\n```php\n\u003c?php\n\nnamespace App\\Models;\n\nuse Illuminate\\Database\\Eloquent\\Factories\\HasFactory;\nuse Illuminate\\Database\\Eloquent\\Model;\n\nclass CommandeProduit extends Model\n{\n    use HasFactory;\n    protected $table = 'commande_produit';\n    protected $fillable = ['quantite', 'prix' , 'commande_id', 'produit_id' ];\n}\n```\n\n- Pour la table `Produit`\n```git\nphp artisan make:model Produit\n```\napp/Models/Produit.php :\n\n```php\n\u003c?php\n\nnamespace App\\Models;\n\nuse Illuminate\\Database\\Eloquent\\Factories\\HasFactory;\nuse Illuminate\\Database\\Eloquent\\Model;\nuse App\\Models\\Commande;\n\nclass Produit extends Model\n{\n    use HasFactory;\n    protected $table = 'produits';\n    protected $primaryKey = 'id';\n    protected $fillable = ['Libelle', 'Couleur', 'Prix' , 'QteStk'];\n    public function Commandes()\n    {\n        return $this-\u003ebelongsToMany(Commande::class);\n    }\n}\n```\n\n## 4 - Migration:\n- pour la table clients:\n\n```git\nphp artisan make:migration create_clients_table\n```\ndatabase/migrations/2023_05_15_141816_create_clients_table.php:\n```php\n public function up(): void\n    {\n        Schema::create('clients', function (Blueprint $table) {\n            $table-\u003eid();\n            $table-\u003estring('nom');\n            $table-\u003estring('prenom');\n            $table-\u003estring('ville');\n            $table-\u003etimestamps();\n        });\n    }\n```\n\n- pour la table Produits\n```git\nphp artisan make:migration create_produits_table\n```\ndatabase/migrations/2023_05_15_141825_create_produits_table.php:\n\n```php\npublic function up(): void\n    {\n        Schema::create('produits', function (Blueprint $table) {\n            $table-\u003eid();\n            $table-\u003estring('Libelle');\n            $table-\u003estring('Couleur');\n            $table-\u003edouble('Prix');\n            $table-\u003einteger('QteStk');\n            $table-\u003etimestamps();\n        });\n```\n- pour la table commandes:\n\n```git\nphp artisan make:migration create_commandes_table\n```\ndatabase/migrations/2023_05_15_141849_create_commandes_table.php\n```php\npublic function up(): void\n    {\n        Schema::disableForeignKeyConstraints();\n        Schema::create('commandes', function (Blueprint $table) {\n            $table-\u003eid();\n            $table-\u003etimestamps();\n            $table-\u003eunsignedBigInteger('client_id');\n            $table-\u003eforeign('client_id')-\u003ereferences('id')-\u003eon('clients')-\u003eonDelete('cascade');\n        });\n    }\n```\n- pour la table commande_produit:\n```git\nphp artisan make:migration create_commande_produit_table\n```\ndatabase/migrations 2023_05_15_141907_create_commande_produit_table.php\n```php\npublic function up(): void\n    {\n        Schema::disableForeignKeyConstraints();\n        Schema::create('commande_produit', function (Blueprint $table) {\n            $table-\u003eprimary(['produit_id', 'commande_id']);\n            $table-\u003einteger('quantite');\n            $table-\u003efloat('prix');\n            $table-\u003etimestamps();\n            $table-\u003eunsignedBigInteger('produit_id');\n            $table-\u003eforeign('produit_id')-\u003ereferences('id')-\u003eon('produits')-\u003eonDelete('cascade');\n            $table-\u003eunsignedBigInteger('commande_id');\n            $table-\u003eforeign('commande_id')-\u003ereferences('id')-\u003eon('commandes')-\u003eonDelete('cascade');\n        });\n    }\n```\n\n## 5 - Factories :\n\n```git \nphp artisan make:factory ClientFactory\n```\ndatabase/factories/ClientFactory.php\n```php\npublic function definition(): array\n    {\n        return [\n            'Nom'=\u003e$this-\u003efaker-\u003elastName(),\n            'Prenom'=\u003e$this-\u003efaker-\u003efirstName(),\n            'ville'=\u003e$this-\u003efaker-\u003ecity(),\n        ];\n    }\n```\n\n```git \nphp artisan make:factory CommandeFactory\n```\ndatabase/factories/CommandeFactory.php\n```php\n public function definition(): array\n    {\n        return [\n            'client_id'=\u003eClient::factory(),\n        ];\n    }\n```\n\n```git \nphp artisan make:factory ProduitFactory\n```\ndatabase/factories/ProduitFactory.php\n```php\n public function definition(): array\n    {\n        return [\n            'Libelle'=\u003e$this-\u003efaker-\u003esentence(3),\n            'Couleur'=\u003e$this-\u003efaker-\u003ecolorName(),\n            'prix'=\u003e$this-\u003efaker-\u003erandomFloat(2, 2, 1000),\n            'QteStk'=\u003e$this-\u003efaker-\u003enumberBetween(2, 100),\n        ];\n    }\n```\n\n```git \nphp artisan make:factory CommandeProduitFactory\n```\ndatabase/factories/CommandeProduitFactory.php\n```php\npublic function definition(): array\n    {\n        return [\n            'commande_id'=\u003eCommande::factory(),\n            'produit_id'=\u003eProduit::factory(),\n            'quantite'=\u003e$this-\u003efaker-\u003erandomNumber(),\n            'prix'=\u003e$this-\u003efaker-\u003erandomFloat(),\n        ];\n    }\n```\n\n## 6 - seeders\n\ndatabase/seeders/DatabaseSeeder.php\n\n```php\nuse App\\Models\\Client;\nuse App\\Models\\Commande;\nuse App\\Models\\Produit;\n\n\n public function run(): void\n    {\n        Client::factory()-\u003ecount(10)-\u003ecreate()-\u003eeach(\n            function ($client){\n                Commande::factory()-\u003ecount(5)-\u003ecreate(\n                  [ 'client_id' =\u003e $client-\u003eid ])-\u003eeach(\n                        function ($commande){\n                            $produits = Produit::factory()-\u003ecount(rand(1, 5))-\u003ecreate();\n                            foreach ($produits as $produit) {\n                                $commande-\u003eproduits()-\u003eattach($produit, [\n                                    'quantite' =\u003e rand(1, 10),\n                                    'prix' =\u003e rand(10, 100),\n                                ]);\n                            }\n                        }\n                );\n            }\n        );\n        \n    }\n```\n\n## 8 - migrate\n```git\nphp artisan migrate:fresh\n \nphp artisan migrate:fresh --seed\n```\n\n\n\n# Laravel Tinker : Tester des requêtes\n\n- Pour ajouter Tinker à votre projet, lancez :\n```git\ncomposer require laravel/tinker\n```\n- Ensuite, lancez Tinker avec la commande suivante :\n\n```git\nphp artisan tinker\n```\n\n## Quelques requêtes à tester :\n\n```git\nuse App\\Models\\Commande;\nuse App\\Models\\Produit;\nuse App\\Models\\Client;\n```\n\n- 1 -  Pour trouver toutes les commandes, clients ou produits, lancez les commandes suivantes : \n\n```git\nCommande::all();\n```\n\n```git\nClient::all();\n```\n\n```git\nProduit::all();\n```\n\n- 2 - Supprimer un client :\n```git\n$client = Client::find(1);\n$client-\u003edelete();\n```\nou\n\n```git\nClient::find(1)-\u003edelete();\n```\n\n3 - Trouver tous les clients liés à une commande :\n\n```git\n$client = Client::find(1); \n$commands = $client-\u003ecommandes;\n```\n\nou \n\n```git\nClient::find(1)-\u003ecommandes;\n```\n\n4 - Trouver tous les produits liés à une commande :\n\n```git\n$commande = Commande::find(1); \n$products = $commande-\u003eproduits;\n```\nou\n\n```git\nCommande::find(1)-\u003eproduits;\n```\n\n5 - Créer une nouvelle commande pour un client :\n\n```git\n$client = Client::find(1); \n$commande = new Commande;\n$commande-\u003edate_commande = now();\n$client-\u003ecommandes()-\u003esave($commande);\n```\n\n6 - Ajouter un produit à une commande existante :\n\n```git\n$commande = Commande::find(1); \n$produit = Produit::find(1);\n$commande-\u003eproduits()-\u003eattach($produit, ['quantite' =\u003e 5]);\n```\n\n7 - Supprimer un produit d'une commande :\n\n```git\n\n$commande = Commande::find(1);\n$produit = Produit::find(1); \n$commande-\u003eproduits()-\u003edetach($produit);\n```\n\n\n8 - Créer une client: \n\n```git\n$client = new Client;\n$client-\u003enom = \"Elazzouzi Hassan\";\n$client-\u003ecategorie =2;\n$client-\u003eville = \"El Jadida\";\n$client-\u003esave();\n```\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felazzouzihassan%2Fgestion-de-commandes","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Felazzouzihassan%2Fgestion-de-commandes","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Felazzouzihassan%2Fgestion-de-commandes/lists"}