add static azmayesh fields

This commit is contained in:
2024-10-23 15:54:01 +03:30
parent c2ceb3d343
commit e9098b0a55
12 changed files with 137 additions and 18 deletions

View File

@@ -6,6 +6,8 @@ use App\Facades\DataTable\DataTableFacade;
use App\Http\Controllers\Controller;
use App\Http\Traits\ApiResponse;
use App\Models\Azmayesh;
use App\Models\AzmayeshType;
use App\Models\Province;
use Illuminate\Http\JsonResponse;
use Illuminate\Http\Request;
@@ -17,7 +19,17 @@ class AzmayeshController extends Controller
*/
public function index(Request $request): JsonResponse
{
$columns = array('id', 'name');
$columns = array(
'id',
'request_date',
'report_date',
'request_number',
'employer',
'contractor',
'work_number',
'consultant',
'applicant',
);
$allowedFilters = $columns;
$allowedSortings = $columns;
@@ -30,15 +42,36 @@ class AzmayeshController extends Controller
allowedFilters: $allowedFilters,
allowedSortings: $allowedSortings);
return $this->successResponse($data);
return response()->json($data);
}
/**
* Store a newly created resource in storage.
*/
public function store(Request $request)
public function store(Request $request): JsonResponse
{
//
$azmayeshType = AzmayeshType::query()->find($request->azmayesh_type_id);
$province = Province::query()->find($request->province_id);
Azmayesh::query()->create([
'lat' => $request->lat,
'lng' => $request->lng,
'azmayesh_type_id' => $azmayeshType->id,
'azmayesh_type_name' => $azmayeshType->name,
'request_date' => $request->lat,
'report_date' => $request->lat,
'request_number' => $request->lat,
'employer' => $request->lat,
'contractor' => $request->lat,
'work_number' => $request->lat,
'project_name' => $request->lat,
'consultant' => $request->lat,
'applicant' => $request->lat,
'province_id' => $province->id,
'province_name' => $province->name,
]);
return $this->successResponse();
}
/**
@@ -52,9 +85,22 @@ class AzmayeshController extends Controller
/**
* Update the specified resource in storage.
*/
public function update(Request $request, Azmayesh $azmayesh)
public function update(Request $request, Azmayesh $azmayesh): JsonResponse
{
//
$province = Province::query()->find($request->province_id);
$azmayesh->update([
'name' => $request->name,
'username' => $request->username,
'email' => $request->email,
'phone_number' => $request->phone_number,
'national_id' => $request->national_id,
'position' => $request->position,
'province_id' => $province->id,
'province_name' => $province->name,
]);
return $this->successResponse();
}
/**

View File

@@ -21,7 +21,7 @@ class AzmayeshTypeController extends Controller
public function fields(AzmayeshType $azmayeshType): JsonResponse
{
$fields = $azmayeshType->azmayeshFields();
$fields = $azmayeshType->azmayeshFields;
return $this->successResponse($fields);
}

View File

@@ -16,4 +16,9 @@ class Azmayesh extends Model
{
return $this->hasMany(AzmayeshSample::class);
}
public function getRouteKeyName(): string
{
return 'id';
}
}

View File

@@ -8,4 +8,6 @@ use Illuminate\Database\Eloquent\Model;
class AzmayeshSample extends Model
{
use HasFactory;
protected $guarded = [];
}

View File

@@ -20,6 +20,6 @@ class AzmayeshType extends Model
public function azmayeshFields(): BelongsToMany
{
return $this->belongsToMany(AzmayeshField::class);
return $this->belongsToMany(AzmayeshField::class,'azmayesh_field_azmayesh_type');
}
}

View File

@@ -2,6 +2,8 @@
namespace Database\Factories;
use App\Models\AzmayeshType;
use App\Models\Province;
use Illuminate\Database\Eloquent\Factories\Factory;
/**
@@ -17,7 +19,14 @@ class AzmayeshFactory extends Factory
public function definition(): array
{
return [
//
'azmayesh_type_id' => AzmayeshType::factory(),
'azmayesh_type_name' => function (array $attributes) {
return AzmayeshType::query()->find($attributes['azmayesh_type_id'])->name;
},
'province_id' => Province::factory(),
'province_name' => function (array $attributes) {
return Province::query()->find($attributes['province_id'])->name;
},
];
}
}

View File

@@ -17,7 +17,9 @@ class AzmayeshFieldFactory extends Factory
public function definition(): array
{
return [
//
'name' => $this->faker->name,
'unit' => $this->faker->name,
'type' => $this->faker->name,
];
}
}

View File

@@ -2,6 +2,7 @@
namespace Database\Factories;
use App\Models\Azmayesh;
use Illuminate\Database\Eloquent\Factories\Factory;
/**
@@ -17,7 +18,11 @@ class AzmayeshSampleFactory extends Factory
public function definition(): array
{
return [
//
'azmayesh_id' => Azmayesh::factory(),
'azmayesh_name' => function (array $attributes) {
return Azmayesh::query()->find($attributes['azmayesh_id'])->name;
},
'data' => json_encode(['test']),
];
}
}

View File

@@ -17,7 +17,7 @@ class AzmayeshTypeFactory extends Factory
public function definition(): array
{
return [
//
'name' => $this->faker->name
];
}
}

View File

@@ -17,8 +17,18 @@ return new class extends Migration
$table->string('azmayesh_type_name');
$table->string('lat');
$table->string('lng');
$table->foreignId('province_id')->constrained('provinces');
$table->unsignedTinyInteger('province_id');
$table->foreign('province_id')->references('id')->on('provinces');
$table->string('province_name');
$table->date('request_date');
$table->date('report_date');
$table->integer('request_number');
$table->string('employer');
$table->string('contractor');
$table->integer('work_number');
$table->string('project_name');
$table->string('consultant');
$table->string('applicant');
$table->timestamps();
});
}

View File

@@ -16,13 +16,41 @@ class AzmayeshSeeder extends Seeder
DB::table('azmayeshes')->insert([
[
'id' => 1,
'name' => '',
'lat' => '13.45',
'lng' => '11.85',
'azmayesh_type_id' => 1,
'azmayesh_type_name' => 'test',
'province_id' => 11,
'province_name' => 'test',
'request_date' => '1403-07-04',
'report_date' => '1403-07-05',
'request_number' => 0,
'employer' => 'test',
'contractor' => 'test',
'work_number' => 0,
'project_name' => 'test',
'consultant' => 'test',
'applicant' => 'test',
'created_at' => now(),
'updated_at' => now()
],
[
'id' => 2,
'name' => '',
'lat' => '13.45',
'lng' => '11.85',
'azmayesh_type_id' => 1,
'azmayesh_type_name' => 'test',
'province_id' => 11,
'province_name' => 'test',
'request_date' => '1403-07-04',
'report_date' => '1403-07-05',
'request_number' => '0',
'employer' => 'test',
'contractor' => 'test',
'work_number' => '0',
'project_name' => 'test',
'consultant' => 'test',
'applicant' => 'test',
'created_at' => now(),
'updated_at' => now()
],

View File

@@ -1,6 +1,7 @@
<?php
use App\Http\Controllers\V3\Azmayesh\AzmayeshController;
use App\Http\Controllers\V3\Azmayesh\AzmayeshTypeController;
use App\Http\Controllers\V3\Harim\DivarkeshiController;
use App\Http\Controllers\V3\ProfileController;
use Illuminate\Support\Facades\Route;
@@ -34,10 +35,21 @@ Route::prefix('profile')
Route::post('change_password', 'changePassword')->name('changePassword');
});
Route::prefix('azmayesh')
->name('azmayesh.')
Route::prefix('azmayesh_types')
->name('azmayesh_types')
->controller(AzmayeshTypeController::class)
->group(function () {
Route::get('/', 'index')->name('index');
Route::get('/fields/{azmayeshType}', 'fields')->name('fields');
});
Route::prefix('azmayeshes')
->name('azmayeshes.')
->controller(AzmayeshController::class)
->group(function () {
Route::get('/', 'index')->name('index');
Route::get('/fields', 'fields')->name('fields');
Route::get('/{azmayesh}', 'show')->name('show');
Route::post('/store', 'store')->name('store');
Route::post('/update/{azmayesh}', 'update')->name('update');
Route::post('/delete/{azmayesh}', 'delete')->name('delete');
});