Why do you think this code is weird?

|
cintya_nainggolan 2022-08-02 15:47:13
okay wait
cintya_nainggolan 2022-08-02 15:50:21
this is the code
e_yavgel 2022-08-02 16:02:22
maybe remove return->back(); (before insert) ))
linux9921 2022-08-02 16:02:27
Where do these variables come from? (int)$all_w.q_ggn_target_real, (int)$all_w.q_ggn_real , etc
linux9921 2022-08-02 16:04:04
of request?
cintya_nainggolan 2022-08-02 16:04:11
the variables come from the attributes in the tables in the database
cintya_nainggolan 2022-08-02 16:04:36
ok i will try
linux9921 2022-08-02 16:04:41
But that’s the first thing to do
linux9921 2022-08-02 16:05:13
Otherwise the rest of the code cannot be executed.
cintya_nainggolan 2022-08-02 16:08:07
But I’ve migrated and created the model, is it still not executable?
didaputraad 2022-08-02 16:08:25
Did execute ?
cintya_nainggolan 2022-08-02 16:13:23
sorry?
didaputraad 2022-08-02 16:13:57
Checking table migration in database
linux9921 2022-08-02 16:14:12
What I advise you to do is rewrite the logic of everything inside the insert[
];
I didn’t manage to understand this piece of code to adapt it to your needs… but if one of us brings you a solution, I’d be curious to see.
linux9921 2022-08-02 16:14:56
Did you understand the logic of what is in insert in its method?
didaputraad 2022-08-02 16:15:20
I think it’s a executable
didaputraad 2022-08-02 16:15:53
If tabel is migration then this it not execute
cintya_nainggolan 2022-08-02 16:22:02
The problem is that I don’t know how to make the correct logic 😭
didaputraad 2022-08-02 16:25:39
What is your problems
cintya_nainggolan 2022-08-02 16:26:29
this
cintya_nainggolan 2022-08-02 16:26:45
My logic still like this
didaputraad 2022-08-02 16:28:06
Create data ?
cintya_nainggolan 2022-08-02 16:32:15
No, so the data I want to include is data that already exists from the import which is managed in the if else condition
e_yavgel 2022-08-02 16:34:48
public function importallw(Request $request)
{
$this->validate($request, [
‘file’ => ‘required|mimes:csv,xls,xlsx’
]);

$file = $request->file(‘file’);
$nama_file = rand().$file->getClientOriginalName();
$file->move(‘file_all_w’,$nama_file);
Excel::import(new AllwImport, public_path(‘/file_all_w/’.$nama_file));

$q_ggn_score = $request->if(int(‘all_w.q_ggn_target_real’) / int(‘all_w.q_ggn_real’) > 1.05)
? int(‘all_w.q_ggn_score’) == int(‘all_w.q_ggn_bobot’) * 1.05
: int(‘all_w.q_ggn_score’) == (int(‘all_w.q_ggn_target_real’)) / (int(‘all_w.q_ggn_real’)) * (int(‘all_w.q_ggn_bobot’))
;

$sugar_score = $request->if(int(‘all_w.sugar_target_real’) / int(‘all_w.sugar_real’) > 1.05)
? int(‘all_w.sugar_score’) == int(‘all_w.sugar_bobot’) * 1.05
: int(‘all_w.sugar_score’) == (int(‘all_w.sugar_target_real’)) / (int(‘all_w.sugar_real’)) * (int(‘all_w.sugar_bobot’))
;

DB::table(‘all_w’)->insert([
‘q_ggn_score’ => $q_ggn_score, // it will be bool (true or false) is it right?
‘sugar_score’ => $sugar_score, // it will be bool (true or false) is it right?
]);

return back();
}

linux9921 2022-08-02 16:38:14
You can first retrieve the data that is in the separate database and insert them but with your condition in request it’s a bit weird I think
linux9921 2022-08-02 16:38:45
the problem I think is this condition in request
linux9921 2022-08-02 16:39:13
$q_ggn_score = $request->if(int(‘all_w.q_ggn_target_real’) / int(‘all_w.q_ggn_real’) > 1.05) 👆
cintya_nainggolan 2022-08-02 16:39:46
did you fix this?
linux9921 2022-08-02 16:40:32
request is composed of key value… i don’t believe this if can work
cintya_nainggolan 2022-08-02 16:40:46
Why do you think this code is weird?
e_yavgel 2022-08-02 16:41:00
a little bit … it is only start ))
cintya_nainggolan 2022-08-02 16:41:35
Ok I’ll try to execute
linux9921 2022-08-02 16:41:52
Because of this if before request. this will have to be reviewed
linux9921 2022-08-02 16:43:00
Let us know the rest, I’m seriously curious to know if it works
cintya_nainggolan 2022-08-02 16:48:25
laravel_discuss-131844.jpg
there is an error like this
|