screwtape_mk

screwtape_mk

Member Since 1 Year Ago

Experience Points 2,890
Experience Level 1

2,110 experience to go until the next level!

In case you were wondering, you earn Laracasts experience when you:

  • Complete a lesson — 100pts
  • Create a forum thread — 50pts
  • Reply to a thread — 10pts
  • Leave a reply that is liked — 50pts
  • Receive a "Best Reply" award — 500pts
Lessons Completed 1
Lessons
Completed
Best Reply Awards 0
Best Reply
Awards
  • start-engines Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-session Created with Sketch.

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • subscriber-token Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer-token Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • lara-evanghelist Created with Sketch.

    Laracasts Evangelist

    Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.

  • chatty-cathy Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

09 Jul
1 week ago

screwtape_mk left a reply on Unique Values On A Collection

Ok atleast when you apply a get() then it becomes a collection. I will now try your suggested solutions and their various permutations to see if they work. Most did not but i guess it must have had to do with the Builder object

screwtape_mk left a reply on Unique Values On A Collection

What im now realising is that $ServicesCollection is not a collection but something i believe known as a Builder

and $ServicesCollection:


Builder {#189 ▼
  #query: Builder {#188 ▼
    #connection: MySqlConnection {#183 ▼
      #pdo: PDO {#184 ▼
        inTransaction: false
        attributes: array:13 [▼
          "CASE" => NATURAL
          "ERRMODE" => EXCEPTION
          "AUTOCOMMIT" => 1
          "PERSISTENT" => false
          "DRIVER_NAME" => "mysql"

.
.
.

So it appears that something in how i'm defining my model is amiss. This article

https://medium.com/@Eddy_mens/knowing-when-its-a-model-or-a-builder-laravel-822f393e578e

explains something to the effect of:

So as you would imagine if you have a model instance the first point of reference of the method will be from the Model class and if not found will be looked up from the Query Builder. More or less like method overriding in the case of inheritance.

08 Jul
2 weeks ago

screwtape_mk left a reply on Unique Values On A Collection

you mean iside the model. ok will try that

screwtape_mk left a reply on Unique Values On A Collection

if by that you mean:

 $ServicesCollection=ServiceAreas::where('EmployeeService','LIKE','%pai%')
                                    ->unique('EmployeeService')
                                    ->take(5)
                                    ->get();

then it has the error:

Call to undefined method Illuminate\Database\Query\Builder::unique()

my model(ServiceAreas):

<?php namespace App\Models;


use Illuminate\Database\Eloquent\Model;



class ServiceAreas extends Model 
{


    
    protected $table = 'AREAS';
    
    public $incrementing=false;
    
    }

screwtape_mk left a reply on Unique Values On A Collection

using your suggested solution returns an empty set. When using my method with the explicit unique('EmployeeService') I get the output as in the question above, still duplicated.

screwtape_mk started a new conversation Unique Values On A Collection

I am failing to get unique values / entries in my collection. Query im running to get unique entries is:

        $ServicesCollection=ServiceAreas::where('EmployeeService','LIKE','%pai%')
                                    ->take(5)
                                    ->get();
                                    
        
       
                                
        $EmployeeServices = $ServicesCollection->map(function ($Services) {
                    return collect($Services->toArray())
                            ->only(['EmployeeService'])
                            ->unique()
                            ->all();
                            });

The outcome / dd($EmployeeServices ) is :


Collection {#182 ▼
  #items: array:5 [▼
    0 => array:1 [▼
      "EmployeeService" => "Painter"
    ]
    1 => array:1 [▼
      "EmployeeService" => "Painter"
    ]
    2 => array:1 [▼
      "EmployeeService" => "Painter"
    ]
    3 => array:1 [▼
      "EmployeeService" => "Garage Door Electrical Repairs/Install"
    ]
    4 => array:1 [▼
      "EmployeeService" => "Electrician, Gate Repairs"
    ]
  ]
}

This `` "EmployeeService" => "Painter"``` appears 3 times when i need it to appear only once

screwtape_mk left a reply on Using A Model Instead Of \DB::table

,,,thanks,,, or '''thanks'''

screwtape_mk left a reply on Using A Model Instead Of \DB::table

The variable actually works - what was failing was the subsequent query i had, which is not shown in here. That test process for debugging proved useful. Thanks. Quick one: whats the keyboard shortcut for this : ``` hate copying and pasting each time lol

06 Jul
2 weeks ago

screwtape_mk left a reply on Using A Model Instead Of \DB::table

not a bad idea - i will try that thanks

screwtape_mk left a reply on Using A Model Instead Of \DB::table

thats not the issue

screwtape_mk left a reply on Using A Model Instead Of \DB::table

i guess i need to split the problem into 2 parts.

  1. The question posed above

  2. How to debug and dd($countries)to see its content when its being rendered in an autocomplete suggestion list.

so to answer @siangboon question on what i mean by "it did not work" - the autocomplete list doesn't come up.

@snapey suggested in one thread using php artisan dump-server but i'm on 5.1. I would then rather spend time upgrading to the latest version

05 Jul
2 weeks ago

screwtape_mk left a reply on Using A Model Instead Of \DB::table

this too did not work

screwtape_mk left a reply on How To Print Something In Laravel Console

is dump server available for versions 5.1 of laravel

screwtape_mk started a new conversation Using A Model Instead Of \DB::table

Hi

I have a variable

$countries=\DB::table('AREAS');

works fine but the minute i use a model it ceases to work:

$countries=ServiceAreas::all();

The Model is ServiceAreas.php:

<?php namespace App\Models;


use Illuminate\Database\Eloquent\Model;



class ServiceAreas extends Model 
{
    
    protected $table = 'AREAS';
    

    }

screwtape_mk left a reply on How To Print Something In Laravel Console

How does this differe from tinker?

screwtape_mk left a reply on Symfony\Component\Debug\Exception\FatalErrorException] Cannot Use 'PhpParser\Node\Scalar\String' As Class Name As It Is Reserved

