SteveCove

SteveCove

Member Since 1 Year Ago

Experience Points
16,820
Total
Experience

3,180 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
137
Lessons
Completed
Best Reply Awards
4
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.

Level 4
16,820 XP
11 Jun
3 months ago

SteveCove left a reply on Laravel 5.8 Override Email Validation / Use 5.7 Rules

@JEKINNEY - thanks for your reply. My issue is with how to overwrite the built in email validation filter, to avoid having to document (and enforce) our own custom rule.

As a side note, this really should have come with a warning in the release notes for 5.8. Yes its technically valid, but i image the vast majority of users will not want this behavior.

SteveCove left a reply on Laravel 5.8 Override Email Validation / Use 5.7 Rules

@CRONIX - Great, that looks like a solid solution, thanks

SteveCove started a new conversation Laravel 5.8 Override Email Validation / Use 5.7 Rules

So i have just discovered that laravel 5.8 uses a new email validation rule, that is technically correct, but functionally useless for our app.

The short version is that [email protected] is technically a valid email:

https://github.com/laravel/ideas/issues/1555

So laravel 5.8 lets this through. Our app uses mailgun, which throws an exception when encountering these emails.

I realize we can create a custom validation rule, and update all our validators to use this instead, but then we have to remind all developers not to use the built in, familiar, documented 'email' validation rule, which feels wrong.

I would prefer to overwrite this new behavior, but am not sure where to start

09 May
4 months ago

SteveCove left a reply on Need Help With An Axios Problem

A few issues. axios is not a property of the object, so you don't need to prefix this., your API URL should have a protocol http://localhost... and the request body is stored in the data property of the axios response console.log(response.data)

I seem to remember trying to console.log the full response object myself, and never getting any output. I have no idea why this might be, perhaps I'm remembering wrong but worth a try

07 Mar
6 months ago

SteveCove left a reply on View Composer Alternative?

Cache the result, the longer you can cache it the better, but even a short time can have a dramatic effect on server performance if the site has many concurrent users

03 Mar
6 months ago

SteveCove left a reply on Understanding Models/migrations In Laravel V. C# VS Entityframework

Entity Framework and Eloquent are very different. The former follows the data mapper pattern, the latter active record.

If you want a mature data mapper solution in PHP you can use doctrine.

If you are happy to stick with active record (probably the best option if you are new to the framework, as the vast majority of docs and tutorials for laravel presume you are using Eloquent), but want you models to indicate what properties they have, you can use doc block @property hints.

There is also a laravel package that can read the DB and auto generated these for you, I think it's called laravel ide helper.

Talking of IDEs phpstorm the most complete solution by a long shot

23 Feb
6 months ago

SteveCove left a reply on Laravel 5.7 Documentation Offline PDF?

You could make a local copy with wget something like:

wget -r -np https://laravel.com/docs/5.7/
22 Feb
6 months ago

SteveCove left a reply on Controller <> Model Conflict?

In my opinion this makes the code much worse.

A great deal of effort has been made by the laravel team to make code read as close to spoken English, doing this removes that.

13 Feb
7 months ago

SteveCove left a reply on HomeController::index (Long Loading Time) Collection Issue

So did you profile it with blackfire.io? it will tell you exactly whats slow

10 Feb
7 months ago

SteveCove left a reply on Is There An Alternative And More Efficient Method That Loop Through A Collection?

Probably makes sense to fall back to the query builder and let the database do the hard work, with AVG function and GROUP BY

05 Feb
7 months ago

SteveCove left a reply on Policy Not Working. Always Return False

@munazzil that code is completely nonsensical

@hamza the simplest thing to do wqould be to set a breakpoint in the controller and step through the code

02 Feb
7 months ago

SteveCove left a reply on Time Between Queue Dispatch And The Job Being Processed

You are seeing the polling time for your workers. I'm sure you can configure this (can't remember where), but the lower the polling interval, the more load you will create at idle.

Generally queued work is slow, so an extra few seconds before starting is insignificant. What's you use case?

30 Jan
7 months ago

SteveCove left a reply on Using Model Event To Constraint CRUD Actions

This has a number of issues. First it couples your data layer to an http session, so you can't use queues or Cron jobs.

Second it feels wrong - conceptually events are used to add side effects, not control main execution flow (this is just personal preference).

26 Jan
7 months ago

SteveCove left a reply on Free Domain Emails

We simply tell new clients we don't host emails, 90% of the time they already have office365 anyway.

Of course we came to the decision the hard way, loosing money trying to fix email issues.

In the rare case that we take on a client that is unwilling to pay for email accounts from Microsoft or Gsuite, we use zoho.com. Zoho is basically a free Gsuite. It's amazing for a free service.

