eddy1992

Web developer intern at Experia Media

Hire Me

Experience

19,360

0 Best Reply Awards

  • Member Since 2 Years Ago
  • 73 Lessons Completed
  • 18 Favorites

11th January, 2018

eddy1992 started a new conversation 'Illuminate\Database\QueryException SQLSTATE[42000]: • 1 week ago

Hi I am checking on new relic and I see some errors coming and it shows like this

Exception 'Illuminate\Database\QueryException' with message 'SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MariaDB server version for the right syntax to use near 'offset 0' at line 1 (SQL: select * from `products1` where `categories_category_id` = 198 and `subcat` = 231 and `categoryAdvertiseTypeId` = 0 and MATCH (product_name, productNameArabic, productNameEnglish, product_Description, productDescriptionArabic, productDescriptionEnglish) AGAINST ( تركيب خيم وعنن وبيوت الشعر IN NATURAL LANGUAGE MODE) and `startdate` > 1510401145890 and `active` = 0 order by `startdate` desc offset 0)' in /home/apimzad/public_html/vendor/laravel/framework/src/Illuminate/Database/Connection.php:729

any idea what I might be doing wrong

my query

public function searchAdsInProducts1($data)
    {
        $searchString = $data->get('searchStr');
        $categoryId = $data->get('productId');//categories_category_id ie. car, property etc.
        $subCategoryIds = $data->get('subCategoryId');//subcat
        $subSubCategoryIds = $data->get('subsubCategoryId');//subsubCategoryId
        $productsLanguage = $data->get('productsLang');//lang
        $numberPerPage = $data->get('numberperpage');

        $manfactureYearFrom = $data->get('manfactureYearFrom');
        $manfactureYearTo = $data->get('manfactureYearTo');
        $kmFrom = $data->get('kmFrom');
        $kmTo = $data->get('kmTo');
        $priceFrom = $data->get('priceFrom');
        $priceTo = $data->get('priceTo');
        $regionId = $data->get('regionId');
        $furnishedTypeId = $data->get('furnishedTypeId');
        $numberOfRoomsFrom = $data->get('numberOfRoomsFrom');
        $numberOfRoomsTo = $data->get('numberOfRoomsTo');
        $cityId = $data->get('cityId');
        $categoryAdvertiseTypeId = $data->get('categoryAdvertiseTypeId');
        $orderBy = $this->decideOrderBy($data);
        $time = $this->decideTime($data);

        $page = $data->get('page', 1);

        // Items per page (maybe put this in a config file?)
        // $perPage = $data->get('numberperpage');
        $perPage = $data->get('numberperpage');
        // Calculate the offset based on the current page.
        $offset = ($page * $perPage) - $perPage;


        if(($data->get('page') == 1)){

            $sticky = Product::with(['category', 'getCity', 'getRegion', 'getVideo'])
                    ->categoriesCategoryId($categoryId)
                    // ->where('companies', 1)
                    ->where('sticky', 1)
                    // ->subSubCategory($subSubCategoryIds)
                    // ->subCat($subCategoryIds)
                    ->categoryAdvertiseTypeId($categoryAdvertiseTypeId)
                    // ->regionId($regionId)
                    // ->furnishedTypeId($furnishedTypeId)
                    // ->cityId($cityId)
                    // ->searchString($searchString)
                    // ->km($kmFrom, $kmTo)
                    // ->price($priceFrom, $priceTo)
                    // ->numberOfRooms($numberOfRoomsFrom, $numberOfRoomsTo)
                    // ->manufactureYear($manfactureYearFrom, $manfactureYearTo)
                    // ->language($productsLanguage)
                    // ->orderBy('product_id', 'desc')
                    // ->active()//
                    // ->inReview()//for new advertisement flow.
                    ->lastOneMonth($categoryId)
                    ->orderByRaw('RAND()')
                    ->take(30)
                    ->get();
        }

        if(($data->get('page') == 1) AND ($categoryId != 0)){
            if(!$sticky->isEmpty()){
                $countOfStarAds = $sticky->count();

                $perPage = $data->get('numberperpage') - $countOfStarAds;
            }
        }


        $ads = Product::with(['category', 'getCity', 'getRegion', 'getVideo'])
                ->categoriesCategoryId($categoryId)
                ->subSubCategory($subSubCategoryIds)
                ->subCat($subCategoryIds)
                ->categoryAdvertiseTypeId($categoryAdvertiseTypeId)
                ->regionId($regionId)
                ->furnishedTypeId($furnishedTypeId)
                ->cityId($cityId)
                ->searchString($searchString, $categoryId)
                ->km($kmFrom, $kmTo)
                ->price($priceFrom, $priceTo)
                ->numberOfRooms($numberOfRoomsFrom, $numberOfRoomsTo)
                ->manufactureYear($manfactureYearFrom, $manfactureYearTo)
                ->lastTwoMonths($categoryId)
                ->time($time)
                ->language($productsLanguage)
                ->orderBy($orderBy, 'desc')
                ->active()//
                // ->inReview()////for new advertisement flow.
                ->skip($offset)//remove if not working
                ->take($perPage)//remove if not working
                // ->paginate(50, ['*'], 'page', $page);
                ->get();

        if($data->get('isAdsSupported') == 'true'){
            $paidAds = $this->getPaidAds($data);
        }

        if(($data->get('page') == 1) AND ($categoryId != 0)) {
            // $data = $ads;
            $data = $sticky->merge($ads);
        }else{
            $data = $ads;
        }

        return ['ads' => $data, 'paidAds' => $paidAds];
    }

please tell me what I am doing

5th January, 2018

eddy1992 started a new conversation SSL Operation Failed • 1 week ago

Hi guys I have code to which is supposed to send ios push messages but it is giving me an error do not know why ?

my code

$streamContextCreate = stream_context_create();
            
            stream_context_set_option($streamContextCreate, 'ssl', 'local_cert', '/home/devmzad/public_html/public/ios/MzadDevCertificates.pem');
            
            $fp = stream_socket_client(
                'ssl://gateway.push.apple.com:2195', $err,
                $errstr, 60, STREAM_CLIENT_CONNECT|STREAM_CLIENT_PERSISTENT, $streamContextCreate);
            echo "<pre>";
            print_r($fp); //gives error here.
            die;

the error

stream_socket_client(): SSL operation failed with code 1. OpenSSL Error messages:
error:14094438:SSL routines:SSL3_READ_BYTES:tlsv1 alert internal error

Guys would appreciate if someone could help me with please that why this is giving this weird error ?

22nd December, 2017

eddy1992 started a new conversation My Api Is Slow And Facing 504 Error Sometimes. • 3 weeks ago

Hi guys I have an api and that api purpose is it to fetch all the products. So this api is giving us some trouble as its slow on live and sometimes gets stuck and gives us 504 time out error. It has become complete nightmare why it happens and I am not able to figure that out, hopefully some one could just see and tell what might be the reason for the slowness.

so I have a controller GetCategoryDataApiController this has the method named getCategoryData this will get the post data and process further.


<?php

namespace App\Http\Controllers\API;

use Illuminate\Http\Request;

