td
This commit is contained in:
parent
5b7403cbbc
commit
29c744c0ec
63
app/Http/Controllers/CategoriesController.php
Normal file
63
app/Http/Controllers/CategoriesController.php
Normal file
@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class CategoriesController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index(Request $request, Bool $paginate = true)
|
||||
{
|
||||
return parent::index($request, $paginate);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
@ -9,10 +9,8 @@ use Illuminate\Http\Response;
|
||||
class ClientsController extends Controller
|
||||
{
|
||||
|
||||
public function index()
|
||||
{
|
||||
return Clients::all();
|
||||
//return response()->json(['Clients' => Clients::all(), 'status' => 'OK'], 200);
|
||||
public function index(Request $request, Bool $paginate = true) {
|
||||
return parent::index($request, $paginate);
|
||||
}
|
||||
|
||||
/**
|
||||
|
63
app/Http/Controllers/CommandesController.php
Normal file
63
app/Http/Controllers/CommandesController.php
Normal file
@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class CommandesController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index(Request $request, Bool $paginate = true)
|
||||
{
|
||||
return parent::index($request, $paginate);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
@ -5,9 +5,32 @@ namespace App\Http\Controllers;
|
||||
use Illuminate\Foundation\Auth\Access\AuthorizesRequests;
|
||||
use Illuminate\Foundation\Bus\DispatchesJobs;
|
||||
use Illuminate\Foundation\Validation\ValidatesRequests;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Routing\Controller as BaseController;
|
||||
use Illuminate\Support\Facades\Log;
|
||||
|
||||
class Controller extends BaseController
|
||||
{
|
||||
use AuthorizesRequests, DispatchesJobs, ValidatesRequests;
|
||||
|
||||
public function index(Request $request, Bool $paginate = true) {
|
||||
try {
|
||||
$route = explode('.', $request->route()->getName());
|
||||
$model = $route[1];
|
||||
$class = 'App\\Models\\' .ucfirst($model);
|
||||
|
||||
$errors = [];
|
||||
|
||||
$instances = $class::fetchAll($request, $paginate);
|
||||
|
||||
foreach ($instances as $i) {
|
||||
$i->setDataTree();
|
||||
}
|
||||
|
||||
return response()->json([$model => $instances, 'status' => 'OK'], 200);
|
||||
} catch (\Exception $e) {
|
||||
Log::debug($e->getMessage() . ' ' .$e->getFile() . ' ' .$e->getLine());
|
||||
return response()->json(['status' => 'ERROR', 'message' => $e->getMessage(), 'errors' => $errors], 404);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
63
app/Http/Controllers/ProduitsController.php
Normal file
63
app/Http/Controllers/ProduitsController.php
Normal file
@ -0,0 +1,63 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class ProduitsController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index(Request $request, Bool $paginate = true)
|
||||
{
|
||||
return parent::index($request, $paginate);
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(Request $request, $id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
@ -3,7 +3,6 @@
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
|
||||
class Categories extends Model
|
||||
@ -24,4 +23,12 @@ class Categories extends Model
|
||||
return $this->belongsToMany('App\Models\Produits', 'produits_categories', 'categories_id', 'products_id');
|
||||
}
|
||||
|
||||
public function setDataTree() {
|
||||
foreach ($this->Produits as $p) {
|
||||
$p->setCalculatedFields();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -3,7 +3,6 @@
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
|
||||
class Clients extends Model
|
||||
{
|
||||
@ -23,4 +22,11 @@ class Clients extends Model
|
||||
{
|
||||
return $this->hasMany('App\Models\Commandes', 'clients_id', 'id');
|
||||
}
|
||||
|
||||
public function setDataTree() {
|
||||
foreach($this->Commandes as $commande) {
|
||||
$commande->setCalculatedFields();
|
||||
$commande->setDataTree();
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -3,7 +3,6 @@
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
@ -28,6 +27,17 @@ class Commandes extends Model
|
||||
|
||||
public function LignesCommandes(): HasMany
|
||||
{
|
||||
return $this->hasMany('App\Models\Lignes_Commandes', 'comandes_id', 'id');
|
||||
return $this->hasMany('App\Models\Lignes_Commandes', 'commandes_id', 'id');
|
||||
}
|
||||
|
||||
public function setDataTree() {
|
||||
if($this->clients_id > 0) {
|
||||
$this->Client->setCalculatedFields();
|
||||
}
|
||||
|
||||
foreach($this->LignesCommandes as $lc) {
|
||||
$lc->setCalculatedFields();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -3,7 +3,6 @@
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsTo;
|
||||
|
||||
class Lignes_Commandes extends Model
|
||||
@ -29,4 +28,10 @@ class Lignes_Commandes extends Model
|
||||
return $this->belongsTo('App\Models\Commandes', 'commandes_id', 'id');
|
||||
}
|
||||
|
||||
public function setDataTree(){
|
||||
foreach($this->Produits as $produit){
|
||||
$produit->setCalculatedFields();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
43
app/Models/Model.php
Normal file
43
app/Models/Model.php
Normal file
@ -0,0 +1,43 @@
|
||||
<?php
|
||||
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model as Basemodel;
|
||||
|
||||
class Model extends Basemodel
|
||||
{
|
||||
use HasFactory;
|
||||
|
||||
public static function fetchOne(int $id) {
|
||||
$class = get_called_class();
|
||||
$instance = $class::find($id);
|
||||
|
||||
/*
|
||||
if($instance) {
|
||||
$instance->setCalculatedFields();
|
||||
}
|
||||
*/
|
||||
return $instance;
|
||||
}
|
||||
|
||||
public static function fetchAll(Request $request, Bool $paginate = true) {
|
||||
$class = get_called_class();
|
||||
if($paginate) {
|
||||
$instances = $class::paginate(24);
|
||||
} else {
|
||||
$instances = $class::get();
|
||||
}
|
||||
|
||||
foreach ($instances as $i) {
|
||||
$i->setCalculatedFields();
|
||||
}
|
||||
|
||||
return $instances;
|
||||
}
|
||||
|
||||
public function setCalculatedFields() {
|
||||
//
|
||||
}
|
||||
}
|
@ -3,7 +3,6 @@
|
||||
namespace App\Models;
|
||||
|
||||
use Illuminate\Database\Eloquent\Factories\HasFactory;
|
||||
use Illuminate\Database\Eloquent\Model;
|
||||
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
|
||||
use Illuminate\Database\Eloquent\Relations\HasMany;
|
||||
|
||||
@ -30,4 +29,12 @@ class Produits extends Model
|
||||
return $this->hasMany('App\Models\Lignes_Commandes', 'produits_id', 'id');
|
||||
}
|
||||
|
||||
public function setDataTree(){
|
||||
foreach($this->Categories as $categorie){
|
||||
$categorie->setCalculatedFields();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
@ -1,6 +1,9 @@
|
||||
<?php
|
||||
|
||||
use App\Http\Controllers\CategoriesController;
|
||||
use App\Http\Controllers\ClientsController;
|
||||
use App\Http\Controllers\CommandesController;
|
||||
use App\Http\Controllers\ProduitsController;
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Route;
|
||||
|
||||
@ -19,6 +22,8 @@ Route::middleware('auth:sanctum')->get('/user', function (Request $request) {
|
||||
return $request->user();
|
||||
});
|
||||
|
||||
Route::apiResource('/clients', ClientsController::class);
|
||||
Route::apiResource('/clients', ClientsController::class, ['as' => 'api']);
|
||||
Route::apiResource('/categories', CategoriesController::class, ['as' => 'api']);
|
||||
Route::apiResource('/commandes', CommandesController::class, ['as' => 'api']);
|
||||
Route::apiResource('/produits', ProduitsController::class, ['as' => 'api']);
|
||||
|
||||
//Route::get('/clients', [ClientsController::class, 'index']);
|
||||
|
Loading…
x
Reference in New Issue
Block a user