But in the long term, the best solution is to get better clients that take their business serious enough to pay for email!

25 Jan
7 months ago

SteveCove left a reply on Decide How To Extend A Model

Well, it can be avoided in more than one way im sure - the made up names make it hard to work out whats actually happening though, so i dont know what the best method would be.

I personally find it pretty rare to need a collection of multiple concrete types.

However, if that really is a requirement that cant be avoided by a better design, you can use eloquents hydrate method to create instances of the correct subtype

SteveCove left a reply on Decide How To Extend A Model

Ok, so it looks like inheritance is suitable:

https://tighten.co/blog/extending-models-in-eloquent

You mention in the OP that this is an issue as it requires multiple queries if you want both types of categories, but thats only the case if you need to branch based on type, eg:

foreach($collection as $item){
    if('SomeSubType' == get_class($item)){...}
    elseif('SomeOtherSubType' == get_class($item)){...}
}

Do you actually have this type of code?

SteveCove left a reply on Decide How To Extend A Model

This is an issue with active record based systems - the line between aggregate and singular behavior is lost.

Could you give an example of the difference between a regular Category and a SpecialCategory, in relation to singular behavior?

If the difference is purely in aggregate methods, then you can keep a single model and push all the aggregate methods into service class(es)

23 Jan
7 months ago

SteveCove left a reply on What Is The Right Way Of Reusing Model's Methods?

Reports are likely to span multiple entities (models in laravel), so logically it makes sense to create a reports service, place your methods in there, and inject the service where needed

Chances are you will end up using the query builder over models anyway once your reports get complex or your dataset large, so you would need to make this change sooner or later.

As a side note, fascades in laravel are essentially global static service locators, which are bad for lots of well documented reasons beyond testing.

Do not obfuscate your code with Real-Time Facades

22 Jan
7 months ago

SteveCove left a reply on Database Optimalization

1000 simple selects is nothing, likely to take a couple of seconds processing time, what's your concern?

What do you actually do in the job?

SteveCove left a reply on Admin Template Without Css/js Collission With Another Web Template

OK yes i see what you mean. Well i have bad news, no matter if you carefuly hand craft you admin interface elements to have non confilcting names etc, it will never work on an to_be_edited page containing arbitary css and javascript, since css and js are frequantly attached via element body p {} etc.

You either need to strip out css and js (breaking the WYSIWYG concept), or load the to_be_editied page in an iframe, which is what pretty much every front end editor does.

There is a nice tutorial here: http://blog.stackhive.com/post/137799349684/building-a-seamless-drag-and-drop-interface

What issues are y ou facing when you tried this approach?

SteveCove left a reply on Admin Template Without Css/js Collission With Another Web Template

An admin template is typically ran as a seperate section of the website, eg example.com/admin, so conflicts are fairly easy to avoid.

Perhaps you mean something else - could you elaborate?

SteveCove left a reply on HomeController::index (Long Loading Time) Collection Issue

Seven seconds is amazingly slow.

Is this on a local environment or a live server?

You need to profile the app to see whats slow - debugbar is a good basic option. If you are running in a linux environment, a free blackfire.io account would be even more useful.

19 Jan
8 months ago

SteveCove left a reply on How To Prevent Spam Using Vue And Laravel?

To answer your questions:

  1. Yes, some bots are based on headless browsers, and a custom bot designed specifically for your site will just post directly to the endpoint.

2.No, csrf protection has nothing to do with spam bots.

3.yes, certainly possible, though headless browser based bots that only fill visible fields won't be fooled, dito custom target bot.

How likely is your site to be a specifically targeted (eg a human write a custom bot just for your site)?

18 Jan
8 months ago

SteveCove left a reply on Laravel 5.6 - How To Authenticate API Using Sessions For Same Folder SPA?

Its hard to follow what changes you have made - you started by adding middleware to the api routes, then tried just adding all your routes in the routes\web.php file (which is what i would do).

Whats your current configuration?

17 Jan
8 months ago

SteveCove left a reply on Laravel 5.6 - How To Authenticate API Using Sessions For Same Folder SPA?

Sessions get created for every user, logged in or not (needed for csrf field).

If you are seeing multiple sessions in local dev (and you are not using multiple browsers /private tabs), then it looks like the cookie isn't being set properly. What are you seeing in Dev tools?

22 Dec
8 months ago

SteveCove left a reply on Using A For Loop On A PHP Multi-dimensional Array

You are overwriting $usm (and the other variables) in each iteration of the loop, so you will always end up with the last value. If you want to collect all the values, you need to push to an array:

$usm = ...
$all_usm[]=$usm;

SteveCove left a reply on Mailing Inconsistency

This is a good example of why the global helper methods and static facades are a bad idea.

