mercredi 30 janvier 2019

Laravel observer Update Event in not Triggering

i am trying to update my remaining_quantity by decreasing the checked_out_quantity from the initial Quantity like this but its not working

public function updating(Consumable $consumable)
{
    $consumable->remaining_qty = $consumable->quantity - $consumable->checked_out_qty;
    $consumable->save();     
}   

anybody know how i can get it to trigger?



from Newest questions tagged laravel-5 - Stack Overflow http://bit.ly/2HNjbMS
via IFTTT

How to send email from multiple users to multiple users in laravel 5.7

I am making a site where people room owners upload their room for rent with their name and email Customers can come and see the room and send email to the room owner with their message from the site by filling up a forom which consist of Email , Name and your Message I dont know how to write that mail function I tried but failed If any one can help me plz ....



from Newest questions tagged laravel-5 - Stack Overflow http://bit.ly/2UtuYRS
via IFTTT

Trying to do multi auth using spatie laravel-permissions hasRoles

I am using Spatie Laravel Permissions to manage the permissions in my project and I am trying to use the hasRole() function for multi auth. I am using if conditions to redirect users to different pages. And its not working So Does some one have idea how to use spatie laravel permissions package to do multiauth.



from Newest questions tagged laravel-5 - Stack Overflow http://bit.ly/2UroIKs
via IFTTT

Laravel model object date value changed when print

I use Laravel framework and I have a strange issue, when I dump model object it return a true results for attributes:

@extends('frontend.includes.master')
@section('content')

<?php
dump($row); exit;
?>
<main class="main">
    <section class="banner banner--inner banner--short">
        <div class="container">

enter image description here

but when I dump or print the date value it give me a wrong result:

<?php
dump($row->start_date); exit;
?>

enter image description here

also this happen when I dump from view, but when I dump from controller it give me a true result:

$row = Forsah::with('company')->with('category')->with('region')->where('forsah.id', $id)->first();
        $data['row'] = $row;


        $data['user_forsah'] = false;
        if (Session::get('member_id')) {
            $user_forsah_row = UsersForsah::where('user_id', Session::get('member_id'))->where('forsah_id', $id)->first();
            if ($user_forsah_row) {
                $data['user_forsah'] = true;
            }
        }

        dump($row->start_date); exit;
        return view('frontend.forsah.show', $data);

enter image description here



from Newest questions tagged laravel-5 - Stack Overflow http://bit.ly/2Wuiw67
via IFTTT

FullCalendar switch events by user in vuejs

I have configured fullcalendar in vuejs, events of 3 members now i want to show hide users events on click.

Normal jQuery working perfect but i am new on vuejs so don't have idea how to do that.

$('#mycalendar').fullCalendar({
    events: [
        {
            title: 'Event 1',
            start: '2015-05-01',
            school: '1'
        },
        {
            title: 'Event 2',
            start: '2015-05-02',
            school: '2'
        },
        {
            title: 'Event 3',
            start: '2015-05-03',
            school: '1'
        },
        {
            title: 'Event 4',
            start: '2015-05-04',
            school: '2'
        }
    ],
    eventRender: function eventRender( event, element, view ) {
        return ['all', event.school].indexOf($('#school_selector').val()) >= 0
    }
});

$('#school_selector').on('change',function(){
    $('#mycalendar').fullCalendar('rerenderEvents');
})



from Newest questions tagged laravel-5 - Stack Overflow http://bit.ly/2Gg4csr
via IFTTT

How to check for a string against json encode array in a table in Laravel?

I am having an issue with a Laravel project. I have a few checkbox of computer specification which I want to check against the database field that I am having called tech_specs. This tech_specs field contains the serialize array of all the tech_specs that are available for that specific product. I just want to list out the products having that particular specification. Please let me know how to proceed.

Controller Function

