php - Laravel:- Calling Functions in Controllers to View -


i new laravel , not sure how use it. have profilecontroller.php have codes , added 1 more piece of code fetch record. want record displayed on profile.blade.php inside particular , not able figure out. need guidelines on how this. please find code bellow:-

profilecontroller.php

    public function showtimings() {          $con = mysql_connect('localhost','****','****');                 mysql_select_db('lblue_db',$con);          if (!function_exists("getsqlvaluestring")) { function getsqlvaluestring($thevalue, $thetype, $thedefinedvalue = "", $thenotdefinedvalue = "")  {   if (php_version < 6) {     $thevalue = get_magic_quotes_gpc() ? stripslashes($thevalue) : $thevalue;   }    $thevalue = function_exists("mysql_real_escape_string") ? mysql_real_escape_string($thevalue) : mysql_escape_string($thevalue);    switch ($thetype) {     case "text":       $thevalue = ($thevalue != "") ? "'" . $thevalue . "'" : "null";       break;         case "long":     case "int":       $thevalue = ($thevalue != "") ? intval($thevalue) : "null";       break;     case "double":       $thevalue = ($thevalue != "") ? doubleval($thevalue) : "null";       break;     case "date":       $thevalue = ($thevalue != "") ? "'" . $thevalue . "'" : "null";       break;     case "defined":       $thevalue = ($thevalue != "") ? $thedefinedvalue : $thenotdefinedvalue;       break;   }   return $thevalue; } }  $colname_detailrs1 = "-1"; if (isset($_get['recordid'])) {   $colname_detailrs1 = $_get['recordid']; } mysql_select_db($database_seo, $seo); $query_detailrs1 = sprintf("select business.id , business.created_at , business.updated_at , business.deleted_at , business.business_name ,address.phone_fixed,  address.street_no , address.street_name, suburb.name 'suburb', address.postcode  ,  address.phone_mobile, business.email , business.active , business.weburl , business.facebook_url , business.googleplus_url , business.twitter_url , business.youtube_url , business.ad_size , business.bold_listing , business.start_date , business.category_id  , category.name , business.region , business.file_location , business.client_id , business.offer_text , business.contract_id, seo_keywordsdesc.businessid, seo_keywordsdesc.keywords, seo_keywordsdesc.desc, seo_keywordsdesc.mono, seo_keywordsdesc.tueo, seo_keywordsdesc.wedo, seo_keywordsdesc.thuro, seo_keywordsdesc.frio, seo_keywordsdesc.sato, seo_keywordsdesc.suno, seo_keywordsdesc.monc, seo_keywordsdesc.tuec, seo_keywordsdesc.wedc, seo_keywordsdesc.thurc, seo_keywordsdesc.fric, seo_keywordsdesc.satc, seo_keywordsdesc.sunc, seo_keywordsdesc.pho, seo_keywordsdesc.phc, seo_keywordsdesc.pubclosed, seo_keywordsdesc.alwaysopen, seo_keywordsdesc.keywords    ,seo_keywordsdesc.desc business left join category on business.category_id = category.id left join address on business.id= address.business_id left join seo_keywordsdesc on business.id= seo_keywordsdesc.businessid left join suburb on  address.suburb_id = suburb.id business.id = %s", getsqlvaluestring($colname_detailrs1, "int")); $detailrs1 = mysql_query($query_detailrs1, $seo) or die(mysql_error()); $row_detailrs1 = mysql_fetch_assoc($detailrs1); $totalrows_detailrs1 = mysql_num_rows($detailrs1); $count = mysql_num_rows($detailrs1); if($count == 0){     $output = 'the store open 24 hours'; }else{          $id = $row_detailrs1['id'];         $businessname = $row_detailrs1['business_name'];         $fixedphone = $row_detailrs1['phone_fixed'];         $fixedmobile = $row_detailrs1['phone_mobile'];         $active = $row_detailrs1['active']; ;          $adsize = $row_detailrs1['ad_size'];           $categoryname =  $row_detailrs1['name'];         $region = $row_detailrs1['region'];          $streetno = $row_detailrs1['street_no'];         $streetname = $row_detailrs1['street_name'];         $suburb = $row_detailrs1['suburb'];         $postcode = $row_detailrs1['postcode'];         $clientid = $row_detailrs1['client_id'] ;          $contractid = $row_detailrs1['contract_id'] ;              $keywords = $row_detailrs1['keywords'];             $description = $row_detailrs1['desc'] ;             $mon  = $row_detailrs1['monday'] ;             $tue  =  $row_detailrs1['tuesday'] ;             $wed  = $row_detailrs1['wednesday'] ;             $thur  = $row_detailrs1['thursday'] ;             $fri  = $row_detailrs1['friday'] ;             $sat  = $row_detailrs1['saturday'] ;             $sun  = $row_detailrs1['sunday'] ;             $pubhol  = $row_detailrs1['public holiday'] ;             $alwaysopen  = $row_detailrs1['always open'] ;                  $lid .= $name . "business id";              $lbusiness_name .= $name .  "business name";             $lfixedphone .= $name . "fixed number";             $lmobilephone .= $name .    "mobile number";             $lactive .= $name . "   active";             $lad_size .= $name .    "   ad size";              $lname .= $name .   "   category name";             $lregion .= $name . "   region";              $lclient_id .= $name .  "client id";              $lcontract_id .= $name .    "contract id";               $keywords .= $name .    "keywords: ";             $description .= $name . "description: ";             $lcontract_id .= $name .    "contract id";             $mon .= $name . "monday";             $tue .= $name . "tuesday";             $wed .= $name . "wednesday";             $thur .= $name .    "thursday";             $fri .= $name . "friday";             $sat .= $name . "saturday";             $sun .= $name . "sunday";             $pubhol .= $name .  "public holiday";             $alwaysopen .= $name .  "always open";         }              date_default_timezone_set('australia/melbourne');   $datetime = new \datetime();    $listitem = array('<li class="active">', '</li>');   $curday = date('l');    $status = array( "now open" ,"closed",  "opening soon",  "closing soon", "open 24 hours", "  ");    $times = $times = array(     1 => array('day' => 'monday', 'open' => date( $row_detailrs1['mono'] ), 'close' => date( $row_detailrs1['monc'] )),     2 => array('day' => 'tuesday', 'open' => date( $row_detailrs1['tueo'] ), 'close' => date( $row_detailrs1['tuec'] )),     3 => array('day' => 'wednesday', 'open' => date( $row_detailrs1['wedo'] ), 'close' => date( $row_detailrs1['wedc']) ),     4 => array('day' => 'thursday', 'open' => date( $row_detailrs1['thuro'] ), 'close' => date( $row_detailrs1['thurc']) ),     5 => array('day' => 'friday', 'open' => date( $row_detailrs1['frio'] ), 'close' => date( $row_detailrs1['fric'] )),     6 => array('day' => 'saturday', 'open' => date( $row_detailrs1['sato'] ), 'close' => date( $row_detailrs1['satc']) ),     7 => array('day' => 'sunday', 'open' => date( $row_detailrs1['suno'] ), 'close' => date( $row_detailrs1['sunc'] )) );      $html .= "  <a href=''>"; echo $curday; $html .="</a>                 <table class='table table-striped'  border='0' align='center' cellpadding='10' cellspacing='20'>                <tr>                  <td>days</td>                  <td><span class='white-text' style='margin-right: 3em;'></td>                   <td>business hours</td>                   <td><span class='white-text' style='margin-right: 3em;'></td>                  <td>hours</td>                 </tr>";   $i = 1;    $cd = $datetime->format('n');   $timenow =     date("h:i:s", time());   // create array of day numbers start current day , loops around $day_order = array_merge(range($cd, 7), range(1, $cd-1));     foreach ($day_order $daynum): {     $oc = $times[$daynum];     $openingtime = $oc['open'];     $closingtime = $oc['close'];     $openingsoon = date('h:i:sa', strtotime($openingtime)-3600);     $closingsoon = date('h:i:sa', strtotime($closingtime)-3600);     if ($cd == $daynum) {         if ($openingtime == ' ' && $closingtime == ' ') {             $s = $status[4];         }         elseif ($timenow < $openingsoon || $timenow > $closingtime ) {             $s = $status[1];         }         elseif  ($timenow > $openingsoon && $timenow < $openingtime ) {             $s = $status[2];         }         elseif  ($timenow > $closingsoon && $timenow < $closingtime ) {             $s = $status[3];         } else {             $s = $status[0];         }     } else {         $s = " ";     }      $html .= "<tr>";     $html .= "<td>". $oc['day']."</td>";     $html .= "<td>  <span class='white-text' style='margin-right: 3em;'> </td>";     $html .= "<td>".$openingtime." ".$closingtime."</td>";     $html .= "<td>  <span class='white-text' style='margin-right: 3em;'> </td>";     $html .= "<td>".$s."</td>";     $html .= "</tr>";  }       $datetime->add(new \dateinterval('p1d'));           endforeach;   $html .= "</table>";   echo $html;       } 

and profile.blade.php

<div>   // want function showtimings displayed here </div> 

from controller can load view using return view('profile');

if want include data can access, html, can compact() data or chain function with() view method.

option 1:

return view('profile', compact('data');

return view('profile', compact('data', 'data2', 'data3');

option 2:

return view('profile')->with('data', $data);

return view('profile')->with(['data' => $data, 'data2' => $data2]);

note laravel automatically assume file postfixed .blade.php

in both examples, have access $data variable inside view.


but need say, php code isn't how @ in laravel. way troublesome teach laravel here, i'll leave link teach need started laravel.

https://laracasts.com/series/laravel-5-from-scratch


Comments

Popular posts from this blog

amazon web services - S3 Pre-signed POST validate file type? -

c# - Check Keyboard Input Winforms -