jeudi 16 février 2023

Argument 1 passed to Jenssegers\Mongodb\Query\Builder::__construct(),of Jenssegers\Mongodb\Connection,Illuminate\Database\MySqlConnection

whenever I want to login my page, this error came, but I added my mongodb database with my project, what's the issue?

I just want login my page with my mongodb database, where i mentioned everything



via Chebli Mohamed

mardi 14 février 2023

Pest package of laravel

The pest package of laravel can push that package on live site what is best practice can i push it or not can anyone help me on that.

I install the pest laravel automation testing package on local setup of automation testing and logical testing can i push that package to live site what are the pros and cons.



via Chebli Mohamed

samedi 11 février 2023

laravel compare from array in controller with if lease condition

I'm trying to compare array getting from two different inputs and compare it in controller if both value same then pass TRUE if Not pass FALSE.

I tried below method but I was getting error and error pointing to below code

 if ($request->ANSWER[$i] === $request->OPTION[$i]) 
          
                {
                 $data->ANSWER_STATUS = "1"; 
                 } else {
                 $data->ANSWER_STATUS = "0"; 
                 } 

Error Code

Trying to access array offset on value of type null

my array pater looks

 "Question" => array:2 [▼
   0 => "html full form"
   1 => "water formula in science"
  ]
  "ANSWER" => array:2 [▼  //COMPARE 
    0 => "Hypertext Markup Language"
    1 => "h2O"
  ]
  "OPTION" => array:2 [▼  //COMPARE 
    0 => "Markup Language"
    1 => "h2O"
  ]

CONTROLLER

    public function Store_Answer(Request $request)
   {
        $Questioncount= $request->Question;
         
         if ($Questioncount) {
         
         for ($i=0; $i <count($request->Question); $i++) {
         $data = New OnlineExminAnswer();
 
             if ($request->ANSWER[$i] === $request->OPTION[$i]) 
              
                    {
                     $data->ANSWER_STATUS = "1"; 
                     } else {
                     $data->ANSWER_STATUS = "0"; 
                     } 
                     
               $data->question = $request->Question [$i];           
        $data->save();
         } 
         } 
 
        return back()->with('success',' Successfully .');
 
   }


via Chebli Mohamed

vendredi 10 février 2023

XMLHttpRequest on Laravel to complete fields based on user input

I have been trying to create an XMLHttpRequest to fetch data on mySQL based on 2 tables, but I can't get it to work properly as the beginner I am, so after a few days I wanna ask you for help

This is how I tried to do this, I'll change a few names as the code belongs to a company, they'll be highlighted with "*":

form

        <div class="col-md-3">
        <div class="position-relative form-group">
            <label class="">*number* - *name*</label>
            <select name="*first input*" id="*first input*" required="required" placeholder="" onchange="GetDetail(this.value)" class="form-control *select class*">
                <option></option>
                @foreach($properties as $prop)
                    <option  value="">  - </option>
                @endforeach
            </select>    
            </select>

this is the XMLHttpRequest function:

function GetDetail(str) {
    if (str.length == 0) {
        document.getElementById("*column1*").value = "";
        document.getElementById("*column2*").value = "";
        document.getElementById("*column3*").value = "";
        document.getElementById("*column4*").value = "";
        document.getElementById("*column5*").value = "";
        document.getElementById("*column6*").value = "";
        document.getElementById("*column7*").value = "";
        document.getElementById("*column8*").value = "";
        document.getElementById("*column9*").value = "";
        document.getElementById("*column10*").value = "";
        return;
    }
    else {

        var xmlhttp = new XMLHttpRequest();
        xmlhttp.onreadystatechange = function () {

            if (this.readyState == 4 && 
                    this.status == 200) {
                        
                var myObj = JSON.parse(this.responseText);

                document.getElementById("*column1*").value = myObj[0];
                document.getElementById("*column2*").value = myObj[1];                 
                document.getElementById("*column3*").value = myObj[2];
                document.getElementById("*column4*").value = myObj[3];
                document.getElementById("*column5*").value = myObj[4];
                document.getElementById("*column6*").value = myObj[5];
                document.getElementById("*column7*").value = myObj[6];
                document.getElementById("*column8*").value = myObj[7];
                document.getElementById("*column9*").value = myObj[8];
                document.getElementById("*column10*").value = myObj[9];    
            }else{
                console.log();("error " + xmlhttp.status);
            }
        };

        xmlhttp.open("GET", "client/for-ajax.blade.php/" +str, true);

        xmlhttp.send();
    }
}

and this is the for-ajax file, which was originally .php, but I tried changing it to .blade.php:

<?php

$prop_id = $_REQUEST['property_id'];
  
$conn = mysqli_connect("localhost", "*user*", "*password*", "d*atabase*");