Your models active_rented_listings method has a call to Auth::id which cannot work from a console command (because there is no current user).

SteveCove left a reply on Laravel GuzzleHttp Post Methods Is Not Responding .it Is Continuesly Loading

What we server are you using. The built in dev server (artisan:serve) is single threaded so cannot be used with a recursive request like this - it will hang forever

21 Dec
9 months ago

SteveCove left a reply on Adding New API Endpoint

Yes, if you need to use eloquent resources.

However you might be overthinking the problem.

It sounds like you already have working (non eloquent) model class to query the movie table, so you could just use that in controller and return a JSON response.

SteveCove left a reply on Portfolio Project Opinions

I would second the suggestion to make something that will actually be used, either by yourself or a specific end user.

Writing code is relatively simple, especially with the wealth of tutorials online nowadays.

Being able to understand a real world problem or business process, distil it down and map it to a software architecture is much much harder.

By creating a fictitious project, you will inadvertently design the problem to fit your solution, when it should be the other way around.

Also, use version control and descriptive commit messages, a VCS history showing how you have handled scope change and refactoring is far more useful to a (good) recruiter than the finished code

SteveCove left a reply on Adding New API Endpoint

The example uses an existing eloquent model (which is where the database work is done), that is passed to the resource via constructor. The resource itself has no knowledge of the database.

Do you have an eloquent model for your movie table?

SteveCove left a reply on Adding New API Endpoint

@kobear eloquent resources are not models, they are a transformation layer that works with models.

https://laravel.com/docs/5.7/eloquent-resources

@eudemon a resource takes an eloquent model as a constructor parameter, and transforms it into JSON. It does not connect to the database.

If you are not using eloquent (your code snippet looks like you are using query builder), then you will need to format the JSON yourself.

SteveCove left a reply on Adding New API Endpoint

Please show the relevant code, its not possible to help based on your description.

It sounds like you have created a resource controller without a corresponding eloquent model.

SteveCove left a reply on Mailing Inconsistency

As @mithrandir suggests, something is getting lost in serialization.

How is $this->renters populated in your job, and what does it hold?

SteveCove left a reply on Instantiate Abstract Class

DomDocument is in the global namespace (its built into php).

Since you are accessing it within a namespace, you will need to use a backslash to reference the global namespace:

$doc = new \DOMDocument(); //<-- note the backslash

SteveCove left a reply on Instantiate Abstract Class

As @zion says, you need to use the Spatie\Crawler\Crawler interface as well, so add the line use Spatie\Crawler\Crawler; under your other use statements at the top of the page, and replace Crawler\Crawler::create() with Crawler::create().

I am happy to help, but without a decent grasp of modern php, you are going to have a really hard time making a usable app with laravel.

Luckily this site has fantastic video tutorials, this would be a good start:

https://laracasts.com/series/object-oriented-bootcamp-in-php

SteveCove left a reply on Instantiate Abstract Class

Its a namespace issue, the autoloader is looking for the interfaces in the current namespace App\Console\Commands

Add the following to the top of the file:

use GuzzleHttp\Exception\RequestException;
use Psr\Http\Message\ResponseInterface;
use Psr\Http\Message\UriInterface;

OR use the fully qualified names in the methods:

    public function crawled(
        Psr\Http\Message\UriInterface $url,
        Psr\Http\Message\ResponseInterface $response,
        ?Psr\Http\Message\UriInterface $foundOnUrl = null
    )
    {

      //
    }

    public function crawlFailed(
        Psr\Http\Message\UriInterface $url,
        GuzzleHttp\Exception\RequestException $requestException,
        ?Psr\Http\Message\UriInterface $foundOnUrl = null
    )
    {
      //
    }

SteveCove left a reply on Cover Validation From Server Errors

I follow a simple rule - errors that can occur under normal circumstances get proper error handling with nice error messages,

Errors that require malicious intent (bypassing client side validations, modifying forms etc) get nothing, i do not need to spend my time creating nice messages to help a hacker get in...

20 Dec
9 months ago

SteveCove left a reply on Instantiate Abstract Class

Here is a quick example class the extends CrawlObserver

class TitleLogger extends CrawlObserver{

    private $pages =[];


    public function crawled(
        UriInterface $url,
        ResponseInterface $response,
        ?UriInterface $foundOnUrl = null
    )
    {

        $path = $url->getPath();
        $doc = new DOMDocument();
        @$doc->loadHTML($response->getBody());
        $title = $doc->getElementsByTagName("title")[0]->nodeValue;

        $this->pages[] = [
            'path'=>$path,
            'title'=> $title
        ];
    }

    public function crawlFailed(
        UriInterface $url,
        RequestException $requestException,
        ?UriInterface $foundOnUrl = null
    )
    {
        echo 'failed';
    }

