Laravel interview questions

https://codingcompiler.com/laravel-interview-questions-answers/

Advertisements

Cartesian algorithm

<?php
error_reporting(0);

if(isset($_POST[“Import”])){

$filename=$_FILES[“file”][“tmp_name”];

if($_FILES[“file”][“size”] > 0)
{

$file = fopen($filename, “r”);

$output .= “<table>”;

while (($getData = fgetcsv($file, 10000, “,”)) !== FALSE)
{
$product_id = $getData[0];
$Accessories = $getData[1];
$Related = $getData[2];
$upc = $getData[3];
$Product_Title = $getData[4];
$Product_category = $getData[5];
$Compare_price = $getData[6];
$Offer_price = $getData[7];
$Commission = $getData[8];
$Wholesale_price = $getData[9];
$Unit_Cost = $getData[10];
$Taxexempt = $getData[11];
$Qty = $getData[12];
$Low_threshhold = $getData[13];
$Warehouse_Location = $getData[14];
$Warehouse_Bin = $getData[15];
$ProductMake = $getData[16];
$ProductModel = $getData[17];
$SummaryDescription = htmlspecialchars($getData[18]);
$DetailedDescription = htmlspecialchars($getData[19]);
$Options = $getData[20];
$Variants = $getData[21];
$Weight = $getData[22];
$Height = $getData[23];
$Length = $getData[24];
$Width = $getData[25];
$img_url = $getData[26];
$Ship_to_customer = $getData[27];
$Pickup_in_store = $getData[28];
$Charge_shipping = $getData[29];
$AccessoriesTabTitle = $getData[30];
$AccessoriesLimit = $getData[31];
$AccessoriesPosition = $getData[32];

$attributesArray1 = explode(“,”, $Variants);
//echo “<pre>attributesArray1:”.print_r($attributesArray1,true).”</pre>”;
if(!empty($attributesArray1)){
foreach($attributesArray1 as $attributes){
$_attributes = str_replace(“\\”, “,”, $attributes);
$attributesArray2[] = explode(“,”, $_attributes);
}
}
//echo “<pre>attributesArray2:”.print_r($attributesArray2,true).”</pre>”;
//echo “<pre>Cartesian product:”.print_r(Cartesian::build($attributesArray2),true).”</pre>”;
foreach(Cartesian::build($attributesArray2) as $a)
{
$price = explode(“|”,implode(‘,’,$a));
$Variants_price = explode(‘,’,$price[1]);

if($Offer_price != ”)
{
$Offer_price = $Offer_price;
}else{
$Offer_price = $Variants_price[0];
}

/*if (strpos($a, ‘|’) != true) {
$b = $a;
}else{
$b = “test”;
} */
$output .= “<tr style=’border:1px solid #000′><td>”.$product_id.”</td><td>”.$Accessories.”</td><td>”.$Related.”</td><td>”.$upc.”</td><td>”.$Product_Title.”</td><td>”.$Product_category.”</td><td>”.$Compare_price.”</td><td>”.$Offer_price.”</td><td>”.$Commission.”</td><td>”.$Wholesale_price.”</td><td>”.$Unit_Cost.”</td><td>”.$Taxexempt.”</td><td>”.$Qty.”</td><td>”.$Low_threshhold.”</td><td>”.$Warehouse_Location.”</td><td>”.$Warehouse_Bin.”</td><td>”.$ProductMake.”</td><td>”.$ProductModel.”</td><td>”.$SummaryDescription.”</td><td>”.$DetailedDescription.”</td><td>”.$Options.”</td><td>”.str_replace(‘+’,’-‘,implode(‘,’,$a)).”</td><td>”.$Weight.”</td><td>”.$Height.”</td><td>”.$Length.”</td><td>”.$Width.”</td><td>”.$img_url.”</td><td>”.$Ship_to_customer.”</td><td>”.$Pickup_in_store.”</td><td>”.$Charge_shipping.”</td><td>”.$AccessoriesTabTitle.”</td><td>”.$AccessoriesLimit.”</td><td>”.$AccessoriesPosition.”</td></tr>”;
$attributesArray2 = ”;
}
}
$output .= ‘</table>’;
header(“Content-Type: application/xls”);
header(“Content-Disposition: attachment; filename=export_excel.xls”);
print $output; exit();
fclose($file);
}
}

class Cartesian
{
public static function build($set)
{
if (!$set) {
return array(array());
}
$subset = array_shift($set);
$cartesianSubset = self::build($set);
foreach ($subset as $value) {
foreach ($cartesianSubset as $p) {
array_unshift($p, $value);
$result[] = $p;
}
}
return $result;
}
}

?>

