create all azmayesh resources and its dependencies

This commit is contained in:
2024-10-22 16:40:36 +03:30
parent 9aa3cf320f
commit c2ceb3d343
20 changed files with 548 additions and 0 deletions

View File

@@ -0,0 +1,69 @@
<?php
namespace App\Http\Controllers\V3\Azmayesh;
use App\Facades\DataTable\DataTableFacade;
use App\Http\Controllers\Controller;
use App\Http\Traits\ApiResponse;
use App\Models\Azmayesh;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class AzmayeshController extends Controller
{
use ApiResponse;
/**
* Display a listing of the resource.
*/
public function index(Request $request): JsonResponse
{
$columns = array('id', 'name');
$allowedFilters = $columns;
$allowedSortings = $columns;
$query = Azmayesh::query();
$data = DataTableFacade::run(
$query,
$request,
allowedFilters: $allowedFilters,
allowedSortings: $allowedSortings);
return $this->successResponse($data);
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
{
//
}
/**
* Display the specified resource.
*/
public function show(Azmayesh $azmayesh): JsonResponse
{
return $this->successResponse($azmayesh->load('azmayeshSamples'));
}
/**
* Update the specified resource in storage.
*/
public function update(Request $request, Azmayesh $azmayesh)
{
//
}
/**
* Remove the specified resource from storage.
*/
public function destroy(Azmayesh $azmayesh): JsonResponse
{
$azmayesh->delete();
return $this->successResponse();
}
}

View File

@@ -0,0 +1,28 @@
<?php
namespace App\Http\Controllers\V3\Azmayesh;
use App\Http\Controllers\Controller;
use App\Http\Traits\ApiResponse;
use App\Models\AzmayeshType;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
class AzmayeshTypeController extends Controller
{
use ApiResponse;
public function index(): JsonResponse
{
$allTypes = AzmayeshType::all();
return $this->successResponse($allTypes);
}
public function fields(AzmayeshType $azmayeshType): JsonResponse
{
$fields = $azmayeshType->azmayeshFields();
return $this->successResponse($fields);
}
}

19
app/Models/Azmayesh.php Normal file
View File

@@ -0,0 +1,19 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\HasMany;
class Azmayesh extends Model
{
use HasFactory;
protected $guarded = [];
public function azmayeshSamples(): HasMany
{
return $this->hasMany(AzmayeshSample::class);
}
}

View File

@@ -0,0 +1,19 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
use Illuminate\Database\Eloquent\Relations\BelongsToMany;
class AzmayeshField extends Model
{
use HasFactory;
protected $guarded = [];
public function azmayeshTypes(): BelongsToMany
{
return $this->belongsToMany(AzmayeshType::class);
}
}

View File

@@ -0,0 +1,11 @@
<?php
namespace App\Models;
use Illuminate\Database\Eloquent\Factories\HasFactory;
use Illuminate\Database\Eloquent\Model;
class AzmayeshSample extends Model
{
use HasFactory;
}

View File

@@ -0,0 +1,25 @@
<?php
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;
class AzmayeshType extends Model
{
use HasFactory;
protected $guarded = [];
public function azmayeshes(): HasMany
{
return $this->hasMany(Azmayesh::class);
}
public function azmayeshFields(): BelongsToMany
{
return $this->belongsToMany(AzmayeshField::class);
}
}

View File

@@ -0,0 +1,23 @@
<?php
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\Azmayesh>
*/
class AzmayeshFactory extends Factory
{
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition(): array
{
return [
//
];
}
}

View File

@@ -0,0 +1,23 @@
<?php
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\AzmayeshField>
*/
class AzmayeshFieldFactory extends Factory
{
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition(): array
{
return [
//
];
}
}

View File

@@ -0,0 +1,23 @@
<?php
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\AzmayeshSample>
*/
class AzmayeshSampleFactory extends Factory
{
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition(): array
{
return [
//
];
}
}

View File

@@ -0,0 +1,23 @@
<?php
namespace Database\Factories;
use Illuminate\Database\Eloquent\Factories\Factory;
/**
* @extends \Illuminate\Database\Eloquent\Factories\Factory<\App\Models\AzmayeshType>
*/
class AzmayeshTypeFactory extends Factory
{
/**
* Define the model's default state.
*
* @return array<string, mixed>
*/
public function definition(): array
{
return [
//
];
}
}

View File

@@ -0,0 +1,31 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('azmayesh_fields', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->string('unit');
$table->string('type');
$table->string('option')->nullable();
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('azmayesh_fields');
}
};