public function GetPage(Request $request,$page_slug){

        $page_title=self::replaceAll($page_slug);
        $category_level1_id=null;
        $category_level2_id=null;
        $category_level3_id=null;
        $products=null;
        $products_count=null;
        $product_lookup=null;
        $page_breadcrumb=null;
        $product_type=null;
        $brand=null;
        $final_selected_brand=array();
        $tech_specs_filter=null;
        $specs_filters=null;

        //Sorting Vars
        $sort_by=$request->query('sort_by');
        $min_price=$request->query('min_price');
        $max_price=$request->query('max_price');

        //Filter Vars
        $product_condition=$request->query('product_condition');
        $product_brand=$request->query('brand');
        $is_assured=$request->query('assured');
        $is_cod_allowed=$request->query('cod');
        $product_specs=$request->query('tech_spec');


        $final_selected_brand=null;
        if(!empty($product_brand)){
            $final_selected_brand=explode('|',$product_brand);
        }

        $final_selected_brand_ids=null;
        if(!empty($final_selected_brand)){
            foreach($final_selected_brand as $fsb){
                $final_selected_brand_ids[]=self::GetBrandIDFromName($fsb);
            }
        }

        $final_selected_spec=null;
        if(!empty($product_specs)){
            $final_selected_spec=explode('|',$product_specs);
        }

        // Get the categories
        $getCatlvl1 = Category::whereCategorySlug($page_slug);
        $getCatlvl2 = SubCategory::whereCategorySlug($page_slug);
        $getCatlvl3 = SubCategoryLvl3::whereCategorySlug($page_slug);


        //Check if is category level 1
        if ($getCatlvl1->count()) {
            $category_level1_id = $getCatlvl1->pluck('id')->toArray();
            $product_type = $getCatlvl1->pluck('product_type')->toArray()[0];
            $category_level1_name = $getCatlvl1->pluck('category_name')->toArray()[0];

            $brand=Brand::where('product_type',$product_type)->orderBy('brand_name')->get();

            $category_level2_id = SubCategory::where('parent_category', $category_level1_id)
                ->pluck('id')
                ->toArray();

            $category_level3_id = SubCategoryLvl3::whereIn('parent_category', $category_level2_id)
                ->pluck('id')
                ->toArray();

            $product_lookup = DB::table('products')
                                ->where('is_approved','Yes')
                                ->where('category_level',3)
                                ->whereIn('category',$category_level3_id)
                                ->when($product_condition, function($query) use($product_condition){
                                    $query->where('product_condition', $product_condition);
                                })
                                ->when($is_assured, function($query) use($is_assured){
                                    $query->where('is_assured','Yes');
                                })
                                ->when($is_cod_allowed, function($query) use($is_cod_allowed){
                                    $query->where('merchant_allowed_for_cod','Yes');
                                })
                                ->when($final_selected_brand_ids, function($query) use($final_selected_brand_ids) {
                                    if(count($final_selected_brand_ids)>1){
                                        $query->whereIn('brand',$final_selected_brand_ids);
                                    } else {
                                        $query->where('brand',$final_selected_brand_ids[0]);
                                    }
                                })
                                ->when($min_price and $max_price, function($query) use($min_price, $max_price) {
                                    if($min_price=='+50000'){
                                        $query->where('selling_price','>=',$min_price);
                                        $query->where('selling_price',$max_price);
                                    } else if($max_price=='+50000'){
                                        $query->where('selling_price',$min_price);
                                        $query->where('selling_price','>=',$max_price);
                                    } else {
                                        $query->whereBetween('selling_price', [
                                            $min_price,
                                            $max_price
                                        ]);
                                    }
                                })
                                ->when($sort_by, function($query) use($sort_by) {
                                    if($sort_by=='high-price'){
                                        $query->orderBy('selling_price', 'DESC');
                                    }
                                    if($sort_by=='low-price'){
                                        $query->orderBy('selling_price', 'ASC');
                                    }
                                    if($sort_by=='new-arrivals'){
                                        $query->orderBy('id', 'DESC');
                                    }
                                });

            $page_breadcrumb.= '<li class="breadcrumb-item active" aria-current="page">'.$category_level1_name.'</li>';
        }

        //Check if is category level 2
        if ($getCatlvl2->count()) {

            $category_level2_id = $getCatlvl2->pluck('id')->toArray();
            $product_type = $getCatlvl2->pluck('product_type')->toArray()[0];
            $category_level2_name = $getCatlvl2->pluck('category_name')->toArray()[0];

            $brand=Brand::where('product_type',$product_type)->orderBy('brand_name')->get();

            $parent_id = $getCatlvl2->pluck('parent_category')->toArray()[0];
            $get_cat_parent_id = Category::where('id',$parent_id)->get()->toArray()[0];
            $category_level1_name = $get_cat_parent_id['category_name'];
            $category_level1_link = $get_cat_parent_id['category_slug'];

            $category_level3_id = SubCategoryLvl3::whereIn('parent_category', $category_level2_id)
                ->pluck('id')
                ->toArray();

            $product_lookup = DB::table('products')
                ->where('is_approved','Yes')
                ->where('category_level',3)
                ->whereIn('category',$category_level3_id)
                ->when($product_condition, function($query) use($product_condition){
                    $query->where('product_condition', $product_condition);
                })
                ->when($is_assured, function($query) use($is_assured){
                    $query->where('is_assured','Yes');
                })
                ->when($is_cod_allowed, function($query) use($is_cod_allowed){
                    $query->where('merchant_allowed_for_cod','Yes');
                })
                ->when($final_selected_brand_ids, function($query) use($final_selected_brand_ids) {
                    if(count($final_selected_brand_ids)>1){
                        $query->whereIn('brand',$final_selected_brand_ids);
                    } else {
                        $query->where('brand',$final_selected_brand_ids[0]);
                    }
                })
                ->when($min_price and $max_price, function($query) use($min_price, $max_price) {
                    if($min_price=='+50000'){
                        $query->where('selling_price','>=',$min_price);
                        $query->where('selling_price',$max_price);
                    } else if($max_price=='+50000'){
                        $query->where('selling_price',$min_price);
                        $query->where('selling_price','>=',$max_price);
                    } else {
                        $query->whereBetween('selling_price', [
                            $min_price,
                            $max_price
                        ]);
                    }
                })
                ->when($sort_by, function($query) use($sort_by) {
                    if($sort_by=='high-price'){
                        $query->orderBy('selling_price', 'DESC');
                    }
                    if($sort_by=='low-price'){
                        $query->orderBy('selling_price', 'ASC');
                    }
                    if($sort_by=='new-arrivals'){
                        $query->orderBy('id', 'DESC');
                    }
                });

            $page_breadcrumb.= '<li class="breadcrumb-item"><a href="'.url('/').'/'.$category_level1_link.'">'.$category_level1_name.'</a></li>';
            $page_breadcrumb.= '<li class="breadcrumb-item active">'.$category_level2_name.'</li>';

        }

        //Check if is category level 3
        if ($getCatlvl3->count()) {
            $category_level3_id = $getCatlvl3->pluck('id')->toArray();
            $product_type = $getCatlvl3->pluck('product_type')->toArray()[0];
            $category_level3_name = $getCatlvl3->pluck('category_name')->toArray()[0];

            $brand=Brand::where('product_type',$product_type)->orderBy('brand_name')->get();

            $matchThese=["product_type"=>$product_type,"category"=>$category_level3_id,"category_level"=>3];
            $tech_specs_filter=TechSpecsFilter::where($matchThese)->get()->toArray();

            if(!empty($tech_specs_filter)){
                $temp=$tech_specs_filter[0];
                $specs_filters=json_decode($temp['filter_specs']);
            }

            $parent_id_lvl2 = $getCatlvl3->pluck('parent_category')->toArray()[0];
            $get_cat_parent_id_lvl2 = SubCategory::where('id',$parent_id_lvl2)->get()->toArray()[0];

            $category_level2_name = $get_cat_parent_id_lvl2['category_name'];
            $category_level2_link = $get_cat_parent_id_lvl2['category_slug'];

            $get_cat_parent_id = Category::where('id',$get_cat_parent_id_lvl2['parent_category'])->get()->toArray()[0];
            $category_level1_name = $get_cat_parent_id['category_name'];
            $category_level1_link = $get_cat_parent_id['category_slug'];

            $product_lookup = DB::table('products')
                ->where('is_approved','Yes')
                ->where('category_level',3)
                ->whereIn('category',$category_level3_id)
                ->when($product_condition, function($query) use($product_condition){
                    $query->where('product_condition', $product_condition);
                })
                ->when($is_assured, function($query) use($is_assured){
                    $query->where('is_assured','Yes');
                })
                ->when($is_cod_allowed, function($query) use($is_cod_allowed){
                    $query->where('merchant_allowed_for_cod','Yes');
                })
                ->when($final_selected_brand_ids, function($query) use($final_selected_brand_ids) {
                    if(count($final_selected_brand_ids)>1){
                        $query->whereIn('brand',$final_selected_brand_ids);
                    } else {
                        $query->where('brand',$final_selected_brand_ids[0]);
                    }
                })
                /*->when($final_selected_spec, function($query) use($final_selected_spec) {
                    if(count($final_selected_spec)>1){
                        //$query->whereIn('brand',$final_selected_spec);
                    } else {
                        $query->where('brand',$final_selected_spec[0]);
                    }
                })*/
                ->when($min_price and $max_price, function($query) use($min_price, $max_price) {
                    if($min_price=='+50000'){
                        $query->where('selling_price','>=',$min_price);
                        $query->where('selling_price',$max_price);
                    } else if($max_price=='+50000'){
                        $query->where('selling_price',$min_price);
                        $query->where('selling_price','>=',$max_price);
                    } else {
                        $query->whereBetween('selling_price', [
                            $min_price,
                            $max_price
                        ]);
                    }
                })
                ->when($sort_by, function($query) use($sort_by) {
                    if($sort_by=='high-price'){
                        $query->orderBy('selling_price', 'DESC');
                    }
                    if($sort_by=='low-price'){
                        $query->orderBy('selling_price', 'ASC');
                    }
                    if($sort_by=='new-arrivals'){
                        $query->orderBy('id', 'DESC');
                    }
                });

            $page_breadcrumb.= '<li class="breadcrumb-item"><a href="'.url('/').'/'.$category_level1_link.'">'.$category_level1_name.'</a></li>';
            $page_breadcrumb.= '<li class="breadcrumb-item"><a href="'.url('/').'/'.$category_level2_link.'">'.$category_level2_name.'</a></li>';
            $page_breadcrumb.= '<li class="breadcrumb-item active">'.$category_level3_name.'</li>';
        }

        $temp_products =  $product_lookup->get();

        if(count($temp_products)>0){
            $products_count = $product_lookup->get()->count();
            $products = $product_lookup->paginate(50);
        }

        //Category Tree
        $content='<ul class="category-page-tree">';
        $get_category_tree_cat_level1 = Category::orderBy('category_name')->get();
        foreach($get_category_tree_cat_level1 as $gct1){
            $content.='<li>';
                $content.='<a href="'.url('/').'/'.$gct1->category_slug.'" class="level1_cat_color"><i class="fas fa-angle-right"></i> '.$gct1->category_name.'</a>';
                $get_category_tree_cat_level2 = SubCategory::orderBy('category_name')
                    ->where('parent_category',$gct1->id)
                    ->get();
                $content.='<ul>';
                    foreach($get_category_tree_cat_level2 as $gct2){
                        $content.='<li>';
                            $content.='<a href="'.url('/').'/'.$gct2->category_slug.'" class="level2_cat_color"><i class="fas fa-angle-right"></i> '.$gct2->category_name.'</a>';
                            $get_category_tree_cat_level3 = SubCategoryLvl3::orderBy('category_name')
                                ->where('parent_category',$gct2->id)
                                ->get();
                            $content.='<ul>';
                            foreach($get_category_tree_cat_level3 as $gct3){
                                $content.='<li>';
                                $content.='<a href="'.url('/').'/'.$gct3->category_slug.'" class="level3_cat_color"><i class="fas fa-angle-right"></i> '.$gct3->category_name.'</a>';
                                $content.='</li>';
                            }
                            $content.='</ul>';
                        $content.='</li>';
                    }
                $content.='</ul>';
            $content.='</li>';
        }
        $content.='</ul>';


        return view("frontend.pages.category_page")->with(
            array(
                'products'=>$products,
                'products_count'=>$products_count,
                'page_slug'=>$page_slug,
                'page_breadcrumb'=>$page_breadcrumb,
                'product_type'=>$product_type,
                'brands'=>$brand,
                'page_title'=>$page_title,
                'category_tree'=>$content,
                'category_level_column'=>2,
                'min_price'=>$min_price,
                'max_price'=>$max_price,
                'selected_brand'=>(array)$final_selected_brand,
                'is_assured'=>$is_assured,
                'is_cod_allowed'=>$is_cod_allowed,
                'specs_filters'=>$specs_filters,
                'selected_specs'=>(array)$final_selected_spec,
            )
        );
    }

