Hi i have an RESTfulAPI that return a JSON object like this:
{
data: [
{
id: 4,
name: "Naranja",
cant_portion: 2,
portion_name: "Piezas",
foodgroup_name: "Frutas"
}
]
}
and i want to rearrange it so i can have something like this:
{
data: [
{
foodgroup_name: "Frutas",
items:[
{
portion_name: "Piezas",
items:[
{
id: 4,
name: "Naranja",
cant_portion: 2,
}
]
}
]
}
]
}
the idea of doing this is that i want to have a nested ul and the first ul should give me the name of the foodgroup, then the next ul should give the type of portions that foodgroup has, and inside that ul to put some li, with the items that match those 2 requirements.
Now in my API i can return the name of each Food group, so i'm ok with that first ul but in the second one where the portions goes, not every foodgroup has all of the portions, just maybe 1 or 2.
Check it:
private function _rearrangeData($data = array())
{
$out = array();
if (!count($data)) {
return $data;
}
$foodgroup = array();
$portion = array();
$foodgroup_name = $data[0]['foodgroup_name'];
$portion_name = $data[0]['portion_name'];
foreach ($data as $item) {
if ($item['foodgroup_name'] == $foodgroup_name) {
if ($item['portion_name'] == $portion_name) {
unset($item['foodgroup_name']);
unset($item['portion_name']);
array_push($portion, $item);
} else {
$arr = [
'portion_name' => $portion_name,
'items' => $portion
];
$portion_name = $item['portion_name'];
unset($item['foodgroup_name']);
unset($item['portion_name']);
$portion = [$item];
array_push($foodgroup, $arr);
}
} else {
$arr = [
'portion_name' => $portion_name,
'items' => $portion
];
array_push($foodgroup, $arr);
$arr = [
'foodgroup_name' => $foodgroup_name,
'items' => $foodgroup
];
$foodgroup_name = $item['foodgroup_name'];
$portion_name = $item['portion_name'];
unset($item['foodgroup_name']);
unset($item['portion_name']);
$portion = [$item];
$foodgroup = [];
array_push($out, $arr);
}
}
$arr = [
'portion_name' => $portion_name,
'items' => $portion
];
array_push($foodgroup, $arr);
$arr = [
'foodgroup_name' => $foodgroup_name,
'items' => $foodgroup
];
array_push($out, $arr);
return $out;
}
Edit: with your db:
$food_group = DB::table('foods')->join('food_group', 'food_group.id', '=', 'foods.food_group_id')->groupBy('food_group_id')->get();
$out = [];
foreach ($food_group as $item) {
$foods = DB::table('foods')->join('portions', 'portions.id', '=', 'foods.portion_id')->where('food_group_id', $item->id)->groupBy('portion_id')->get();
$arr1 = [];
foreach($foods as $item2) {
$por_food = DB::table('foods')->where('food_group_id',$item->id)->where('portion_id',$item2->id)->get();
$arr = [
'portion_name' => $item2->name,
'items' => $por_food
];
array_push($arr1, $arr);
}
$arr2 = [
'foodgroup_name'=>$item->name,
'items'=>$arr1
];
array_push($out, $arr2);
}
return response()->json(['data'=>$out],200);
Related
I am doing a project with Laravel 7. I have to read a csv file and through a controller passing the data in json format to a view.
Unfortunately I don't know how to do that.
These are my controller methods:
public function index($source)
{
$source = strtolower($source);
switch ($source) {
case "csv":
$file_csv = base_path('transactions.csv');
$transactions = $this->csvToJson($file_csv);
dd(gettype($transactions));
return view('transactions', ['source' => $source, 'transactions' => $transactions]);
break;
case "db":
$transactions = Transaction::all();
dd(gettype($transactions));
return view('transactions', ['source' => $source, 'transactions' => $transactions]);
break;
default:
abort(400, 'Bad sintax error.');
}
}
function csvToJson($filename = '', $delimiter = ',')
{
if (!file_exists($filename) || !is_readable($filename)) {
return false;
}
$header = null;
$data = array();
if (($handle = fopen($filename, 'r')) !== false)
{
while (($row = fgetcsv($handle, 1000, $delimiter)) !== false)
{
if (!$header)
$header = $row;
else
$data[] = array_combine($header, $row);
}
fclose($handle);
}
return $data;
}
As you can see, under the two cases I put a dd with a gettype function inside. In the first case I receive uncorrectly the response array, in the second one I receive correctly the response object.
The converted csv file should have this format:
[{"id":1,"code":"T_218_ljydmgebx","amount":"8617.19","user_id":375,"created_at":"2020-01-19T16:08:59.000000Z","updated_at":"2020-01-19T16:08:59.000000Z"},
{"id":2,"code":"T_335_wmhrbjxld","amount":"6502.72","user_id":1847,"created_at":"2020-01-19T16:08:59.000000Z","updated_at":"2020-01-19T16:08:59.000000Z"}]
Do you know how to convert the array transactions into a json object in the first case?
I don't know if there is any build-in solution on Laravel, but it can be done by PHP.
I didn't test my code. So it might not work, or contain some typos, but I'm sure it will give you some directions.
$cols = ["id","code","amount","user_id","created_at","updated_at"];
$csv = file('folder/name.csv');
$output = [];
foreach ($csv as $line_index => $line) {
if ($line_index > 0) { // I assume the the first line contains the column names.
$newLine = [];
$values = explode(',', $line);
foreach ($values as $col_index => $value) {
$newLine[$cols[$col_index]] = $value;
}
$output[] = $newLine;
}
}
$json_output = json_encode($output);
You can just do this :
$csv= file_get_contents($file);
$array = array_map('str_getcsv', explode(PHP_EOL, $csv));
$json json_encode($array);
If you want to return json object
return $json;
If you want to create a .json file
// Pure PHP
$file = fopen('results.json', 'w');
fwrite($file, $json);
fclose($file);
// Laravel using Storage
Storage::disk('local')->put('public/result.json', $json);
I hope this helps somone.
I have an email marketing application where I made bulk importers. So here is their CSV TO JSON code.
function convert_csv_to_json($csv_data){
// CSV to JSON process 1
$context = array(
'http'=>array(
'follow_location' => false,
'max_redirects' => 1000000
)
);
$context = stream_context_create($context);
if (($handle = fopen($csv_data, "r", false, $context)) !== FALSE) {
$csvs = [];
while(! feof($handle)) {
$csvs[] = fgetcsv($handle);
}
$datas = [];
$column_names = [];
foreach ($csvs[0] as $single_csv) {
$column_names[] = $single_csv;
}
foreach ($csvs as $key => $csv) {
if ($key === 0) {
continue;
}
foreach ($column_names as $column_key => $column_name) {
$datas[$key-1][$column_name] = $csv[$column_key];
}
}
return $json = json_encode($datas);
}
// OR
// CSV to JSON process 1
$cols = ['id',
'owner_id',
'name',
'email',
'country_code',
'phone',
'favourites',
'blocked',
'trashed',
'is_subscribed',
'deleted_at',
'created_at',
'updated_at.'];
$csv = file($csv_data);
$output = [];
foreach ($csv as $line_index => $line) {
if ($line_index > 0) { // I assume the the first line contains the column names.
$newLine = [];
$values = explode(',', $line);
foreach ($values as $col_index => $value) {
$newLine[$cols[$col_index]] = $value;
}
$output[] = $newLine;
}
}
return $json_output = json_encode($output);
}
I am creating one API. In that I want to show buyers info, urls for their files/ images, and count in response. I have 3 tables buyers(PK: buyers_id), filedocs(FK: buyers_id), give_credit_transaction_master(FK: buyers_id). In those tables common column is buyers_id.
CODE
public function index()
{
$filedocsObj = FileDoc::with(['relBuyers'])->where('is_active','1')->get();
//return $filedocsCount;
$info = [];
// $profile_urls=[];
// $aadhar_urls=[];
// $pan_urls=[];
// $transaction_count=[];
// $info = array();
for($i = 0; $i < count($filedocsObj); $i++){
$buyer = FileDoc::Join('buyers', 'file_docs.buyers_id', '=', 'buyers.buyers_id')
->where('file_docs.buyers_id',$filedocsObj[$i]->buyers_id)
->select(
'buyers.buyers_id',
'buyers.buyers_name',
'buyers.buyers_address',
'buyers.buyers_contact_number',
'buyers.buyers_aadhar_number',
'buyers.buyers_pan_number',
'file_docs.buyers_profile_image',
'file_docs.buyers_aadhar_file',
'file_docs.buyers_pan_file',
)
->first();
// $info = $buyer->toArray();
array_push($info, [
'info' => $buyer
]);
// $info[] = $buyer;
$existProfile = Storage::disk('local')->exists('public/uploads/profile_images/'.$filedocsObj[$i]->buyers_profile_image);
if (isset($filedocsObj[$i]->buyers_profile_image) && $existProfile) {
// $profile_urls[$i] = Storage::disk('public')->url('/uploads/profile_images/'.$filedocsObj[$i]->buyers_profile_image);
array_push($info, [
'profile_url' => Storage::disk('public')->url('/uploads/profile_images/'.$filedocsObj[$i]->buyers_profile_image)
]);
//$info[] = Storage::disk('public')->url('/uploads/profile_images/'.$filedocsObj[$i]->buyers_profile_image);
}
else
{
// $profile_urls[$i]="";
array_push($info, [
'profile_url' => ''
]);
// $info[] = "";
}
$existAadhar = Storage::disk('local')->exists('public/uploads/aadhar_files/'.$filedocsObj[$i]->buyers_aadhar_file);
if (isset($filedocsObj[$i]->buyers_aadhar_file) && $existAadhar) {
//$aadhar_urls[$i] = Storage::disk('public')->url('/uploads/aadhar_files/'.$filedocsObj[$i]->buyers_aadhar_file);
array_push($info, [
'aadhar_url' => Storage::disk('public')->url('/uploads/aadhar_files/'.$filedocsObj[$i]->buyers_aadhar_file)
]);
// $info[] = Storage::disk('public')->url('/uploads/aadhar_files/'.$filedocsObj[$i]->buyers_aadhar_file);
}
$existPan = Storage::disk('local')->exists('public/uploads/pan_files/'.$filedocsObj[$i]->buyers_pan_file);
if (isset($filedocsObj[$i]->buyers_pan_file) && $existPan) {
//$pan_urls[$i] = Storage::disk('public')->url('/uploads/pan_files/'.$filedocsObj[$i]->buyers_pan_file);
array_push($info, [
'pan_url' => Storage::disk('public')->url('/uploads/pan_files/'.$filedocsObj[$i]->buyers_pan_file)
]);
//$info[] = Storage::disk('public')->url('/uploads/pan_files/'.$filedocsObj[$i]->buyers_pan_file);
}
$buyerTransactions = GiveCreditTransactionMaster::where('buyers_id',$filedocsObj[$i]->buyers_id)->get();
array_push($info, [
'transaction_count' => count($buyerTransactions)
]);
// $transaction_count[$i] = count($buyerTransactions);
// $resultSet = array_merge($info,$profile_urls,$aadhar_urls,$pan_urls,$transaction_count);
}
return $this->sendResponse($info, 'Buyers retrieved successfully.');
// return $this->sendResponse($resultSet, 'Buyers retrieved successfully.');
// return $this->sendResponse(array("Info" => $filedocs->toArray(),"profile_path" => $profile_urls, "aadhar_urls" => $aadhar_urls, "pan_urls" => $pan_urls, "transactionCountArray" => $transactionCountArray), 'Buyers retrieved successfully.');
}
In above code, I have taken one array info in which I am pushing query result buyer , iteration result profile_url, aadhar_url, pan_url, and another query result counts transaction_count. And returning info array as response.
MY API response:
{
"success": true,
"data": [
{
"info": {
"buyers_id": 2,
"buyers_name": "uuu",
"buyers_address": "dfgfgf",
"buyers_contact_number": "8986665576",
"buyers_aadhar_number": "654654654545",
"buyers_pan_number": "tytyr43242",
"buyers_profile_image": "2_B_profile_lady_profile.png",
"buyers_aadhar_file": "2_B_aadhar_aadhar_card_image.png",
"buyers_pan_file": "2_B_pan_pan_image.jpg"
}
},
{
"profile_url": "http://localhost/storage/uploads/profile_images/2_B_profile_lady_profile.png"
},
{
"aadhar_url": "http://localhost/storage/uploads/aadhar_files/2_B_aadhar_aadhar_card_image.png"
},
{
"pan_url": "http://localhost/storage/uploads/pan_files/2_B_pan_pan_image.jpg"
},
{
"transaction_count": 2
},
{
"info": {
"buyers_id": 28,
"buyers_name": "lili",
"buyers_address": "hjkhkdfgf",
"buyers_contact_number": "7856564656",
"buyers_aadhar_number": "343435353545",
"buyers_pan_number": "trtre34343",
"buyers_profile_image": "28_B_profile_test_profile.png",
"buyers_aadhar_file": "28_B_aadhar_test_aadhar.jpg",
"buyers_pan_file": "28_B_pan_test_pan.jpg"
}
},
{
"profile_url": "http://localhost/storage/uploads/profile_images/28_B_profile_test_profile.png"
},
{
"aadhar_url": "http://localhost/storage/uploads/aadhar_files/28_B_aadhar_test_aadhar.jpg"
},
{
"pan_url": "http://localhost/storage/uploads/pan_files/28_B_pan_test_pan.jpg"
},
{
"transaction_count": 0
}
],
"message": "Buyers retrieved successfully."
}
But in above response I am getting info of particular buyer separately than profile_url, aadhar_url, pan_url, transaction_count. Also profile_url, aadhar_url, pan_url, transaction_count this are getting separately.
I want all parameters(info,profile_url, aadhar_url, pan_url, transaction_count) of one buyer should come in one {}. How can I get that type of response?
I tried a lot using array_push, array_merge etc. But not getting requied response.
Please help. Thanks in advance.
This will help you with your desired response. I have manged your function. make it try and let me know if it helps you thanks
public
function index()
{
$filedocsObj = FileDoc::with(['relBuyers'])->where('is_active', '1')->get();
//return $filedocsCount;
$info = [];
// $profile_urls=[];
// $aadhar_urls=[];
// $pan_urls=[];
// $transaction_count=[];
// $info = array();
foreach ($filedocsObj as $index => $filedocsObjInfo) {
$buyer = FileDoc::Join('buyers', 'file_docs.buyers_id', '=', 'buyers.buyers_id')
->where('file_docs.buyers_id', $filedocsObjInfo->buyers_id)
->select(
'buyers.buyers_id',
'buyers.buyers_name',
'buyers.buyers_address',
'buyers.buyers_contact_number',
'buyers.buyers_aadhar_number',
'buyers.buyers_pan_number',
'file_docs.buyers_profile_image',
'file_docs.buyers_aadhar_file',
'file_docs.buyers_pan_file',
)
->first();
// $info = $buyer->toArray();
$info[$index]['info'] = $buyer;
// $info[] = $buyer;
$existProfile = Storage::disk('local')->exists('public/uploads/profile_images/' . $filedocsObjInfo->buyers_profile_image);
if (isset($filedocsObjInfo->buyers_profile_image) && $existProfile) {
$info[$index]['profile_url'] = Storage::disk('public')->url('/uploads/profile_images/' . $filedocsObjInfo->buyers_profile_image);
} else {
$info[$index]['profile_url'] = '';
}
$existAadhar = Storage::disk('local')->exists('public/uploads/aadhar_files/' . $filedocsObjInfo->buyers_aadhar_file);
if (isset($filedocsObjInfo->buyers_aadhar_file) && $existAadhar) {
$info[$index]['aadhar_url'] = Storage::disk('public')->url('/uploads/aadhar_files/' . $filedocsObjInfo->buyers_aadhar_file);
}
$existPan = Storage::disk('local')->exists('public/uploads/pan_files/' . $filedocsObjInfo->buyers_pan_file);
if (isset($filedocsObjInfo->buyers_pan_file) && $existPan) {
$info[$index]['pan_url'] = Storage::disk('public')->url('/uploads/pan_files/' . $filedocsObjInfo->buyers_pan_file);
}
$buyerTransactions = GiveCreditTransactionMaster::where('buyers_id', $filedocsObjInfo->buyers_id)->get();
$info[$index]['transaction_count'] = count($buyerTransactions);
// $transaction_count[$i] = count($buyerTransactions);
// $resultSet = array_merge($info,$profile_urls,$aadhar_urls,$pan_urls,$transaction_count);
}
return $this->sendResponse($info, 'Buyers retrieved successfully.');
// return $this->sendResponse($resultSet, 'Buyers retrieved successfully.');
// return $this->sendResponse(array("Info" => $filedocs->toArray(),"profile_path" => $profile_urls, "aadhar_urls" => $aadhar_urls, "pan_urls" => $pan_urls, "transactionCountArray" => $transactionCountArray), 'Buyers retrieved successfully.');
}
on PHP the following solution might work.
json_encode(array_merge(json_decode($a, true),json_decode($b, true)))
Try and let me know.
When you use an array_merge try json_decode your value like above.
How can i insert data into two MySql tables on a single click ?
model code
public function insertCSV($data)
{
$this->db->insert('question_tb', $data);
$this->db->insert('option_tb', $data);
return TRUE;
}
controller code
public function import(){
if (isset($_POST["import"])) {
$this->load->model('Welcome_model', 'welcome');
$exam_id = $this->welcome->get_max_exam_id();
$filename = $_FILES["file"]["tmp_name"];
if ($_FILES["file"]["size"] > 0) {
$file = fopen($filename, "r");
while (($importdata = fgetcsv($file, 10000, ",")) !== false) {
$data = [
'question' => $importdata[0],
'answer' => $importdata[1],
'exam_id' => $exam_id,
];
while (($importdata = fgetcsv($file, 10000, ",")) !== false) {
$data = [
'option1' => $importdata[2],
'option2' => $importdata[3],
'option3' => $importdata[4],
'exam_id' => $exam_id,
];
$insert = $this->welcome->insertCSV($data);
}
//fclose($file);
fclose($file);
redirect('upload/index');
}
}
}
}
There are two options
Create two functions in the model and call those function in the controller.
Model:
function a($data1){
$this->db->insert('table1', $data1);
}
function b($data2){
$this->db->insert('table2', $data2);
}
Controller :
function insert(){
$this->model_name->a($data1);
$this->model_name->b($data2);
}
Create a function in the model and pass two array data
Model:
function a($data1, $data2){
$this->db->insert('table1', $data1);
$this->db->insert('table2', $data2);
}
Controller:
function insert(){
$this->model_name->a($data1, $data2);
}
Using Laravel5.1 ...
I'm trying to convert this JSON:
"[{"John Doe":"john.gmail.com"},{"Frank Smith":"frank#frank.com"},{"Jie Brent":"jie#gmail.com"},{"Jeffrey Manney":"jeff17#gmail.com"}]"
To this:
"[{"name":"John Doe", "email":"john.gmail.com"},{"name":"Frank Smith", "email":"frank#frank.com"},{"name":"Jie Brent", "email":"jie#gmail.com"},{"name":"Jeffrey Manney", "email":"jeff17#gmail.com"}]"
This is my code:
$users_storage = [];
foreach($rcf_and_rcfm_users as $key => $user){
$users_storage[][$key] = $user;
}
$users = json_encode($users_storage);
dd($users);
The $rcf_and_rcfm_users variable is a collection of users from the database.
If I understand it correctly.
$users_storage = [];
foreach($rcf_and_rcfm_users as $name => $email){
$users_storage[] = [
'name' => $name,
'email' => $email,
];
}
$users = json_encode($users_storage);
dd($users);
I think this is what you're trying to accomplish.
I am working on Yii2. I have developed an API which will save the incoming records from the client. A client can send an image so I am saving its name and then uploading in the folder. Along with the name of the image I am also sending data with it. All the data except the image name are saved. Below is my API call.
public function actionAddnew()
{
$fp = fopen('preinstall.txt', 'w+');
fwrite($fp, file_get_contents('php://input'));
fclose($fp);
$inputs = json_decode(file_get_contents('php://input'));
return PreInstallations::saveAll($inputs);
}
The function saveAll is
public static function saveAll($inputs)
{
$coutner = 0;
$arr_status = [];
foreach ($inputs as $input) {
$s = new PreInstallations;
foreach ((array)$input as $key => $value) {
if ($key != 'image_names') {
if ($s->hasAttribute($key)) {
$s->$key = $value;
}
}
}
$user = Yii::$app->user;
if (isset($input->auth_key) && Users::find()->where(['auth_key' => $input->auth_key])->exists()) {
$user = Users::find()->where(['auth_key' => $input->auth_key])->one();
}
$s->created_by = $user->id;
if (PreInstallations::find()->where(['ref_no' => $input->ref_no])->exists()) {
$arr_status[] = ['install_id' => $input->install_id, 'status' => 2, 'messages' => "Ref # Already exists"];
continue;
}
$s->sync_date = date('Y-m-d H:i:sāā');
if ($s->save()) {
if ($s->pre_install_status == 'Pre Installed') {
Meters::change_status_byinstall($s->meter_msn, Meters::$status_titles[8]);
}
$arr_status[] = ['install_id' => $input->install_id, 'status' => 1];
$coutner++;
if (isset($input->site_images_name)) {
foreach ($input->site_images_name as $img) {
$image2 = new PreInstallationImagesSite;
$image2->image_name = $img->image_name;
$image2->pre_install_id = $s->id;
$image2->save();
}
}
}
else {
$arr_status[] = ['install_id' => $input->install_id, 'status' => 0, 'messages' => $s->errors];
}
}
return ['status' => 'OK', 'details' => $arr_status, 'records_saved' => $coutner];
}
Below part of above code saves the images name
if (isset($input->site_images_name)) {
foreach ($input->site_images_name as $img) {
$image2 = new PreInstallationImagesSite;
$image2->image_name = $img->image_name;
$image2->pre_install_id = $s->id;
$image2->save();
}
}
For testing purpose API call is made from POSTMAN with below details
[{
"ref_no": "20371521444700U",
"meter_msn" :"002999001189",
"billing_msn" : "74516" ,
"latitude": "36.2703169",
"longitude": "78.178266",
"tarrif": "07",
"s_load": "07",
"customer_id" :"37010673625",
"pre_install_status": "Pre Installed",
"site_issues" : "No issue",
"install_id" : "20371521444700U_1521263491",
"created_date": "2018-03-17 10:12:12",
"consumer_name": "HDA PUMPING STATION SEVERAGE UNO.8 LATIFABAD HYD",
"consumer_address" :"HDA PUMPING STATION SEVERAGE UNO.8 LATIFABAD HYD",
"auth_key": "key",// replaced the original auth key with key
"ct_ratio": "200/5",
"ct_ratio_quantity":"4",
"cable_type":"37/83",
"cable_length":"11",
"atb_installed": "Yes",
"meter_type":"L.T.TOU",
"site_images_name":["20371521444700U_1522299780_site_1.jpg"]
}]
When I Send the request I am getting an error
{
"name": "PHP Notice",
"message": "Trying to get property of non-object",
"code": 8,
"type": "yii\\base\\ErrorException",
"file": "E:\\xampp\\htdocs\\inventory-web\\common\\models\\PreInstallations.php",
"line": 137,
"stack-trace": [
"#0 E:\\xampp\\htdocs\\inventory-web\\common\\models\\PreInstallations.php(137): yii\\base\\ErrorHandler->handleError(8, 'Trying to get p...', 'E:\\\\xampp\\\\htdocs...', 137, Array)",
"#1 E:\\xampp\\htdocs\\inventory-web\\api\\modules\\v1\\controllers\\PreinstallationController.php(36): common\\models\\PreInstallations::saveAll(Array)",
"#2 [internal function]: api\\modules\\v1\\controllers\\PreinstallationController->actionAddnew()",
"#3 E:\\xampp\\htdocs\\inventory-web\\vendor\\yiisoft\\yii2\\base\\InlineAction.php(57): call_user_func_array(Array, Array)",
"#4 E:\\xampp\\htdocs\\inventory-web\\vendor\\yiisoft\\yii2\\base\\Controller.php(156): yii\\base\\InlineAction->runWithParams(Array)",
"#5 E:\\xampp\\htdocs\\inventory-web\\vendor\\yiisoft\\yii2\\base\\Module.php(523): yii\\base\\Controller->runAction('addnew', Array)",
"#6 E:\\xampp\\htdocs\\inventory-web\\vendor\\yiisoft\\yii2\\web\\Application.php(102): yii\\base\\Module->runAction('v1/preinstallat...', Array)",
"#7 E:\\xampp\\htdocs\\inventory-web\\vendor\\yiisoft\\yii2\\base\\Application.php(380): yii\\web\\Application->handleRequest(Object(yii\\web\\Request))",
"#8 E:\\xampp\\htdocs\\inventory-web\\api\\web\\index.php(35): yii\\base\\Application->run()",
"#9 {main}"
]
}
The line 137 is $image2->image_name = $img->image_name;.
The Image model is
public function rules()
{
return [
[['pre_install_id'], 'required'],
[['pre_install_id', 'image_upload_flag'], 'integer'],
[['image_name'], 'string', 'max' => 255],
[['pre_install_id'], 'exist', 'skipOnError' => true, 'targetClass' => PreInstallations::className(), 'targetAttribute' => ['pre_install_id' => 'id']],
];
}
/**
* #inheritdoc
*/
public function attributeLabels()
{
return [
'id' => 'ID',
'pre_install_id' => 'Pre Install ID',
'image_name' => 'Image Name',
'image_upload_flag' => 'Image Upload Flag',
];
}
I must be missing something that I don't know. Any help would be highly appreciated.