use DB;
use App\User;
use App\City;
use App\Product;
use App\Category;
use App\Http\Requests;
use App\Product_images1;
use App\Http\Controllers\Controller2;
use App\Http\Traits\ProductsOneTableLangTrait;
use App\Http\Traits\ProductOneImageUtilityTrait;
use App\Http\Traits\ProductOneUtilityTrait;
use App\Http\Traits\UtilitiesTrait;

class GetCategoryDataApiController extends Controller2
{   
    /**
     * This trait will handle all the 
     * data that will be filtered 
     * on the basis of language
     */
    use ProductsOneTableLangTrait, 
    ProductOneImageUtilityTrait, 
    ProductOneUtilityTrait,
    UtilitiesTrait;


    /**
     * the website url
     * @var string
     */
    protected $website;


    /**
     * device language the user pass
     * @var string
     */
    protected $deviceLanguage;


    /**
     * products Language the use pass
     * @var string
     */
    protected $prodLanguage;



    protected $lastupdatetime;


    protected $countOfRow;

    /**
     * get the category data  
     * @param  Request $request 
     * @return json we would get the ads from the products1 table.
     */
    public function getCategoryData(Request $request)
    {   
        
        $data = $request->json();
        $this->setLanguage($data);

        $adsFound = $this->searchAdsInProducts1($data); // this would get all the products.
        $ads = $this->createJsonFormatForGetCategoryData($adsFound['ads'], $this->deviceLanguage);
        return $this->mergePaidAdsWithNormalAds($ads, $adsFound['paidAds']);
    }   


    /**
     * set language so we could refer it 
     * in the code whenever needed
     * @param $data this is the request param
     */
    public function setLanguage($data)
    {   
        $this->website = config('app.url');
        $this->deviceLanguage = $data->get('userDeviceLanguage');
        $this->prodLanguage = $data->get('productsLang');
        $this->countOfRow = $data->get('countOfRow');
        $this->lastupdatetime = ($data->get('lastupdatetime')) 
        ?  $data->get('lastupdatetime')
        :  $this->lastUpdateTime();
    }

    
    public function createJsonFormatForGetCategoryData($data, $lang)
    {
        if(!$data->isEmpty()){

            $index = 0;
            foreach($data as $key => $item) {

                $categoryName = $this->getCategoryNameOnBasisOfLang($item->categories_category_id, $lang);
                $subCategoryName = $this->getCategoryNameOnBasisOfLang($item->subcat, $lang);
                $subsubCategoryName = $this->getCategoryNameOnBasisOfLang($item->subsubCategoryId, $lang);

                $cityName = $this->getCityNameDependLanguage($lang, $item);
                $advertiseName = Category::getAdvertiseType($item->categoryAdvertiseTypeId, $lang);
                $furnishedTypeName = $this->getFurnishedNameDependLanguage($lang, $item);
                // $properties = $this->addPropertiesArray($categoryName,$subCategoryName,$advertiseName,$item->manfactureYear,$furnishedTypeName,$lang,$item);
                $manfactureYearId = $this->getManufactureIdFromYear($item->manfactureYear);
                $properties = $this->addProperties($item,$advertiseName,$subsubCategoryName,$subCategoryName,$furnishedTypeName,$manfactureYearId,$lang);

                
                $mainImage = $this->getProductMainImage($item, $this->website);

                $products[] = [
                    'dateOfAdvertise'          => $item->startdate,
                    'isAd'                     => $item->isAd,
                    'isShowAddCommentAndLikes' => $item->isShowAddCommentAndLIkes,
                    'productId'               =>  "$item->product_id",
                    'categoryAdvertiseTypeId'  => $item->categoryAdvertiseTypeId,
                    'productName'              => $this->setProductNameUsingLang($item, $this->prodLanguage),
                    'productNameEnglish'       => $item->productNameEnglish,
                    'productNameArabic'        => $item->productNameArabic,
                    'productPrice'             => "$item->product_price",
                    'productDescription'       => $item->product_Description,
                    'productDescriptionEnglish'=> $item->productDescriptionEnglish,
                    'productDescriptionArabic' => $item->productDescriptionArabic,
                    'categoryId'               => "$item->categories_category_id",
                    'categoryName'             => $categoryName,
                    'subCategoryId'            => "$item->subcat",
                    'subCategoryName'          => $subCategoryName,
                    'subsubCategoryId'         => $item->subsubCategoryId,
                    'subsubCategoryName'       => $subsubCategoryName,
                    'categoryAdvertiseTypeName'=> $advertiseName,
                    'cityId'                   => $item->cityId,
                    'cityName'                 => $cityName,
                    'regionId'                 => $item->regionId,
                    'regionName'               => $this->getRegionNameDependLanguage($lang, $item),
                    'manfactureYear'           => $this->convertDateToTheLang($lang, $item->manfactureYear),
                    'km'                       => $item->km,
                    'furnishedTypeId'          => $item->furnishedTypeId,
                    'furnishedTypeName'        => $furnishedTypeName,
                    'numberOfRooms'            => $item->numberOfRooms,
                    'commentCount'             => "$item->comment",
                    'likeCount'                => $this->getUserLikes($data, $item),
                    'productAdvertiseUrl'      => $item->productAdvertiseUrl,
                    'isCompany'                => $item->companies,
                    'clickType'                => $item->clickType,
                    'productMainImage'         => $mainImage,
                    'userCountryCode'          => $item->countries_country_id,
                    'userNumber'               => "$item->users_user_id",
                    'userName'                 => User::findUserNameBasedOnNumber($item->users_user_id, $this->deviceLanguage),
                    'userEmail'                => User::findEmailBasedOnNumber($item->users_user_id),
                    'userPhoto'                => User::findUserPhotoBasedOnNumber($item->users_user_id),
                    'userSmallDescription'     => User::getUserInfo($item->users_user_id),
                    'userProfileLink'          => $this->profileLink($item, $this->website),
                    'productUrl'               => $this->productUrl($item, $this->website),
                    'productShareImage'        => $this->productShareImage($item, $this->website),
                    'advertiseTimeFormatted'   => $this->getAdvertiseTimeFormatted($item, $lang),
                    'numberOfViews'            => "$item->points",
                    'lang'                     => $item->lang,
                    'properties'               => $properties,
                    'productImages'            => $this->getProductImages($item, $this->website),
                    'productMainImageNewSize'  => $mainImage,
                    'productAttachments'       => $this->getProdAttachments($item, $this->website),
                    'isMainVideo'              => $this->setIsMainVideo($mainImage, $item),
                    'mainAttachment'           => $mainImage,
                    'manfactureYearId'         => $manfactureYearId,
                    'longitude'                => $item->longitude,
                    'latitude'                 => $item->latitude,
                    'location'                 => $item->location
                ];
            }
            $productInfo['lastupdatetime'] = "$this->lastupdatetime";
            $productInfo['products'] = $products;

            return $productInfo;
        }

        return [
            'lastupdatetime' => "$this->lastupdatetime",
            'products' => []
        ];
    }

    public function mergePaidAdsWithNormalAds($ads, $paidAds)
    {   
        $key = ($this->countOfRow * 4) - ((0 * ($this->countOfRow - 1)) + $this->countOfRow);
        $countOfAds = count($ads['products']);
        if($key < $countOfAds){
            $ads['products'][$key] = $paidAds;
            return $ads;
        }else{
            return $ads;
        }
    }
}