jQuery Code

$(document).on("click", ".tech_specs_filter_box input[type='checkbox']", function(e) {
        var selected_specs=$(this).val();
        var current_url=window.location.href;
        var page_slug=$("#page_slug").val();
        var url_parameters = [];
        var specs_append = [];

        //Parameters
        var product_condition = getParam('product_condition');
        var sort_by = getParam('sort_by');
        var min_price = getParam('min_price');
        var max_price = getParam('max_price');
        var brand = getParam('brand');
        var tech_spec = getParam('tech_spec');
        var to_add_quesion_mark='no';

        if($(this).prop("checked") == true){
            if(current_url.indexOf('?tech_spec') == -1){
                url_parameters.push('?tech_spec='+selected_specs);
            } else {
                if(current_url.indexOf('?tech_spec') !== -1){
                    specs_append.push('?tech_spec='+tech_spec);
                    specs_append.push('|'+selected_specs);
                    url_parameters.push(specs_append.join(""));
                } else if(current_url.indexOf('&tech_spec') !== -1){
                    specs_append.push('&tech_spec='+tech_spec);
                    specs_append.push('|'+selected_specs);
                    url_parameters.push(specs_append.join(""));
                } else if(current_url.indexOf('&tech_spec') !== -1) {
                    url_parameters.push('&tech_spec='+selected_specs);
                }
            }
        } else if($(this).prop("checked") == false) {

            var specsArr = [];
            $('.tech_specs_filter_box input:checked').each(function(index) {
                var temp_val=$(this).attr('id');
                specsArr.push($("#"+temp_val).val());
            });
            var getSpecStr = specsArr.join("|");

            if(getSpecStr!==""){
                if(current_url.indexOf('?tech_spec') !== -1){
                    url_parameters.push('?tech_spec='+getSpecStr);
                }
            } else {
                to_add_quesion_mark="yes";
            }
        }


        if(sort_by!==""){
            url_parameters.push('sort_by='+sort_by);
        }
        if(product_condition!==""){
            url_parameters.push('product_condition='+product_condition);
        }
        if(min_price!==""){
            url_parameters.push('min_price='+min_price);
        }
        if(max_price!==""){
            url_parameters.push('max_price='+max_price);
        }
        if(brand!==""){
            url_parameters.push('brand='+brand);
        }

        if(to_add_quesion_mark=='yes'){
            for(var i=0;i<url_parameters.length;i++){
                if(i==0) url_parameters[i] = '?'+url_parameters[i];
            }
        }

        target_location = url_parameters.join("&");
        window.location = page_slug+target_location;

    });