Ok Atleast my app is back on after commenting out

'Barryvdh\Debugbar\ServiceProvider'

But i sort of still need tinker - unless theres another way of showing contents of variables in controllers on the commandline/console

screwtape_mk left a reply on Symfony\Component\Debug\Exception\FatalErrorException] Cannot Use 'PhpParser\Node\Scalar\String' As Class Name As It Is Reserved

after running composer update now my whole application throws this exception:

Class 'Barryvdh\Debugbar\ServiceProvider' not found

screwtape_mk left a reply on Symfony\Component\Debug\Exception\FatalErrorException] Cannot Use 'PhpParser\Node\Scalar\String' As Class Name As It Is Reserved

i just did and i continue to have an error

Uncaught TypeError: Argument 1 passed to App\Exceptions\Handler::report() must be an instance of Exception, instance of Error given, called in .../vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/HandleExceptions.php on line 73 and defined in .../app/Exceptions/Handler.php:25

screwtape_mk left a reply on Laravel 5.0, Error With Tinker On Php7 ('String' Is A Special Class Name Error)

did @mike12345 end up voting the correct answer here? I am having the same issue and dont want to update my version of laravel just yet.

screwtape_mk started a new conversation Symfony\Component\Debug\Exception\FatalErrorException] Cannot Use 'PhpParser\Node\Scalar\String' As Class Name As It Is Reserved

I was trying to run : php artisan tinker on the cmd line and encountered this weird error. any ideas

screwtape_mk left a reply on How To Print Something In Laravel Console

@birbird did u come right on this. I am also looking to output some variable(s) in my controller. But i want to do it on the console.

04 Jul
2 weeks ago

screwtape_mk left a reply on Why Keys When Accessing A Cache

Thanks Guys- for a beginner this helps in grasping the concepts - copying a solution as is without understanding concepts isnt the greatest idea

screwtape_mk left a reply on Why Keys When Accessing A Cache

so a key is like a short-hand query?

screwtape_mk started a new conversation Why Keys When Accessing A Cache

I am trying to learn the basics of caching a database query. There is plenty of examples on how to do so. Except i want to also understand the concept/theory of caching in laravel. None of the material ive seen actually bothers to explain why you need a cache key. SO why must u have a key to access a cache?

13 Jun
1 month ago

screwtape_mk left a reply on Optimizing Eloquent Query

