From 8bc9e962b7f258466da9cfe21d2e61a2aed74552 Mon Sep 17 00:00:00 2001 From: OMGiTzPomPom Date: Fri, 3 Mar 2023 17:22:05 +0100 Subject: [PATCH] get clients --- app/Http/Controllers/ClientsController.php | 63 ++++++++++++++++++++++ app/Models/Categories.php | 27 ++++++++++ app/Models/Clients.php | 26 +++++++++ app/Models/Commandes.php | 33 ++++++++++++ app/Models/Lignes_Commandes.php | 32 +++++++++++ app/Models/Produits.php | 33 ++++++++++++ routes/api.php | 5 ++ 7 files changed, 219 insertions(+) create mode 100644 app/Http/Controllers/ClientsController.php create mode 100644 app/Models/Categories.php create mode 100644 app/Models/Clients.php create mode 100644 app/Models/Commandes.php create mode 100644 app/Models/Lignes_Commandes.php create mode 100644 app/Models/Produits.php diff --git a/app/Http/Controllers/ClientsController.php b/app/Http/Controllers/ClientsController.php new file mode 100644 index 0000000..4b19301 --- /dev/null +++ b/app/Http/Controllers/ClientsController.php @@ -0,0 +1,63 @@ +json(['Clients' => Clients::all(), 'status' => 'OK'], 200); + + } + + /** + * Store a newly created resource in storage. + * + * @param \Illuminate\Http\Request $request + * @return Response + */ + public function store(Request $request) + { + // + } + + /** + * Display the specified resource. + * + * @param int $id + * @return Response + */ + public function show($id) + { + // + } + + /** + * Update the specified resource in storage. + * + * @param \Illuminate\Http\Request $request + * @param int $id + * @return Response + */ + public function update(Request $request, $id) + { + // + } + + /** + * Remove the specified resource from storage. + * + * @param int $id + * @return Response + */ + public function destroy($id) + { + // + } +} diff --git a/app/Models/Categories.php b/app/Models/Categories.php new file mode 100644 index 0000000..4619149 --- /dev/null +++ b/app/Models/Categories.php @@ -0,0 +1,27 @@ + 'timestamp', + 'updated_at' => 'timestamp', + ]; + + public function Produits(): BelongsToMany + { + return $this->belongsToMany('App\Models\Produits', 'produits_categories', 'categories_id', 'products_id'); + } + +} diff --git a/app/Models/Clients.php b/app/Models/Clients.php new file mode 100644 index 0000000..7bd5bdf --- /dev/null +++ b/app/Models/Clients.php @@ -0,0 +1,26 @@ + 'json', + 'created_at' => 'timestamp', + 'updated_at' => 'timestamp', + ]; + + public function Commandes(): \Illuminate\Database\Eloquent\Relations\HasMany + { + return $this->hasMany('App\Models\Commandes', 'clients_id', 'id'); + } +} diff --git a/app/Models/Commandes.php b/app/Models/Commandes.php new file mode 100644 index 0000000..aa0265f --- /dev/null +++ b/app/Models/Commandes.php @@ -0,0 +1,33 @@ + 'json', + 'created_at' => 'timestamp', + 'updated_at' => 'timestamp', + ]; + + public function Client(): BelongsTo + { + return $this->belongsTo('App\Models\Clients', 'clients_id', 'id'); + } + + public function LignesCommandes(): HasMany + { + return $this->hasMany('App\Models\Lignes_Commandes', 'comandes_id', 'id'); + } +} diff --git a/app/Models/Lignes_Commandes.php b/app/Models/Lignes_Commandes.php new file mode 100644 index 0000000..7b5f0a9 --- /dev/null +++ b/app/Models/Lignes_Commandes.php @@ -0,0 +1,32 @@ + 'timestamp', + 'updated_at' => 'timestamp', + ]; + + public function Produit(): BelongsTo + { + return $this->belongsTo('App\Models\Produits', 'produits_id', 'id'); + } + + public function Commandes(): BelongsTo + { + return $this->belongsTo('App\Models\Commandes', 'commandes_id', 'id'); + } + +} diff --git a/app/Models/Produits.php b/app/Models/Produits.php new file mode 100644 index 0000000..b3d01b1 --- /dev/null +++ b/app/Models/Produits.php @@ -0,0 +1,33 @@ + 'timestamp', + 'updated_at' => 'timestamp', + ]; + + public function Categories(): BelongsToMany + { + return $this->belongsToMany('App\Models\Categories', 'produits_categories', 'products_id', 'categories_id'); + } + + public function LignesCommandes(): HasMany + { + return $this->hasMany('App\Models\Lignes_Commandes', 'produits_id', 'id'); + } + +} diff --git a/routes/api.php b/routes/api.php index eb6fa48..ff9afb0 100644 --- a/routes/api.php +++ b/routes/api.php @@ -1,5 +1,6 @@ get('/user', function (Request $request) { return $request->user(); }); + +Route::apiResource('/clients', ClientsController::class); + +//Route::get('/clients', [ClientsController::class, 'index']);