HTML View Tech Specs For the particular category that I have selected



from Newest questions tagged laravel-5 - Stack Overflow http://bit.ly/2Wwiiv9
via IFTTT

mardi 29 janvier 2019

How can I fetch from multi level array in Laravel eloquent?

My question is about fetching data from multi level array what is generated from Laravel Groupby method ( Eloquent) .

-array

array:1 [▼
  1 => array:3 [▼
    4 => array:1 [▼
      2 => array:7 [▼
        0 => array:7 [▶]
        1 => array:7 [▶]
        2 => array:7 [▶]
        3 => array:7 [▶]
        4 => array:7 [▶]
        5 => array:7 [▶]
        6 => array:7 [▶]
      ]
    ]
    3 => array:1 [▼
      1 => array:1 [▼
        0 => array:7 [▶]
      ]
    ]
    2 => array:1 [▼
      1 => array:1 [▼
        0 => array:7 [▶]
      ]
    ]
  ]
]


Actually my datatable is so-

{"4":{"2":[{"id":1,"technology_id":1,"subject_id":20,"session_id":4,"semester_id":2,"created_at":"2019-01-18 18:16:49","updated_at":"2019-01-18 18:16:49"},{"id":2,"technology_id":1,"subject_id":23,"session_id":4,"semester_id":2,"created_at":"2019-01-18 18:16:49","updated_at":"2019-01-18 18:16:49"},{"id":3,"technology_id":1,"subject_id":24,"session_id":4,"semester_id":2,"created_at":"2019-01-18 18:16:49","updated_at":"2019-01-18 18:16:49"},{"id":4,"technology_id":1,"subject_id":45,"session_id":4,"semester_id":2,"created_at":"2019-01-18 18:16:49","updated_at":"2019-01-18 18:16:49"},{"id":5,"technology_id":1,"subject_id":46,"session_id":4,"semester_id":2,"created_at":"2019-01-18 18:16:49","updated_at":"2019-01-18 18:16:49"},{"id":6,"technology_id":1,"subject_id":47,"session_id":4,"semester_id":2,"created_at":"2019-01-18 18:16:49","updated_at":"2019-01-18 18:16:49"},{"id":7,"technology_id":1,"subject_id":48,"session_id":4,"semester_id":2,"created_at":"2019-01-18 18:16:49","updated_at":"2019-01-18 18:16:49"}]},"3":{"1":[{"id":8,"technology_id":1,"subject_id":1,"session_id":3,"semester_id":1,"created_at":"2019-01-18 18:18:27","updated_at":"2019-01-18 18:18:27"}]},"2":{"1":[{"id":9,"technology_id":1,"subject_id":7,"session_id":2,"semester_id":1,"created_at":"2019-01-18 18:18:27","updated_at":"2019-01-18 18:18:27"}]}}

I expect view in html is so-

https://imgur.com/a/O03Iog0

Can anyone help?



from Newest questions tagged laravel-5 - Stack Overflow http://bit.ly/2CUZRaq
via IFTTT