Now $adsFound = $this->searchAdsInProducts1($data); this would fetch the records from the table using eloquent. In this method we are just fetching using the query scope and merging two record sets.

/**
     * we would search the products 1 table
     * with all the request params posted
     * we would query only when the request 
     * params are passed.
     * @param  object $data This is the request param
     * @return eloquent collection
     */
    public function searchAdsInProducts1($data)
    {   
        $searchString = $data->get('searchStr');
        $categoryId = $data->get('productId');//categories_category_id ie. car, property etc.
        $subCategoryIds = $data->get('subCategoryId');//subcat
        $subSubCategoryIds = $data->get('subsubCategoryId');//subsubCategoryId
        $productsLanguage = $data->get('productsLang');//lang
        $numberPerPage = $data->get('numberperpage');

        $manfactureYearFrom = $data->get('manfactureYearFrom');
        $manfactureYearTo = $data->get('manfactureYearTo');
        $kmFrom = $data->get('kmFrom');
        $kmTo = $data->get('kmTo');
        $priceFrom = $data->get('priceFrom');
        $priceTo = $data->get('priceTo');
        $regionId = $data->get('regionId');
        $furnishedTypeId = $data->get('furnishedTypeId');
        $numberOfRoomsFrom = $data->get('numberOfRoomsFrom');
        $numberOfRoomsTo = $data->get('numberOfRoomsTo');
        $cityId = $data->get('cityId');
        $categoryAdvertiseTypeId = $data->get('categoryAdvertiseTypeId');
        $orderBy = $this->decideOrderBy($data);
        $time = $this->decideTime($data);

        $page = $data->get('page', 1);

        // Items per page (maybe put this in a config file?)
        $perPage = 50; 

        // Calculate the offset based on the current page.
        $offset = ($page * $perPage) - $perPage;

        if(($data->get('page') == 1)){

            $sticky = Product::categoriesCategoryId($categoryId)
                    // ->where('companies', 1)
                    ->where('sticky', 1)
                    // ->subSubCategory($subSubCategoryIds)
                    // ->subCat($subCategoryIds)
                    ->categoryAdvertiseTypeId($categoryAdvertiseTypeId)
                    
                    ->orderBy('product_id', 'desc')
                    ->take(50)
                    ->get();
        }
        
        $ads = Product::categoriesCategoryId($categoryId)
                ->subSubCategory($subSubCategoryIds)
                ->subCat($subCategoryIds)
                ->categoryAdvertiseTypeId($categoryAdvertiseTypeId)
                ->regionId($regionId)
                ->furnishedTypeId($furnishedTypeId)
                ->cityId($cityId)
                ->searchString($searchString, $categoryId)
                ->km($kmFrom, $kmTo)
                ->price($priceFrom, $priceTo)
                ->numberOfRooms($numberOfRoomsFrom, $numberOfRoomsTo)
                ->manufactureYear($manfactureYearFrom, $manfactureYearTo)
                // ->lastTwoMonths($categoryId)
                ->time($time)
                ->language($productsLanguage)
                ->orderBy($orderBy, 'desc')
                ->skip($offset)//remove if not working
                ->take($perPage)//remove if not working
                // ->paginate(50, ['*'], 'page', $page);
                ->get();

        if($data->get('isAdsSupported') == 'true'){
            $paidAds = $this->getPaidAds($data);
        }

        if(($data->get('page') == 1) AND ($categoryId != 0)) {
            // $data = $ads;
            $data = $sticky->merge($ads);
        }else{
            $data = $ads;
        }

        return ['ads' => $data, 'paidAds' => $paidAds];
    }

This all what is happening. I would appreciate your views in how I could improve this and then improve performance , or if you feel there is something suspicious then please let me know. Thank you. Please assist.

eddy1992 left a reply on Pagination For Api. • 3 weeks ago

Thank you so much @bobbybouwmann , I think the issue is somewhere else for the performance.

19th December, 2017

eddy1992 started a new conversation Search Columns Using % Like % • 4 weeks ago

Hi guys I have a question , If I had to search multiple columns using eloquent query scope how will I do it . The below elquent query giving me less results when searching. Is this correct to search a string in columns in a table. Please assist.

/**
     * query scope for search string
     * @param  $query
     * @param  String $searchString 
     * @return 
     */
    public function scopeSearchString($query, $searchString)
    {   
        if(!empty($searchString)){
            return $query->where('product_name', 'like', '%'.$searchString.'%')
                    ->orWhere('product_Description', 'like', '%'.$searchString.'%')
                    ->orWhere('users_user_id', 'like', '%'.$searchString.'%')
                    ->orWhere('productNameArabic', 'like', '%'.$searchString.'%')
                    ->orWhere('productNameEnglish', 'like', '%'.$searchString.'%')
                    ->orWhere('productDescriptionArabic', 'like', '%'.$searchString.'%')
                    ->orWhere('productDescriptionEnglish', 'like', '%'.$searchString.'%');
        }
        return $query;
    }

17th December, 2017

eddy1992 left a reply on Pagination For Api. • 1 month ago

Hi @bobbybouwmann wow thanks for that answer. It would be really helpful if you could provide me an example. I think the second options seems perfect for me. Thank you so much.

eddy1992 started a new conversation Pagination For Api. • 1 month ago

Hi guys I have two queries that would fetch records for me but I am using laravel paginator and I feel its making it slow, I am doing this query for api