@SNAPEY - Please elaborate what needs disabling. Its not so much that i have found a delay or its cause thereof...its really more like i observed a delay - please elaborate on what needs disabling. Is there anything you can pick up on the js above that suggest the i might be be using the autocomplete library wrongly or the min length option

screwtape_mk left a reply on Optimizing Eloquent Query

@CRONIX - if you look at the js i posted above i am using $(this).autocomplete({ and minLength: 0. i am now just gonna move on to caching and see how that improves speed

12 Jun
1 month ago

screwtape_mk left a reply on Optimizing Eloquent Query

@CRONIX - I really think the problem here is if you typing it waits until you finish typing to send the Ajax request. Thats why it appears slow since it waits for the typing to stop. What it must do is start sending ajax as you type - maybe after 2 characters or so

screwtape_mk left a reply on Optimizing Eloquent Query

@CRONIX - when i type and then stop then it sends a single ajax request. I typed "Pai" and it sent:

http://spanibox.com/searchajax?term=pai&type=EmpService

when i typed slowly like 1st "P" and then "a" then it sent 2 requests:

http://spanibox.com/searchajax?term=p&type=EmpService

and

http://spanibox.com/searchajax?term=p&type=EmpService

respectively

screwtape_mk left a reply on Optimizing Eloquent Query

@CRONIX - I had not seen your update - let me do what u reccommended!.

screwtape_mk left a reply on Optimizing Eloquent Query

If its of any significance the javascript handling the typing event is as follows:

$(document).on('focus','.autocomplete_txt',function(){
  type = $(this).data('type');
  
  if(type =='EmpService' )autoType='EmployeeService'; 
  
 
  
   $(this).autocomplete({
       minLength: 0,
       source: function( request, response ) {
            $.ajax({
                url: SPANIBOX.search_ajax,
                dataType: "json",
                data: {
                    term : request.term,
                    type : type,
                },
                success: function(data) {
                    var array = $.map(data, function (item) {
                       return {
                           label: item[autoType],
                           value: item[autoType],
                           data : item
                       }
                   });
                    response(array)
                }
            });
       },
       select: function( event, ui ) {
           var data = ui.item.data;           
           id_arr = $(this).attr('id');
           id = id_arr.split("_");
           elementId = id[id.length-1];
           $('#EmpService_'+elementId).val(data.name);
           
       }
   })
   
   });

screwtape_mk left a reply on Optimizing Eloquent Query

Debugbar seem to require laravel 5.1 and abover - im using 5.0

11 Jun
1 month ago

screwtape_mk left a reply on Optimizing Eloquent Query

i also suspect my javascript event handler might be an issue - the auto complete is fast when you type just one character and wait - its extremely slow when u type several characters - its as though it waits for you to finish typing then send that as the term to search for - maybe it would work best to return a suggested list based on the first 2 characters typed

screwtape_mk left a reply on Optimizing Eloquent Query

I ended up with:

        $query1 = $request->get('term','');
        $countries=\DB::table('MY_TABLE');
        if($request->type=='EmpService')
        
            {
                $countries->select('EmployeeService')
                            ->where('EmployeeService','LIKE',$query1.'%')
                            ->distinct()
                            ->take(5)
                            ->get();
            }
      
           $countries=$countries->get();        
        
            return $countries;
    }

Not much improvement still. What i will end up doing is caching. i don't want to move this to cloud server just yet.

screwtape_mk left a reply on Optimizing Eloquent Query

@NASH - When checking the network tab on chrome dev tools Waiting (TTBF) is about 600ms and initial connection averages 300ms - which makes it a total of 1s and that enough time to finish typing a word without a suggestion list.

You suggested modification doesn't return anything - only "Internal Error 500" in the console log. Not sure what could be wrong

10 Jun
1 month ago

screwtape_mk left a reply on Optimizing Eloquent Query

I have made these changes and i dont see any improvements. in fact i think there might have been a miniscule deterioration in speed.

    public function searchResponse(Request $request){
        $query1 = $request->get('term','');
        $countries=\DB::table('MY_TABLE');
        if($request->type=='EmpService')
        
            {
                $countries->where('EmployeeService','LIKE',$query1.'%')
                            ->groupBy('EmployeeService')
                            ->take(5)
                            ->get();
            }
      
           $countries=$countries->get();        
        
            return $countries;
    }

Do you have anymore suggestions around optimizing this snippet? I want to maybe move into Caching and see if that will work.

screwtape_mk left a reply on Optimizing Eloquent Query

@SNAPEY - Yes the grouping is for unique values.

09 Jun
1 month ago

screwtape_mk left a reply on Optimizing Eloquent Query

@NASH - I did a take(5) as suggested not much change. Do you mind showing where exactly would i put the select EmployeeService from statement

screwtape_mk started a new conversation Optimizing Eloquent Query

I have an autocomplete text box that works well. I need to increase speed of the drop down list. Its too long - you can finish typing before it suggest anything. I have indexed the table and no improvements. So right now I just want to break down the problem into smaller pieces. Lets for now look at the eloquent query itself. Is this the most optimal I could have written it? I got this off the Internet so im not exactly sure why it was written this way it just works- I guess this is how I get to understand the query and optimizing it:

        $query1 = $request->get('term','');
        $countries=\DB::table('T_EMPLOYEE_SERVICE_AREAS');
        if($request->type=='EmpService')
        
            {
                $countries->where('EmployeeService','LIKE',$query1.'%')
                            ->groupBy('EmployeeService')
                            ->get();
            }
      
           $countries=$countries->get();        
        $data=array();
        foreach ($countries as $country) {
                $data[]=array('EmployeeService'=>$country->EmployeeService);
        }
        if(count($data))
             return $data;
        else
            return ['EmployeeService'=>''];

16 May
2 months ago

screwtape_mk started a new conversation Ajax And Laravel Autocomplete Slow

I have a form with automplete feature as you type. The feature is slow. An average typing speed is faster than the autocomplete list. You can finish typing before the suggestion pops out. it uses jquery to and makes an ajax call to a URL which calls a function within a controller that then runs all the list containing the typed string:

 public function searchResponse(Request $request){
        $query1 = $request->get('term','');
        $c1=\DB::table('T_EMPLOYEE_SERVICE_AREAS');
        if($request->type=='EmpService')
        
            {
                $c1->where('EmployeeService','LIKE','%'.$query1.'%')
                            ->groupBy('EmployeeService')
                            ->get();
            }
      
           $c1=$c1->get();        
        $data=array();
        foreach ($c1 as $service) {
                $data[]=array('EmployeeService'=>$service->EmployeeService);
        }
        if(count($data))
             return $data;
        else
            return ['EmployeeService'=>''];
    }
    

Aside from maybe optimizing the above query - how would i go about checking where the the most time is spent. The network tab in the chrome developer tools only showed me how long the url that gets called took and its about 700ms.

I have added a link of the exact same autocomplete script i got from another forum

http://www.expertphp.in/article/laravel-5-autocomplete-mutiple-fields-using-jquery-ajax-and-mysql

22 Apr
3 months ago

screwtape_mk left a reply on Unexpected Else

Thank you very helpful

screwtape_mk left a reply on Unexpected Else

@DALMA - any documentation link on this?

because now i have :

@if 
    @if 
        @if 

without an @else condition. Would i need to make it

@if 
    @if 
        @if 

        @endif 

    @endif 

@endif

``
?
20 Apr
3 months ago

screwtape_mk left a reply on Trying To Get Property Of Non-object

@ASHRAAM - It turns out that it wasnt $bookingPayments that was causing issues but another variable and have fixed it thanks

18 Apr
3 months ago

screwtape_mk left a reply on Trying To Get Property Of Non-object

@SERGIU17 - ``` dd($bookingPayments);

I had already done and is shown in the question i posted

Collection {#199 ▼ #items: array:2 [▼ 0 => UserPayments {#202 ▶} 1 => UserPayments {#203 ▶} ] }

Then

dd($bookingPayments->first());

Gives the first item: 

0 => UserPayments {#202 ▶}

Then

dd($bookingPayments->first()->employee_id);


outputs the employee_id I am looking for. I am assuming that all these dd are to be done within the controller 'cause thats the only i know how.

The problem seems to be when the same gets applied in the view:

$Employee->id==$bookingPayments->first()->employee_id