    public function finishedCrawling()
    {
        echo 'crawled ' . count($this->pages) . ' urls' . PHP_EOL;
        foreach ($this->pages as $page){
            echo sprintf("Url  path: %s Page title: %s%s", $page['path'], $page['title'], PHP_EOL);
        }
    }

}

to use it in your command:

    Crawler\Crawler::create()
            ->setCrawlObserver(new TitleLogger())
            ->setMaximumCrawlCount(1)
            ->ignoreRobots() //github doesnt like scrapers...
            ->startCrawling('https://github.com/spatie/crawler');

But again, the only thing you need to do to "get it working" is implement those two abstract methods crawled, crawlFailed in your class, what you use in the method bodies is entirely up to you

SteveCove left a reply on Instantiate Abstract Class

As i said in my reply, you need to implement the abstact methods in your concrete implementation of CrawlObserver, in your case myClass.

Nobody can tell you what code to put in those methods, as thats where your specific business logic goes.

Perhaps you want to log the failed pages to a database, so you would write that code in the crawlFailed method. Perhaps you want to extract all the images from successfull pages and send them to your google drive, then you would write that code in the crawled method.

Do you see what i mean?

SteveCove left a reply on Get The Value Of Select Box With Same Class

You need to use classes, as ids must be unique. Addtionally, if you wrap your button and select in a parent element, its easy to find the correct select in your javascript:

@foreach($test as $t)
  <div>
    <button class="btn">Choose</button>

    <select name="select_test">
      <option value="0">0</option>
      <option value="1">1</option>
    </select>
  </div>
@endforeach

$('.btn').on('click', function() {
    var select = $(this).parent().find('select[name="select_test"]').val();
    alert(select);
});

SteveCove left a reply on Instantiate Abstract Class

You can fix this specific error by implementing the abstract methods (without bodies):

class myClass extends CrawlObserver {

    public function crawled(
            UriInterface $url,
            ResponseInterface $response,
            ?UriInterface $foundOnUrl = null
        )
    {
        //noop
    }

    public function crawlFailed(
            UriInterface $url,
            RequestException $requestException,
            ?UriInterface $foundOnUrl = null
        )
    {
        //noop
    }

}

But this will then make your code pointless - im guessing you actually want to do something with the crawled pages?

19 Dec
9 months ago

SteveCove left a reply on GuzzleHttp Hang Up My Laravel App

You may have fixed this already, but if not, could you clarify how you are serving the app.

You mention apache, but then talk about changing ports etc, which makes me think you are actually using artisan:serve, which as i mentioned before, uses phps built in (single threaded) webserver, which will not work

SteveCove left a reply on Guzzle Get Request Loading

@bhargav960143 No problem, glad i could help

SteveCove left a reply on Guzzle Get Request Loading

What we server are you using? The build in PHP development server (artisan: serve) is single threaded so will hang as described in this situation. You would need to use a real server (Apache /nginx)

18 Dec
9 months ago

SteveCove left a reply on Same Select On Multiple Row

Well it depends on how your app works.

Your initial post talked about blade foreach, which suggested server side rendering.

Are you doing a bit of both, eg rendering a number of selects server side, and giving the user the option to add more client side?

If yes then i would suggest making the ajax request once (pageload), and saving the data in a javascript object. Then apply the data to the server side rendered fields once (pageload), and then apply to any client side created selects when they are created.

If you have the time however, it would be a lot cleaner to just render the whole lot client side with a data driven design, eg Vuejs, React or similar:

https://codepen.io/stevecove/pen/xmEeam

The nice thing about vuejs is its simple to add to an existing traditional server side rendered app. You dont have to move everything to ajax, you just replace your blade foreach with a json echo into a script tag, and pick it up in vue in the mounted function

SteveCove left a reply on Same Select On Multiple Row

If you swap ids for classes, you just need to itterate through the selects on the page:

https://codepen.io/stevecove/pen/MZjBpw

15 Dec
9 months ago

SteveCove left a reply on GuzzleHttp Hang Up My Laravel App

Ok so is Apache listening on port 8000?

SteveCove left a reply on GuzzleHttp Hang Up My Laravel App

What server are you using? If PHP artisan:serve it won't work, as that uses phps single threaded dev server.

You would need to use Apache or nginx

14 Dec
9 months ago

SteveCove left a reply on Same Select On Multiple Row

Sorry I didn't realize you dont get notified when someone replies.

You might have already fixed this, but this issue is like I said. You are using CSS IDs in a loop. CSS IDs must be unique, so you can't use them in a loop. Switch to CSS classes instead:

<select class="type-of-time">...

$('.type-of-time').find(...