/**
     * we would search the products 1 table
     * with all the request params posted
     * we would query only when the request 
     * params are passed.
     * @param  object $data This is the request param
     * @return eloquent collection
     */
    public function searchAdsInProducts1($data)
    {   
        $searchString = $data->get('searchStr');
        $categoryId = $data->get('productId');//categories_category_id ie. car, property etc.
        $subCategoryIds = $data->get('subCategoryId');//subcat
        $subSubCategoryIds = $data->get('subsubCategoryId');//subsubCategoryId
        $productsLanguage = $data->get('productsLang');//lang
        $page = $data->get('page');
        $numberPerPage = $data->get('numberperpage');

        $manfactureYearFrom = $data->get('manfactureYearFrom');
        $manfactureYearTo = $data->get('manfactureYearTo');
        $kmFrom = $data->get('kmFrom');
        $kmTo = $data->get('kmTo');
        $priceFrom = $data->get('priceFrom');
        $priceTo = $data->get('priceTo');
        $regionId = $data->get('regionId');
        $furnishedTypeId = $data->get('furnishedTypeId');
        $numberOfRoomsFrom = $data->get('numberOfRoomsFrom');
        $numberOfRoomsTo = $data->get('numberOfRoomsTo');
        $cityId = $data->get('cityId');
        $categoryAdvertiseTypeId = $data->get('categoryAdvertiseTypeId');
        $orderBy = $this->decideOrderBy($data);
        $time = $this->decideTime($data);

        if(($data->get('page') == 1) AND ($categoryId != 0)){

            $sticky = Product::categoriesCategoryId($categoryId)
                    ->where('companies', 1)
                    ->where('sticky', 1)
                    // ->subSubCategory($subSubCategoryIds)
                    // ->subCat($subCategoryIds)
                    ->categoryAdvertiseTypeId($categoryAdvertiseTypeId)
                    ->regionId($regionId)
                    ->furnishedTypeId($furnishedTypeId)
                    ->cityId($cityId)
                    // ->searchString($searchString)
                    ->km($kmFrom, $kmTo)
                    ->price($priceFrom, $priceTo)
                    ->numberOfRooms($numberOfRoomsFrom, $numberOfRoomsTo)
                    ->manufactureYear($manfactureYearFrom, $manfactureYearTo)
                    // ->language($productsLanguage)
                    ->orderBy('product_id', 'desc')
                    ->take(50)
                    ->get();
        }

        $ads = Product::categoriesCategoryId($categoryId)
                ->subSubCategory($subSubCategoryIds)
                ->subCat($subCategoryIds)
                ->categoryAdvertiseTypeId($categoryAdvertiseTypeId)
                ->regionId($regionId)
                ->furnishedTypeId($furnishedTypeId)
                ->cityId($cityId)
                ->searchString($searchString)
                ->km($kmFrom, $kmTo)
                ->price($priceFrom, $priceTo)
                ->numberOfRooms($numberOfRoomsFrom, $numberOfRoomsTo)
                ->manufactureYear($manfactureYearFrom, $manfactureYearTo)
                ->lastTwoMonths($categoryId)
                ->time($time)
                ->language($productsLanguage)
                ->orderBy($orderBy, 'desc')
                ->paginate(50, ['*'], 'page', $page);

        if($data->get('isAdsSupported') == 'true'){
            $paidAds = $this->getPaidAds($data);
        }

        if(($data->get('page') == 1) AND ($categoryId != 0)) {
            // $data = $ads;
            $data = $sticky->merge($ads);
        }else{
            $data = $ads;
        }

        return ['ads' => $data, 'paidAds' => $paidAds];
    }

When I see db log query it does SELECT count(*) as aggregate

Now I have million records and it would do count *, I feel this would make it slow, is there any other alternative to this for api ? Please suggest thank you.

16th December, 2017

eddy1992 left a reply on Search On The Last Two Months Records • 1 month ago

@Snapey If I do recent() in the first then it would first search only in the scope of last month, and if do in the last then it would do something else right ?

eddy1992 left a reply on Search On The Last Two Months Records • 1 month ago

@Snapey Thank you so much for your answer.

eddy1992 left a reply on Search On The Last Two Months Records • 1 month ago

@Snapey thanks for you reply , so doing a simple where would do the trick ? so it would search from all the records when done with where date = 2 months before from now ?

eddy1992 started a new conversation Search On The Last Two Months Records • 1 month ago

Hi I have a situation where I have millions of records in a table and I dont want to search the whole record set all times. Imagine I have a products table and I have 1 million products of last 5 years and to search something like finding product name I have to search the whole records, can I do something like search only the last two months records. So that the performance improves. If yes how will I do it using eloquent ?

please assist.

13th November, 2017

eddy1992 left a reply on Having Condition In A Laravel Eloquent Query. • 2 months ago

@tykus Thank you so much for your reply but I wanted to know whether I could user sortBy() to achieve this ?

eddy1992 started a new conversation Having Condition In A Laravel Eloquent Query. • 2 months ago

Hi I have an eloquent query and the table I am querying contains a column named active. So active could be 1 or 0. Now I am querying all the records from the table, that means I have all the records which may have active = 1 or active = 0. Now what I want to do is that I want to show or get the active = 1 records first then the those records which have active = 0.

//now Imagine we get all the records from this query so the $allRecords variable has 
//all the records which are active and not active.
$allRecords = Product::where('city', 'New York')->get();

//Now I want to sequence or reorder the collection where I want to show the active=1 first then active=0.

please assist.

25th October, 2017

eddy1992 started a new conversation Bind List Item Array Vue Data To Input Value In A Form • 2 months ago

Hi I have a form and I have a input field in which I have a vue event which allows to take some values and add it to a data a object in the vue js, but I am not able to bind this vue data property to the input value so I would get back when the form is submitted.

My input

<div class="col-md-4">
   <ul>
      <li v-for="item in filterListValueEnArray">
         @{{ item }}
         <button @click.prevent="removeFilterEn(filterListValueEn)">remove</button>
      </li>
   </ul>
   <input type="text" v-model="filterListValueEn" @keydown.enter.prevent="addFilterValEn(filterListValueEn)" name="array" v-bind:value="filterListValueEnArray" class="form-control">
</div>

vue js code

        new Vue({
            el: '#advFilter',

            data: {
                selectFilterType: '',
                
                filterListValueEn: '',
                filterListValueEnArray: [],
                filterListValueAr: '',
                filterListValueArArray: [],
            },

            methods: {
                addFilterValEn: function(filterListValueEn) {
                    this.filterListValueEnArray.push(filterListValueEn);
                    this.filterListValueEn = '';

                },
                addFilterValAr: function(filterListValueAr) {
                    this.filterListValueArArray.push(filterListValueAr);
                    this.filterListValueAr = '';    
                },
                removeFilterAr: function(filterListValueAr) {
                    this.filterListValueArArray.pop(filterListValueAr)
                },
                removeFilterEn: function(filterListValueEn) {
                    this.filterListValueEnArray.pop(filterListValueEn)
                }
            }
        });

I want to bind the filterListValueEnArray in the value of the text field but I dont get back anything when I do

$request->all();

Please assist

29th September, 2017

eddy1992 left a reply on Laravel Db::raw Query For The Query Scope. • 3 months ago

@36864 thank you for you response please check I have edited my question

eddy1992 started a new conversation Laravel Db::raw Query For The Query Scope. • 3 months ago

Hi I have a query scope in laravel and I have a column named km which is varchar. Now I want to write a raw query scope for it. The problem is it wont search for the varchar. So need to cast km to unsigned.

    public function scopeKm($query, $kmFrom, $kmTo)
    {   
        $kmFrom = (int)$kmFrom;
        $kmFrom = (int)$kmTo;

        if((count($kmFrom) > 0) && count($kmTo) > 0){ 

            return $query->whereBetween('km', [$kmFrom, $kmTo]);   
        }
        return $query;
    }

I want to write the db raw query for the above in which I cast the km column to unsigned in the raw query.

eddy1992 left a reply on WhereBetween() Eloquent Returning Wrong Results • 3 months ago

@ChristophHarms thank you for your reply. Even If I am trying to pass integer same issue.

eddy1992 left a reply on WhereBetween() Eloquent Returning Wrong Results • 3 months ago

@nadj Its varchar(10).

eddy1992 started a new conversation WhereBetween() Eloquent Returning Wrong Results • 3 months ago

Hi I have a eloquent query and I am using query scope. I have a km column in my table and I am passing kmFrom and KmTo values as post data. Now I am doing a eloquent whereBetween and its returning wrong results when I search for km.

For example if I pass kmFrom = 1000 and kmTo = 2000. Its giving me results which are not in between these two values.

Eloquent

