mirror of
https://git.meshkee.com/cssd/cssd-back.git
synced 2026-10-10 20:01:07 +03:30
Come BackEnd
This commit is contained in:
@@ -0,0 +1,116 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers;
|
||||
|
||||
use Illuminate\Http\Request;
|
||||
use Illuminate\Support\Facades\Auth;
|
||||
use App\TestResult;
|
||||
|
||||
class TestResultController extends Controller
|
||||
{
|
||||
/**
|
||||
* Display a listing of the resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function index()
|
||||
{
|
||||
$TestResult = TestResult::with('testtype')->paginate(10);
|
||||
return response()->json(['TestResult' => $TestResult, 'LastPage' => $TestResult->lastPage()]);
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for creating a new resource.
|
||||
*
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function create()
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Store a newly created resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function store(Request $request)
|
||||
{
|
||||
$TestResult = [
|
||||
'user_id' => Auth::user()->id,
|
||||
'autoclave_id' => $request->autoclave_id,
|
||||
'test_type_id' => $request->test_type_id,
|
||||
'result' => $request->result,
|
||||
'verified' => 0,
|
||||
];
|
||||
$TestResultObj = TestResult::create($TestResult);
|
||||
$TestResultInfo = $request->info;
|
||||
|
||||
// $TestType = TestType::with('inputs')->where('id',$request->test_type_id)->first();
|
||||
$Inputs = Input::where('test_type_id',$request->test_type_id)->get();
|
||||
foreach ($Inputs as $Input) {
|
||||
if ($Input->type == 'Select' || $Input->type == 'CheckBox') {
|
||||
$OptionIDs = $Input->options->pluck('id')->toArray();
|
||||
$Value = $OptionIDs;
|
||||
}
|
||||
else {
|
||||
$Value = $TestResultInfo[$Input->name];
|
||||
}
|
||||
$InputValueObj = InputValue::create(['test_result_id' => $TestResultObj->id , 'input_id' => $Input->id , 'value' => $Value]);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Display the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function show($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Show the form for editing the specified resource.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function edit($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
|
||||
/**
|
||||
* Update the specified resource in storage.
|
||||
*
|
||||
* @param \Illuminate\Http\Request $request
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function update(Request $request, TestResult $TestResult)
|
||||
{
|
||||
$this->validate($request, [
|
||||
'user_id' => 'required',
|
||||
'autoclave_id' => 'required',
|
||||
'test_type_id' => 'required',
|
||||
'result' => 'required',
|
||||
'verified' => 'required',
|
||||
]);
|
||||
$TestResult->update($request->all());
|
||||
return response()->json(trans('messages.success'));
|
||||
}
|
||||
|
||||
/**
|
||||
* Remove the specified resource from storage.
|
||||
*
|
||||
* @param int $id
|
||||
* @return \Illuminate\Http\Response
|
||||
*/
|
||||
public function destroy($id)
|
||||
{
|
||||
//
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user