0

I have two request sample and incomplete sample, I get the complete sample by submitting the form without ticking any checkbox, then get incomplete samples by clicking the checkbox.

I can get incomplete samples by ticking the checkbox. I get the error while getting the complete samples.

if(!in_array($sample, $request->pending)){
    $tests = Session('tests');
    $createSample = Sample::create([
        'test_user_id' => $request->test_user_id,
        'received_by' => (integer)$request->received_by,
        'received_at' => $now,
        'received_name' => $request->received_name,
        'biobank' => $request->biobank,
        'order_id' => $request->order_id,
        'order_type' => $request->order_type,
        'name' => $request->name,
    ]);
2
  • first, check if you have pending value in your request Commented Aug 8, 2019 at 14:00
  • there are none, but i need to skip the error and add the value for sample Commented Aug 8, 2019 at 14:26

1 Answer 1

2

Its because if you don't check the checkbox, the value won't submit and hence the $request->pending will be null instead of an array. You can try to check if its null and then you can do whatever you want to do with it.

if($request->pending){
    if(!in_array($sample, $request->pending)){
        $tests = Session('tests');
        $createSample = Sample::create([
                        'test_user_id' => $request->test_user_id,
                        'received_by' => (integer)$request->received_by,
                        'received_at' => $now,
                        'received_name' => $request->received_name,
                        'biobank' => $request->biobank,
                        'order_id' => $request->order_id,
                        'order_type' => $request->order_type,
                        'name' => $request->name,
        ]);
     }
}
Sign up to request clarification or add additional context in comments.

2 Comments

yes, how can i still save the request even tho the request doesnt contain pending
then why are you using the if condition? just remove it.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.