$property_id = "SELECT `id` FROM `*table1*`";

if ($property_id !== "") {
       
    $query = mysqli_query($conn, "SELECT `*column1*`, `*column2*`, `*column3*`, `*column4*`, `*column5*`, `*column6*`, `*column7*`, `*column8*`, `*column9*`, `*column10*` FROM `*table2*` WHERE property_id='$property_id'");
  
    $row = mysqli_fetch_array($query);
    $*column1* = $row["*column1*"];
    $*column2* = $row["*column2*"];
    $*column3* = $row["*column3*"];
    $*column4* = $row["*column4*"];
    $*column5* = $row["*column5*"];
    $*column6* = $row["*column6*"];
    $*column7* = $row["*column7*"];
    $*column8* = $row["*column8*"];
    $*column9* = $row["*column9*"];
    $*column10* = $row["*column10*"];

}

$result = array("$*column1*", "$*column2*", "$*column3*", "$*column4*", "$*column5*", "$*column6*", "$*column7*", "$*column8*", "$*column9*", "$*column10*");
  
$myJSON = json_encode($result);
echo $myJSON;
?>

At first I was getting a 404, then I created a view for that url "client/for-ajax.blade.php/" and now I get a syntax error on the console:

Uncaught SyntaxError: Unexpected token '<', "<!doctype "... is not valid JSON
    at JSON.parse (<anonymous>)
    at GetDetail.xmlhttp.onreadystatechange


via Chebli Mohamed

laravel controller if else condition for array value

I'm Trying to pass value 1 for if equal value 0 for if not equal in columan ANSWER_STATUS using if and else condition in controller, i was tried two different methods but it was giving error help me to fix this.

ARRYR value

 "Question" => array:2 [▼
    0 => "html full form"
    1 => "water formula in science"
  ]
  "ANSWER" => array:2 [▼  //THIS ARRAY CONTAINING ALL RIGHT ANSWER
    0 => "Hypertext Markup Language"
    1 => "h2O"
  ]
  "OPTION" => array:2 [▼  //THIS ARRAY STUDENTS ANSWER 
    0 => "Markup Language"
    1 => h2O"
  ]
]

my controller method 1

public function Store_Answer(Request $request)
{
    $count = $request->Question;
    if ($count) {
        for ($i = 0; $i < count($request->Question); $i++) {
            $data = new OnlineExminAnswer();
            $data->ANSWER_STATUS = $request->ANSWER[$i] == $request->OPTION[$i] ? 1 : 0;
            $data->question = $request->Question[$i];
            $data->answer = $request->OPTION[$i];
            $data->save();
        }
    }
}

error

Trying to access array offset on value of type null

my controller method 2

 public function Store_Answer(Request $request)
    {
        $count = $request->Question;
        if ($count) {
            for ($i = 0; $i < count($request->Question); $i++) {
                $data = new OnlineExminAnswer();
                     if ($request->ANSWER[$i] == $request->OPTION[$i]) 
                     {
                     $data->ANSWER_STATUS = "1"; 
                     } else {
                     $data->ANSWER_STATUS = "0"; 
                     }  
                $data->question = $request->Question[$i];
                $data->answer = $request->OPTION[$i];
                $data->save();
            }
        }
    }

error

    Trying to access array offset on value of type null


via Chebli Mohamed

jeudi 9 février 2023

syntax error, unexpected token "}" LARAVEL

I got error in my Laravel controller that says syntax error, unexpected token "}", i have checked every line but couldn't identified the error reason.

<?php

namespace App\Http\Controllers;
use Illuminate\Http\Request;
use Dompdf\Dompdf;

class WordController extends Controller
{
    public function importForm()
    {
        return view('import');
    }

    public function importWord(Request $request)
    {
        $file_path = $request->file('word_file')->getRealPath();

        try {
            $word = new COM("Word.Application") or die("Unable to instantiate Word");
            $word->Visible = 0;
            $word->Documents->Open($file_path);
            $content = $word->ActiveDocument->Content->Text;
            $word->Quit();
            $word = null;
            unset($word);
        } catch (Exception $e) {
            return redirect()->back()->with('error', 'An error occurred while importing the Word document');
        }

        $dompdf = new Dompdf();
        $dompdf->loadHtml($content);
        $dompdf->setPaper('A4', 'portrait');
        $dompdf->render();

        return $dompdf->stream();
        }
}


via Chebli Mohamed

mercredi 8 février 2023

laravel 5.1 installation issue with php 7.1 , cannot install carbon 2

  • composer install error on carbon 1 is deprecated SO, how can i run my vagrant with laravel 5.1 with carbon 1 and I have try find from stackoverflow and other site but no helps comes up . every thing is done but shows carbon 1 is deprecated


via Chebli Mohamed