Product::categoriesCategoryId($categoryId)
            ->km($kmFrom, $kmTo)->get();

Query Scope for the km -:

public function scopeKm($query, $kmFrom, $kmTo)
    {   
        if(($kmFrom) && ($kmTo)){
            return $query->whereBetween('km', ["$kmFrom", "$kmTo"]);   
        }
        return $query;
    }

Please assist

24th September, 2017

eddy1992 started a new conversation Laravel Not Returning Request • 3 months ago

I am trying to post this json http://jsoneditoronline.org/?id=4d930c11daaf8cd8bb6df6edbc446a1e object with base 64 and its returning empty array when I do $request->all();

31st August, 2017

eddy1992 started a new conversation Undefined Index Http_accept_language Laravel • 4 months ago

Hi I am facing an error when I trying to call a route on the remote server.

ErrorException in Controller.php line 25:
Undefined index: HTTP_ACCEPT_LANGUAGE
in Controller.php line 25
at HandleExceptions->handleError('8', 'Undefined index: HTTP_ACCEPT_LANGUAGE', '/home/devmzad/public_html/app/Http/Controllers/Controller.php', '25', array('request' => object(Request))) in Controller.php line 25
at Controller->__construct(object(Request))
at ReflectionClass->newInstanceArgs(array(object(Request))) in Container.php line 779
at Container->build('App\Http\Controllers\API\AdvFilterApiController', array()) in Container.php line 629
at Container->make('App\Http\Controllers\API\AdvFilterApiController', array()) in Application.php line 697
at Application->make('App\Http\Controllers\API\AdvFilterApiController') in ControllerDispatcher.php line 67
at ControllerDispatcher->makeController('App\Http\Controllers\API\AdvFilterApiController') in ControllerDispatcher.php line 52
at ControllerDispatcher->dispatch(object(Route), object(Request), 'App\Http\Controllers\API\AdvFilterApiController', 'getAddAdvFilters') in Route.php line 174
at Route->runController(object(Request)) in Route.php line 140
at Route->run(object(Request)) in Router.php line 724
at Router->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in Checklang.php line 26
at Checklang->handle(object(Request), object(Closure))
at call_user_func_array(array(object(Checklang), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in ShareErrorsFromSession.php line 49
at ShareErrorsFromSession->handle(object(Request), object(Closure))
at call_user_func_array(array(object(ShareErrorsFromSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in StartSession.php line 64
at StartSession->handle(object(Request), object(Closure))
at call_user_func_array(array(object(StartSession), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in AddQueuedCookiesToResponse.php line 37
at AddQueuedCookiesToResponse->handle(object(Request), object(Closure))
at call_user_func_array(array(object(AddQueuedCookiesToResponse), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in EncryptCookies.php line 59
at EncryptCookies->handle(object(Request), object(Closure))
at call_user_func_array(array(object(EncryptCookies), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
at Pipeline->then(object(Closure)) in Router.php line 726
at Router->runRouteWithinStack(object(Route), object(Request)) in Router.php line 699
at Router->dispatchToRoute(object(Request)) in Router.php line 675
at Router->dispatch(object(Request)) in Kernel.php line 246
at Kernel->Illuminate\Foundation\Http\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 52
at Pipeline->Illuminate\Routing\{closure}(object(Request)) in CheckForMaintenanceMode.php line 44
at CheckForMaintenanceMode->handle(object(Request), object(Closure))
at call_user_func_array(array(object(CheckForMaintenanceMode), 'handle'), array(object(Request), object(Closure))) in Pipeline.php line 136
at Pipeline->Illuminate\Pipeline\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 32
at Pipeline->Illuminate\Routing\{closure}(object(Request))
at call_user_func(object(Closure), object(Request)) in Pipeline.php line 103
at Pipeline->then(object(Closure)) in Kernel.php line 132
at Kernel->sendRequestThroughRouter(object(Request)) in Kernel.php line 99
at Kernel->handle(object(Request)) in index.php line 54

Please any idea what is wrong with it. Please assist.

25th August, 2017

eddy1992 left a reply on Error Facing When Creating Columns Dynamically In A Table • 4 months ago

@Snapey Thank you. No the error looks like this http://imgur.com/ID3yIrY

eddy1992 started a new conversation Error Facing When Creating Columns Dynamically In A Table • 4 months ago

Hi I am creating columns dynamically in a table and facing a weird error. The page says

error GTO

error

when I am running the command to create a new column in the table.

The code where I am creating the columns -:

public function createColumn($column)
    {   
        DB::transaction(function () use ($column){
            $this->createColumnInProducts1($column);
            $this->createColumnInProducts4($column);
        });
    }


    public function createColumnInProducts1($column)
    {   
        Schema::table('products1', function ($table) use ($column) {
            $table->string($column);
        });
    }


    public function createColumnInProducts4($column)
    {
        Schema::table('products4', function ($table) use ($column){
            $table->string($column);
        });
    }

Please assist why its showing this error. On my local its working fine but on the server I am getting this error.

18th August, 2017

eddy1992 left a reply on Create Columns In A Table Dynamically • 5 months ago

Thanks @Cronix you are awesome cheers.

eddy1992 left a reply on Create Columns In A Table Dynamically • 5 months ago

@Dunsti No I want to add it dynamically through code.

eddy1992 started a new conversation Create Columns In A Table Dynamically • 5 months ago

Hi I want to know whether its possible to create columns dynamically in a table. For example If I have table named car and I have two columns , car_name, car_year and later on some condition I want to add columns dynamically like car_tyre, car_insurance in the table. If this is possible please let me know. Thanks.

11th August, 2017

eddy1992 started a new conversation How To Take Json As Input And Display In Laravel • 5 months ago

Hi I want to know whether I could take an array of json and store it in a table as a longText and retrieve it as json later on ? Is this the way to approach it ? if not then what will the ideal way to do it.

Right now in my database there is a table column named filterListValues which has a datatype longText.

I am coping the json ie is the value of the key filterListValues and pasting it in using an text area.

and later I am just getting the it as a string for this column.

"filterListValues": [
            {
              "filterListValuesId": "0",
              "filterListValuesNameEnglish": "All Types",
              "filterListValuesNameArabic": "All Types arabic",
              "filterListValuesImage": ""
            },
            {
              "filterListValuesId": "1",
              "filterListValuesNameEnglish": "Furnished",
              "filterListValuesNameArabic": "Furnished arabic",
              "filterListValuesImage": ""
            },
            {
              "filterListValuesId": "2",
              "filterListValuesNameEnglish": "Semi Furnished",
              "filterListValuesNameArabic": "Semi Furnished arabic",
              "filterListValuesImage": ""
            },
            {
              "filterListValuesId": "3",
              "filterListValuesNameEnglish": "Not Furnished",
              "filterListValuesNameArabic": "Not Furnished arabic",
              "filterListValuesImage": ""
            }
          ]

Please assist me on this. Thank you

9th August, 2017

eddy1992 left a reply on Base Table Or View Not Found: 1051 Unknown Table After Php Artisan Migrate:refresh • 5 months ago

@tykus Thank you for your response, I am using laravel 5.2 and I tried the option to drop all tables and run migrations again but gave me the same error.

eddy1992 started a new conversation Base Table Or View Not Found: 1051 Unknown Table After Php Artisan Migrate:refresh • 5 months ago

Hi I am facing an issue where I am trying to run php artisan migrate:refresh and every time I run my migration it gives me an error

[Illuminate\Database\QueryException]
  SQLSTATE[42S02]: Base table or view not found: 1051 Unknown table 'mzad-web.adv_filter_categories' (SQL: drop table `adv_filter_categories`)
 [PDOException]
  SQLSTATE[42S02]: Base table or view not found: 1051 Unknown table 'mzad-web.adv_filter_categories'

But when I go and check in the adminer I could see the tables have been dropped. After that If i run php artisan migrate it migrates the tables back again. The only issue is when I try to run php artisan migrate:refresh it gives me this error. Please assist

my migration files I have only two migration files -:

  1. This is the one which is shown in the error.
<?php

use Illuminate\Database\Schema\Blueprint;
use Illuminate\Database\Migrations\Migration;

class CreateAdvFilterCategoriesTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('adv_filter_categories', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('category_id')->unsigned();
            $table->string('category_name_english');
            $table->string('category_name_arabic');
            $table->boolean('active')->default(1);
            $table->timestamps();
        });
    }

    /**
     * Reverse the migrations.
     *
     * @return void
     */
    public function down()
    {
        Schema::drop('adv_filter_categories');
    }
}


Please assist I am stuck with it for such a long time and not able to understand why tis happening.

Thank you

12th July, 2017

eddy1992 left a reply on Selected Option Not Working When Using V-model • 6 months ago

@tykus nope I do not have any errors in my browser.

eddy1992 left a reply on Selected Option Not Working When Using V-model • 6 months ago

@tykus no they have -:

<select class="form-control c-select" v-model="signUpUserTypeSelected" name="user_type" >
                <option disabled value="">Please select one</option>
                <option value="Parent">Parent</option>
                <option value="Student">Student</option>
                <option value="Teacher">Teacher</option>
            </select>

eddy1992 started a new conversation Selected Option Not Working When Using V-model • 6 months ago

Hi I have a select which looks like this -:

<select class="form-control c-select" v-model="signUpUserTypeSelected" name="user_type" >
                
                <option selected>Parent</option>
                <option>Student</option>
                <option>Teacher</option>
            </select>

Now the select selected option is not working on it please assist.

My app.js for signUpUserTypeSelected,

const app = new Vue({
    el: '#app',

    data: {
        signUpUserTypeSelected: '',
        signInUserTypeSelected: '',
    },

Please assist how will I solve this issue

eddy1992 started a new conversation Vue And Laravel Partials • 6 months ago

Hi I have a layout name app.blade.php which looks like this -:

<body>
    <div class="app white" id="app"> //I have mentioned this id in vue 
        @yield('content')
    </div>
</body>

I have mentioned a div with an id of app , Now I have two blades one is sign-up and other is sign-in

Sign-up.blade.php looks like this in which I have mentioned a v-model with a select -:

@extends('layouts.app') 

@section('title', 'sign-up')

@section('content')

<div class="col-sm-10">
            <select class="form-control c-select" v-model="signUpUserTypeSelected"          name="user_type" required>
                <option disabled value="">Please select one</option>
                <option>Parent</option>
                <option>Student</option>
                <option>Teacher</option>
            </select>
        </div>

and in app.js I have declared an empty data for signUpUserTypeSelected and everything works fine for the sign-up.blade.php-:

my app.js

const app = new Vue({
    el: '#app',
    data: {
        signUpUserTypeSelected: '',//this works fine in signup.blade.php
        signInUserTypeSelected: ''//this does not work in signin blade php
    },

So when I declare and create a new data named sing-in.blade.php

@extends('layouts.app')

@section('title', 'sign-up')

@section('content')

<div class="form-group">
      <select class="form-control c-select" v-model="signInUserTypeSelected" name="user_type" required>
        <option disabled value="">Login as</option>
          <option>Parent</option>
          <option>Student</option>
          <option>Teacher</option>
      </select>
    </div>

Now vue is giving me a warning for signInUserTypeSelected.

[Vue warn]: Property or method "signInUserTypeSelected" is not defined on the instance but referenced during render. Make sure to declare reactive data properties in the data option.

(found in <Root>)

I guess I am doing something wrong with the partial and the id="app", Sorry I am new with vue js so I am struggling with this.

11th July, 2017

eddy1992 left a reply on Property Or Method "test" Is Not Defined On The Instance But Referenced During Render.... • 6 months ago

@lars6 thanks for your response but I tried it, It gave me the same error.

eddy1992 started a new conversation Property Or Method "test" Is Not Defined On The Instance But Referenced During Render.... • 6 months ago

Hi I am facing an error with vue, I have a Laravel 5.4 project and I installed and performed all the necessary steps to get laravel mix up and running. Now I am trying to perform a simple hello world using vue in my laravel project in app.js I am facing an warning

app.js:32213 [Vue warn]: Property or method "test" is not defined on the instance but referenced during render. Make sure to declare reactive data properties in the data option.

(found in <Root>)

my app.js


/**
 * First we will load all of this project's JavaScript dependencies which
 * includes Vue and other libraries. It is a great starting point when
 * building robust, powerful web applications using Vue and Laravel.
 */

require('./bootstrap');

window.Vue = require('vue');

/**
 * Next, we will create a fresh Vue application instance and attach it to
 * the page. Then, you may begin adding components to this application
 * or customize the JavaScript scaffolding to fit your unique needs.
 */

Vue.component('example', require('./components/Example.vue'));

const app = new Vue({
    el: 'body',
    data: {
        test: 'hello world'
    }
});


and In the front end whenever I try to call @{{ test }} I am facing this warning and I am frustrated now Please assist.

7th July, 2017

eddy1992 started a new conversation Laravel Mix • 6 months ago

I am just trying to bundle all my js and css into one file. I assume its a good idea right ? Please correct me if I am wrong. Now my webpack.mix.js looks something like this -:

mix.js([

        'resources/assets/js/app.js',
        'public/js/plugins/tether/dist/js/tether.min.js',
        'public/js/plugins/jQuery-Storage-API/jquery.storageapi.min.js',
        'public/js/plugins/jquery-pjax/jquery.pjax.js',
        'public/js/plugins/blockUI/jquery.blockUI.js',
        'public/js/plugins/jscroll/jquery.jscroll.min.js',

    ], 'public/js/app.js')

    .scripts([

        'public/js/scripts/config.lazyload.js',
        'public/js/scripts/ui-load.js',
        'public/js/scripts/ui-jp.js',
        'public/js/scripts/ui-include.js',
        'public/js/scripts/ui-device.js',
        'public/js/scripts/ui-form.js',
        'public/js/scripts/ui-modal.js',
        'public/js/scripts/ui-nav.js',
        'public/js/scripts/ui-list.js',
        'public/js/scripts/ui-screenfull.js',
        'public/js/scripts/ui-scroll-to.js',
        'public/js/scripts/ui-toggle-class.js',
        'public/js/scripts/ui-taburl.js',
        'public/js/scripts/app-dev.js',
        'public/js/scripts/ajax.js',
        'public/js/scripts/flickity.pkgd.min.js',
        'public/js/scripts/index.js',
        'public/js/scripts/jquery.fancybox.js',

    ], 'public/js/app.js')

    .styles([

        'public/css/plugins/animate.css/animate.min.css',
        'public/css/plugins/glyphicons/glyphicons.css',
        'public/css/plugins/font-awesome/css/font-awesome.min.css',
        'public/css/plugins/material-design-icons/material-design-icons.css',
        'public/css/plugins/ionicons/css/ionicons.min.css',
        'public/css/plugins/simple-line-icons/css/simple-line-icons.css',
        'public/css/styles/bootstrap.min.css',
        'public/css/styles/app.css',
        'public/css/styles/style.css',
        'public/css/styles/font.css',
        'public/css/styles/jquery.fancybox.css',
        'public/css/styles/flickity.css',
        
    ], 'public/css/app.css')

   .sass('resources/assets/sass/app.scss', 'public/css');

But Its not working I must be doing something wrong please assist me on this as I new with laravel mix. Thank you.

eddy1992 started a new conversation Using Laravel Mix • 6 months ago

Hi I am new to laravel mix and bundle my assets. I have few html file like named index.html and signup.html and so on. When I see those html files source code I could see it is using many css and many third party css and js. For example it is using all these css -:

<link rel="stylesheet" href="css/animate.css/animate.min.css" type="text/css"/>
    <link rel="stylesheet" href="css/glyphicons/glyphicons.css" type="text/css"/>
    <link rel="stylesheet" href="css/font-awesome/css/font-awesome.min.css" type="text/css"/>
    <link rel="stylesheet" href="css/material-design-icons/material-design-icons.css" type="text/css"/>
    <link rel="stylesheet" href="css/ionicons/css/ionicons.min.css" type="text/css"/>
    <link rel="stylesheet" href="css/simple-line-icons/css/simple-line-icons.css" type="text/css"/>
    <link rel="stylesheet" href="css/bootstrap/dist/css/bootstrap.min.css" type="text/css" />
    <link href="https://fonts.googleapis.com/css?family=Open+Sans" rel="stylesheet">
    
    <!-- build:css css/styles/app.min.css -->
    <link rel="stylesheet" href="css/styles/app.css" type="text/css" />
    <link rel="stylesheet" href="css/styles/style.css" type="text/css" />
    <!-- endbuild -->
    <link rel="stylesheet" href="css/styles/font.css" type="text/css" />
    <link rel="stylesheet" href="css/fancybox/jquery.fancybox.css" type="text/css" />
    <link rel='stylesheet prefetch' href="css/flickity/flickity.css">

and its using all these js files -:

<script src="libs/jquery/dist/jquery.js"></script>
<!-- Bootstrap -->
<script src="libs/tether/dist/js/tether.min.js"></script>
<script src="libs/bootstrap/dist/js/bootstrap.js"></script>
<!-- core -->
<script src="libs/jQuery-Storage-API/jquery.storageapi.min.js"></script>
<script src="libs/PACE/pace.min.js"></script>
<script src="libs/jquery-pjax/jquery.pjax.js"></script>
<script src="libs/blockUI/jquery.blockUI.js"></script>
<script src="libs/jscroll/jquery.jscroll.min.js"></script>

<script src="scripts/config.lazyload.js"></script>
<script src="scripts/ui-load.js"></script>
<script src="scripts/ui-jp.js"></script>
<script src="scripts/ui-include.js"></script>
<script src="scripts/ui-device.js"></script>
<script src="scripts/ui-form.js"></script>
<script src="scripts/ui-modal.js"></script>
<script src="scripts/ui-nav.js"></script>
<script src="scripts/ui-list.js"></script>
<script src="scripts/ui-screenfull.js"></script>
<script src="scripts/ui-scroll-to.js"></script>
<script src="scripts/ui-toggle-class.js"></script>
<script src="scripts/ui-taburl.js"></script>
<script src="scripts/app.js"></script>
<script src="scripts/ajax.js"></script>
<script src="scripts/plugins/flickity.pkgd.min.js"></script>
<script src="scripts/index.js"></script>
<script src="scripts/index.js"></script>
<script src="scripts/plugins/jquery.fancybox.js"></script>

Now what I see is these are a lot of js and css file, so my first question is should I add all these css and js folders in my laravel project and then compile of them to app.css and app.js using Laravel mix ? Is this how it is done ? and please correct me if I am wrong or suggest some more ideas about how should I proceed with it. Thank You.

23rd June, 2017

eddy1992 started a new conversation Vue 1 Or Vue 2 • 6 months ago

Hi I have just started to learn about vue 1 tutorial from laracast and I am enjoying every bit of it but I am concerned about one thing , should I invest on Vue 1 and learn it first or should I straight start with vue 2 ? What do you guys suggest ?

16th June, 2017

eddy1992 started a new conversation How To Get More Contents From Url Using Curl • 7 months ago

HI I have a function to get the contents from a url using the curl and its called file_get_contents_curl($url); Now the issue is I am getting only limited contents what we want to do is download more content, possible couple of paragraph and save it in our database.

function file_get_contents_curl($url) {
        $agent = 'Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; SV1; .NET CLR 1.0.3705; .NET CLR 1.1.4322)';

        $ch = curl_init();
        curl_setopt($ch, CURLOPT_HEADER, 1);
        curl_setopt($ch, CURLOPT_COOKIEJAR, 'cookie.txt');
        curl_setopt($ch, CURLOPT_COOKIEFILE, 'cookie.txt');
        curl_setopt($ch, CURLOPT_COOKIESESSION, 1);
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
        curl_setopt($ch, CURLOPT_URL, $url);
        //curl_setopt($ch, CURLOPT_REFERER, $url);
        //curl_setopt($ch, CURLOPT_URL, 'https://graph.facebook.com/v1.0/?id='. urlencode($url). '&scrape=1');
        //curl_setopt($ch, CURLOPT_POST, 1);
        curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
        //curl_setopt($ch, CURLOPT_MAXREDIRS,10);
        //curl_setopt($ch, CURLOPT_NOBODY, true); 
        //curl_setopt($ch, CURLOPT_CUSTOMREQUEST, 'GET');  
       
        curl_setopt($ch, CURLOPT_USERAGENT, $agent);
        curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
        //curl_setopt($ch, CURLOPT_VERBOSE, true);

        $data = curl_exec($ch);
        $info = curl_getinfo($ch, CURLINFO_CONTENT_TYPE);
        //$info = curl_getinfo($ch) ;
        $err = curl_error($ch);
        $http_code = curl_getinfo($ch, CURLINFO_HTTP_CODE);
        $eff_url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
        
        //checking mime types

        if(strstr($info,'text/html')) {
            curl_close($ch);
            return $data;
        } elseif(strstr($info,'text/plain')) {
            curl_close($ch);
            $data = shell_exec ('/usr/bin/curl' . ' ' . $url);
            return $data;
        } else {
            return false;
        }
    }

Please assist how will I achieve this behavior. Thank you.

13th June, 2017

eddy1992 started a new conversation Insert Into Db Using Array With Foreach • 7 months ago

Hi I have an array and I want to insert into the db now is there any way in which I could add the whole array to the db rather than doing foreach and looping and creating a new record.


$subjects = ['physics', 'maths', 'science', 'politics', 'engineering'];
foreach($subjects as $subject) {
    App\Subject::create['name' => $subject]);  // I dont want to do for each now. 
}

So what if I dont want to foreach and create a new record ? Please assist.

28th May, 2017

eddy1992 started a new conversation Links Not Opening In Linkedin App (laravel) • 7 months ago

Hi I have social website and people can share posts. When people share post they have the option to copy the link. Now I have a situation in which I paste the link in the Linkedin desktop website to share it it works fine, it works properly and when I click the link it opens and redirects me to the page.

Now the issue is when I perform the same step to paste the link in mobile linkedin app the link gets pasted and shared but when I click on the link their are no request parameters. It comes out an empty request array.

The link urls-: http://e7e3f263.ngrok.io/post/1248?SHARE=SHARE-OUID=83-COLID=164-UID=821024609-CID=pGgdW1-Pa1JSTXI2iyj-b2zcS-stamp=05282017090758

The method -: ```

public function editPost(Request $request, $postId){ $data = $request->all(); echo "

";
print_r($data); //on web I gt back the query string but in app I get empty array.
die;
}


The request I should get -: [SHARE] => SHARE-OUID=83-COLID=164-UID=821024609-CID=pGgdW1-Pa1JSTXI2iyj-b2zcS-stamp=05282017090758

If you try to share this url in website and try open it, it works fine I get the request object. But if you try to paste the same link in linkedin mobile app then I get an empty request array.

Please assist if some has any idea why this is happening. Thank you.

4th May, 2017

eddy1992 started a new conversation Incremental Api Screen Cast With Laravel 5.4 • 8 months ago

Hi I am going through Laracast Incremental api screen cast https://laracasts.com/series/incremental-api-development and I am little confused about the authentication part of it. As the screen cast is using laravel 4. I am trying to learn about building REST Api from it and practicing it in Laravel 5.4. Now I am confused, should I use the token to authenticate the apis or should I use Laravel passport and if passport then why ?

10th April, 2017

eddy1992 started a new conversation Toggle Method Not Working • 9 months ago

Hi I have a relationship set between user and communitylink, there is a method named votes() which has the belongsToMany relationship on it.

in App\User.php 

public function votes()
    {
        return $this->belongsToMany(CommunityLink::class, 'community_links_votes')->withTimestamps(); 
    }

Now when I am trying to use the toggle method on the many to may relationship it gives me an error

public function store(CommunityLink $link)
    {   
   
        $check = auth()->user()->votes()->toggle($link);
        

        return back();
    }

I get an error

BadMethodCallException in Builder.php line 2405:
Call to undefined method Illuminate\Database\Query\Builder::toggle()

I am stuck please assist.

5th April, 2017

eddy1992 started a new conversation How To Use Hydrate Method In Eloquent ? • 9 months ago

Hi I want to know how to use the hydrate method in eloquent and save those records to database.

//$this->channels is an array. 
$channels = App\Channel::hydrate($this->channels); // this returns me a collection of multiple eloquent method, but how would I save it to the database. 

I am not able to save it to the db. Please assist.

9th March, 2017

eddy1992 started a new conversation Should I Learn Jquery ? • 10 months ago

Hi I am new to javascript. I am still learning the language and I am feeling a little comfortable with the language. Now I am in a position where I cant decide whether I should learn Jquery or should I straight dive into Vue js. I am wondering is it worth learning jquery today ?

15th February, 2017

eddy1992 started a new conversation Convert This 06 December 1899 - 12:00 AM To Timestamp • 11 months ago

Hi I want to know how will I convert this to the timestamp format that laravel uses to save it in the database.

Please assist thank you.

2nd February, 2017

eddy1992 left a reply on Pass Html In File::put() • 11 months ago

Thank you for your response @SaeedPrez

1st February, 2017

eddy1992 started a new conversation Pass Html In File::put() • 11 months ago

Hi I have a method that create a blade file for me

/**
     * Get the view full path.
     *
     * @param string $view
     *
     * @return string
     */
    public function viewPath($view)
    {
        $view = str_replace('.', '/', $view) . '.blade.php';
        $path = base_path("resources/views/{$view}");
        return $path;
    }

  //this is the method
  public function handle()
  {
    $path = $this->viewPath($viewName); 
    File::put($path, ''); //how will I pass html in it .
  }

I want to pass html when putting in the File.

for example I want to pass this html when the blade is created.

<!DOCTYPE html>
<html>
<head>
    <title></title>
</head>
<body>
    <h1>{{ $data->title }}</h1>
    <p>{!! $data->body !!}</p>
</body>
</html>

Please assist.

Thank you.

eddy1992 left a reply on How To Create A View Dynamically In Laravel • 11 months ago

Thanks @cipsas for your answer.

30th January, 2017

eddy1992 started a new conversation Issue When Create A Directory And Blade File In Resources Folder From Artisan Command • 11 months ago

Hi I have created an artisan command to create a blade file template. The artisan command looks something like this-:

<?php

namespace App\Console\Commands;

use Illuminate\Console\Command;
use File;

class MakeViews extends Command
{
    
    /**
     * The name and signature of the console command.
     *
     * @var string
     */
    protected $signature = 'make:view {viewName}';


    /**
     * The console command description.
     *
     * @var string
     */
    protected $description = 'create a new blade template';


    /**
     * Create a new command instance.
     *
     * @return void
     */
    public function __construct()
    {
        parent::__construct();
    }


    /**
     * Execute the console command.
     *
     * @return mixed
     */
    public function handle()
    {   
        $viewName = $this->argument('viewName');
        $path = $this->viewPath($viewName);
        $this->createDir($path);

        if (File::exists($path)){
            $this->error("File {$path} already exists!");
            return;
        }

        File::put($path, '');
        $this->info("File {$path} created.");
    }


    /**
     * Get the view full path.
     *
     * @param string $view
     *
     * @return string
     */
    public function viewPath($view)
    {
        $view = str_replace('.', '/', $view) . '.blade.php';
        $path = "resources/views/{$view}";
        return $path;
    }


    /**
     * Create view directory if not exists.
     *
     * @param $path
    */
    public function createDir($path)
    {
        $dir = dirname($path);
        
        if (!file_exists($dir)){

            mkdir($dir, 0777, true);
        }
    }
}

now when I call php artisan make:view newBladeDirectory.newBlade so this would create it in the

resources/views/newBladeDirectory/newBlade.blade.php 

with no problem. But the strange thing is that when I call the Artisan command from the route it creates the file and the directory in the public folder

Route::get('create-blade', function(){

   $execute =  Artisan::call('make:view', ['viewName' =>            'createAnotherBladeDirectory.anotherBlade']);
   dd($execute);

});

I do not know why It gets created in the public folder when I am calling the artisan command from the code or the route but at the same time when I am calling the command from the console it creates properly in the resource folder as I had mentioned in the code.

Please assist. Thank you.

Edit Your Profile
Update

Want to change your profile photo? We pull from gravatar.com.