yii app db createcommand join yii1

yii app db createcommand join yii1

$user = Yii::app()->db->createCommand() ->select(‘id, username, profile’) ->from(‘tbl_user u’) ->join(‘tbl_profile p’, ‘u.id=p.user_id’) ->where(‘id=:id’, array(‘:id’=>$id)) ->queryRow(); Here is what the above code is Doing: 1. We create a command object using Yii::app()->db->createCommand(). 2. We call the select() method to specify the SELECT clause. 3. We call the from() method to specify the FROM clause. 4. We call…

laravel map the output of the api

laravel map the output of the api

Booking::select([‘booking_date’, ‘pickup_datetime’])->get() ->map(function ($booking) { $booking->pickup_datetime = optional($booking->pickup_time)->format(‘d M Y, h:i A’); $booking->booking_date = optional($booking->created_at)->format(‘d M Y, h:i A’); return $booking; }); Here is what the above code is Doing: 1. We are selecting the booking_date and pickup_datetime columns from the Booking model. 2. We are getting the results of the query. 3. We are…

Pass object to query on Router.push NextJs

Pass object to query on Router.push NextJs

import Router, { withRouter } from ‘next/router’ performSearch = (event) => { event.preventDefault(); Router.push({ pathname: ‘/results’, state: { pattern: this.state.searchText } }); }; Here is what the above code is Doing: 1. We’re importing the Router object from the next/router package. 2. We’re importing the withRouter HOC from the next/router package. 3. We’re creating a…

reindex after post api magento 2

reindex after post api magento 2

$objectManager = \Magento\Framework\App\ObjectManager::getInstance(); $indexerCollectionFactory = $objectManager->get(“\Magento\Indexer\Model\Indexer\CollectionFactory”); $indexerFactory = $objectManager->get(“\Magento\Indexer\Model\IndexerFactory”); $indexerCollection = $indexerCollectionFactory->create(); $allIds = $indexerCollection->getAllIds(); foreach ($allIds as $id) { $indexer = $indexerFactory->create()->load($id); $indexer->reindexAll(); } Here is what the above code is Doing: 1. Get the object manager 2. Get the indexer collection factory 3. Get the indexer factory 4. Get the indexer collection 5….

Save image to custom meta box

Save image to custom meta box

function save_joe_details($post_id){ global $post; if ( defined(‘DOING_AUTOSAVE’) && DOING_AUTOSAVE ) return $post_id; update_post_meta($post->ID, “custom_field_image”, $_POST[“custom_field_image”] ); } add_action(‘save_post’, ‘save_joe_details’); Here is what the above code is Doing: 1. We’re creating a custom meta box called “Joe Details” 2. We’re adding a custom field called “custom_field_image” 3. We’re saving the value of the custom field when…