Interview questions

  1. FIG in php
  2. PSR 1 and PSR 2
  3. array_walk
  4. in_array return values?
  5. innodb vs myisam
  6. hooks in CI
  7. or_where query in CI
  8. can index primary key?
  9. mysql full text search
  10. z-index
  11. position – absolute, relative
  12. display – inline, block
  13. find the no of radio button available on the form using jquery
  14. primary key vs unique key
  15. what is the use of new in class initialize ($a = new classname)
  16. unian and unianall in mysql

Interview questions in Sastha tech,

Get the content onchange event using Jquery Ajax

View file :

———–

function get_org_address(org_name)
{
$.ajax({
type : “POSt”,
url : “<?php echo DOMAIN_URL?>registration/get_organization_address”,
data : ‘org_name=’+org_name,
success : function (res)
{
//alert(res);
//alert(res);
var address = JSON.parse(res);
//alert(address.zip_code);
$(“#address_one”).val(address.address_1);
$(“#address_two”).val(address.address_2);
$(“#city”).val(address.city);
$(“#state”).val(address.state);
$(“#main_ph_no”).val(address.phone_no);
$(“#zip_code”).val(address.zip_code);
//var zip_code = address.zip_code;
//document.getElementById(‘zip_code’).value = zip_code;
}
});
}


Controller File :

——————–

function get_organization_address()
{
$org_name = $this->input->post(‘org_name’);
$this->db->select(‘MAIN_PH_NBR,ADDR_LN_1,ADDR_LN_2,CITY,STATE,ZIP_CODE’);
$this->db->where(‘ORG_ID’,$org_name);
$this->db->from(TBL_ORGANIZATION);
$query = $this->db->get();
if($query->num_rows() > 0)
{
$data = $query->result();
$org_address = array(‘phone_no’ =>$data[0]->MAIN_PH_NBR,
‘address_1’=>$data[0]->ADDR_LN_1,
‘address_2’=>$data[0]->ADDR_LN_2,
‘city’=>$data[0]->CITY,
‘state’=>$data[0]->STATE,
‘zip_code’=>$data[0]->ZIP_CODE);
print json_encode($org_address);
}
//print_r($data);
}

Made the API response to Tripadvisor

$this->load->library(‘gapitripadvisor/gapitripadvisor’);
$endpoint = ‘api/tripadvisor2/search’;
$request_params = array();
$request_params[‘city_id’] = ‘47292’;
$request_params[‘check_in’] = $check_in;
$request_params[‘check_out’] = $check_out;
$request_params[‘search_type’] = ‘city’;
$request_params[‘num_rooms’] = $room_count;
$request_params[‘guests’] = $room_pax_str;
$request_params[‘guests_count’] = $pax;
$request_params[‘base_url’] = BASE_URL;
$request_params[‘domain_id’] = !empty($domain_result->domain_id) ? $domain_result->domain_id : ”;

//echo ‘<pre>’; print_r($request_params);
$response = $this->gapitripadvisor->send_request(‘GET’, $endpoint, $request_params);

 

// headers to tell that result is JSON

header(‘Content-type: application/json’);

//echo $response;

 

$trip = json_decode($response,true);

//print_r($trip);die;

$trip_hotels = $trip[‘results’][‘hotels’];

//print_r($trip_hotels);die;

foreach($trip_hotels as $hotels)

{

//print_r($hotels);die;

$hotel[‘hotel_id’] = $hotels[‘hotel_id’];

$hotel[‘hotel_code’] = $hotels[‘hotel_code’];

$hotel[‘room_type’] = $hotels[‘room_type’];

$hotel[‘name’] = $hotels[‘name’];

$hotel[‘api’] = $hotels[‘api’];

$hotel[‘resort_fee’] = $hotels[‘resort_fee’];

 

$hotel[‘price’][‘price_per_room_per_night’] = $hotels[‘price’][‘price_per_room_per_night’];

$hotel[‘price’][‘tax_percentage’] = $hotels[‘price’][‘tax_percentage’];

$hotel[‘price’][‘sub_total’] = $hotels[‘price’][‘sub_total’];

$hotel[‘price’][‘tax_amount’] = $hotels[‘price’][‘tax_amount’];

$hotel[‘price’][‘total_price’] = $hotels[‘price’][‘total_price’];

$hotel[‘price’][‘currency_code’] = $hotels[‘price’][‘currency_code’];

 

$hotel[‘language’] = $hotels[‘language’];

$hotel[‘url’] = $hotels[‘url’];

$hotel_response = $hotel;

//}

//echo “=====>”.print_r($hotel_response);die;

$trip_result = [

“api_version”=> 8,

“language”=> “en_US”,

“availability_request”=> [

“api_version”=> 8,

“start_date”=> “2017-05-01”,

“end_date”=> “2017-05-03”,

“party”=> [[

“adults”=> 3

],

[

“adults”=> 2,

“children”=> [

9,

5

]

]],

“language”=> “en_US”,

“query_key”=> “6167a22d1f87d2028bf60a8e5e27afa7_191_1360299600000_2_2”,

“currency”=> “USD”,

“user_country”=> “US”,

“device_type”=> “Desktop”,

“availability_id”=> “a2fd740a-ad02-476d-b314-925a125509be”,

“requested_payload”=> [

“categories”=> [

“room_type_details”=> false,

“rate_plan_details”=> false,

“room_rate_details”=> false,

“hotel_details”=> false

],

“category_modifiers”=> [

“partner_booking_data”=> false,

“real_time_pricing”=> false,

“multiple_room_rates”=> false,

“photos”=> false,

“text”=> false

]

],

“hotels”=> [

[

“ta_hotel_id”=> $hotel_response[‘hotel_id’],

“partner_hotel_code”=> $hotel_response[‘hotel_code’]

],

]],

“response_payload”=> [

“categories”=> [

“room_type_details”=> false,

“rate_plan_details”=> false,

“room_rate_details”=> false,

“hotel_details”=> false

],

“category_modifiers”=> [

“partner_booking_data”=> false,

“real_time_pricing”=> false,

“multiple_room_rates”=> false,

“photos”=> false,

“text”=> false

]

],

 

 

“hotels”=> [

“A123″=> [

“response_type”=> “available”,

“available”=> [

“room_types”=> [

“1”=> [

“persistent_room_type_code”=> $hotel_response[‘room_type’]

],

],

“rate_plans”=> [

“1”=> [

“persistent_rate_plan_code”=> “BR21”

],

“2”=> [

“persistent_rate_plan_code”=> “OL44”

]

],

“room_rates”=> [

“1”=> [

“persistent_room_rate_code”=> “21dr-wi4g-aaa9-kg2np”,

“room_type_key”=> “1”,

“rate_plan_key”=> “1”,

“url”=> $hotel_response[‘url’],

“line_items”=> [

[

“price”=> [

“requested_currency_price”=> [

“amount”=> $hotel_response[‘price’][‘total_price’],

“currency”=> $hotel_response[‘price’][‘currency_code’]

]

],

“type”=> $hotel_response[‘price’][‘sub_total’],

“paid_at_checkout”=> false,

], [

“price”=> [

“requested_currency_price”=> [

“amount”=> $hotel_response[‘price’][‘price_per_room_per_night’],

“currency”=> $hotel_response[‘price’][‘currency_code’]

]

],

“type”=> $hotel_response[‘price’][‘tax_amount’],

“sub_type”=> $hotel_response[‘price’][‘tax_percentage’],

“paid_at_checkout”=> false,

]

]

],

]

]

],

“B456″=> [

“response_type”=> “unavailable”

],

“555”=> [

“response_type”=> “error”,

“error”=> [

“error_code”=> 3,

“message”=> “Unknown hotel id was requested.”

]

]

]

 

 

];

echo json_encode($trip_result);

Apache Web Server – Virtual host creation

Hosting the Zend Framework based application in the production environment is very simple and straight-forward. Just create a VirtualHost in the Apache configuration file and point the DocumentRoot to the Public folder of the Zend Framework application.

********C:\Windows\System32\drivers\etc\hosts

Eg :

127.0.0.1 localhost
127.0.0.1 1degreeadmin.vivid
127.0.0.1 1dwgapi.vivid
127.0.0.1 tourbeaver.vivid
127.0.0.1 dctoursus.vivid
127.0.0.1 venus.vivid

108.171.165.58 tourbeaver.com
108.171.165.58 http://www.tourbeaver.com

********D:\xampp\apache\conf\extra\httpd-vhosts

<VirtualHost *:80>
DocumentRoot “D:/xampp/htdocs/”
ServerName localhost
</VirtualHost>

<VirtualHost *:80>
DocumentRoot “D:/xampp/htdocs/1degreeadmin”
ServerName 1degreeadmin.vivid
</VirtualHost>
<VirtualHost *:80>
DocumentRoot “D:/xampp/htdocs/1dwgapi_dev”
ServerName 1dwgapi.vivid
</VirtualHost>

<VirtualHost *:80>
DocumentRoot “D:/xampp/htdocs/tourbeaver_dev”
ServerName tourbeaver.vivid
</VirtualHost>
<VirtualHost *:80>
DocumentRoot “D:/xampp/htdocs/dctoursus.1degreeworld.biz”
ServerName dctoursus.vivid
</VirtualHost>
<VirtualHost *:80>
DocumentRoot “D:/xampp/htdocs/venus_dev”
ServerName venus.vivid
</VirtualHost>

 

A sample configuration (myapp) is given below −

<VirtualHost *:80> 
   ServerName myapp.localhost 
   DocumentRoot /path/to/install/myapp/public 
   <Directory /path/to/install/myapp/public> 
      DirectoryIndex index.php 
      AllowOverride All 
      Order allow,deny 
      Allow from all 
      <IfModule mod_authz_core.c> 
         Require all granted 
      </IfModule> 
   </Directory> 
</VirtualHost>