View File

@@ -0,0 +1,28 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('azmayesh_types', function (Blueprint $table) {
$table->id();
$table->string('name');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('azmayesh_types');
}
};

View File

@@ -0,0 +1,33 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('azmayeshes', function (Blueprint $table) {
$table->id();
$table->foreignId('azmayesh_type_id')->constrained('azmayesh_types');
$table->string('azmayesh_type_name');
$table->string('lat');
$table->string('lng');
$table->foreignId('province_id')->constrained('provinces');
$table->string('province_name');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('azmayeshes');
}
};

View File

@@ -0,0 +1,30 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('azmayesh_samples', function (Blueprint $table) {
$table->id();
$table->foreignId('azmayesh_id')->constrained('azmayeshes');
$table->string('azmayesh_name');
$table->json('data');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('azmayesh_samples');
}
};

View File

@@ -0,0 +1,29 @@
<?php
use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;
return new class extends Migration
{
/**
* Run the migrations.
*/
public function up(): void
{
Schema::create('azmayesh_field_azmayesh_type', function (Blueprint $table) {
$table->id();
$table->foreignId('azmayesh_field_id')->constrained('azmayesh_fields');
$table->foreignId('azmayesh_type_id')->constrained('azmayesh_types');
$table->timestamps();
});
}
/**
* Reverse the migrations.
*/
public function down(): void
{
Schema::dropIfExists('azmayesh_field_azmayesh_type');
}
};

View File

@@ -0,0 +1,37 @@
<?php
namespace Database\Seeders;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
class AzmayeshFieldSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{
DB::table('azmayesh_fields')->insert([
[
'id' => 1,
'name' => 'طول',
'unit' => 'سانتی متر',
'type' => 'input',
'option' => null,
'created_at' => now(),
'updated_at' => now()
],
[
'id' => 2,
'name' => 'عرض',
'unit' => 'سانتی متر',
'type' => 'input',
'option' => null,
'created_at' => now(),
'updated_at' => now()
],
]);
}
}

View File

@@ -0,0 +1,32 @@
<?php
namespace Database\Seeders;
use App\Models\Azmayesh;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
class AzmayeshSampleSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{
DB::table('azmayesh_samples')->insert([
[
'id' => 1,
'azmayesh_id' => Azmayesh::factory(),
'azmayesh_name' => function (array $attributes) {
return Azmayesh::query()->find($attributes['azmayesh_id'])->name;
},
'data' => json_encode([
1 => 'test'
]),
'created_at' => now(),
'updated_at' => now()
],
]);
}
}

View File

@@ -0,0 +1,31 @@
<?php
namespace Database\Seeders;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
class AzmayeshSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{
DB::table('azmayeshes')->insert([
[
'id' => 1,
'name' => '',
'created_at' => now(),
'updated_at' => now()
],
[
'id' => 2,
'name' => '',
'created_at' => now(),
'updated_at' => now()
],
]);
}
}

View File

@@ -0,0 +1,25 @@
<?php
namespace Database\Seeders;
use Illuminate\Database\Console\Seeds\WithoutModelEvents;
use Illuminate\Database\Seeder;
use Illuminate\Support\Facades\DB;
class AzmayeshTypeSeeder extends Seeder
{
/**
* Run the database seeds.
*/
public function run(): void
{
DB::table('azmayesh_types')->insert([
[
'id' => 1,
'name' => 'تعیین مقاومت فشاری بتن',
'created_at' => now(),
'updated_at' => now()
],
]);
}
}

View File

@@ -1,5 +1,6 @@
<?php
use App\Http\Controllers\V3\Azmayesh\AzmayeshController;
use App\Http\Controllers\V3\Harim\DivarkeshiController;
use App\Http\Controllers\V3\ProfileController;
use Illuminate\Support\Facades\Route;
@@ -32,3 +33,11 @@ Route::prefix('profile')
Route::post('edit', 'edit')->name('edit');
Route::post('change_password', 'changePassword')->name('changePassword');
});
Route::prefix('azmayesh')
->name('azmayesh.')
->controller(AzmayeshController::class)
->group(function () {
Route::get('/', 'index')->name('index');
Route::get('/fields', 'fields')->name('fields');
});