deansatch

deansatch

Member Since 2 Years Ago

Experience Points
53,430
Total
Experience

1,570 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
265
Lessons
Completed
Best Reply Awards
35
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 11
53,430 XP
Jan
13
1 week ago
Activity icon

Replied to Step After Activate New Release Always Fails With Connection Refused

do you have any instructions on how to do this? I am having the same problem as rate limiting is set at 6 per 30 seconds but no idea how to either change it to a higher number or add envoyer as an exception

Dec
19
1 month ago
Activity icon

Replied to Laravel 5.1 WhereHas('polymorphic')

An example to narrow down to the issue as the actual code is monstrous - I just fixed the confusing part of it (changed Post to Comment::)

Dec
18
1 month ago
Activity icon

Started a new Conversation Laravel 5.1 WhereHas('polymorphic')

I have a project currently stuck on 5.1 but need to get all items whereHas a polymorphic relationship with a certain sub-relationship. I expect this would have been a breeze in 6 using whereHasMorph but is there any quick way to get similar results in 5.1?

basically trying to achieve...



Comment::whereHas('commentable', function($q){
    $q->whereHas('tags', function($q){
        $q->whereIn('id', [1,2,3]);
    });
});

// basically want all posts which have comments that have been tagged with tagID 1,2 or 3

Dec
09
1 month ago
Activity icon

Replied to Laravel Charts Ajax And Csrf

Can anyone else help on this? If I remove 'auth:api' from the api route it works ok.

Activity icon

Replied to Laravel Charts Ajax And Csrf

Just like the example really...but to clarify a bit better, here is my api controller (index method):


    $chart = new Test();
        $chart->dataset('Sample Test', 'bar', [3, 4, 1]);
        $chart->dataset('Sample Test', 'line', [1, 4, 3]);
        return $chart->api();

And my api route:


Route::group(['namespace' => 'API', 'prefix' => 'v1'], function () {
    Route::group(['middleware' => ['auth:api']], function () {
        Route::get('test', '[email protected]');
    });
});

And my view:

@extends('layouts.main')
@section('content')
        {!! $chart->container() !!}
@endsection

@section('footerscripts')
<script src="https://cdnjs.cloudflare.com/ajax/libs/Chart.js/2.7.1/Chart.min.js" charset="utf-8"></script>
{!! $chart->script() !!}

<script>
    {{ $chart->id }}_refresh({{ $chart->id }}_api_url);
</script>

@endsection

Controller method for the view:


$url = url('/api/v1/test');
        $chart = new Test();
        $chart->labels(['test1', 'test2', 'test3'])->load($url);
        return view('charts.test', compact('chart'));


Activity icon

Started a new Conversation Laravel Charts Ajax And Csrf

I have an api to be consumed by the same site. I am using laravel charts and want to use the api endpoints to build the datasets and use ajax to load them.

Following the laravel charts docs (https://charts.erik.cat/api_charts.html#building-the-chart) I have used their example data for now as my endpoint (api/v1/test) and set up the view exactly as their example. It fails authorisation on page load so the chart never loads.

I am guessing this is because it uses fetch() but isn't setting a csrf header but I have no idea how to inject that header in this case.

A quick test with jquery $.get() setting the jquery csrf header I am authenticated and can return the data.

Nov
30
1 month ago
Activity icon

Started a new Conversation Restart Supervisor During Deploy?

Can anyone explain to me the best way to keep my queue worker up to date and running as stable as possible?

So for example I have a worker that runs order confirmations which are queued via the database. I have noticed if I make a change to my job scripts whilst the worker is running I have to restart it before it will see those changes.

My worker conf file is pretty simple:


[program:laravel-worker]
process_name=%(program_name)s_%(process_num)02d
command=php /var/www/current/artisan queue:work --sleep=10 --tries=6 --daemon
autostart=true
autorestart=true
user=root
numprocs=3
redirect_stderr=true
stderr_logfile=/var/www/storage/supervisor/worker.err.log
stdout_logfile=/var/www/storage/supervisor/worker.log

Should I be adding a deployment hook in envoyer to restart supervisor everytime I deploy new code? Or is that bad? My main worry with that would be what would happen if I had jobs in the jobs table at the time of restart...would they be lost? Any clarification on the whole process would be much appreciated

Thanks

Nov
05
2 months ago
Activity icon

Replied to Which Deployment Hooks?

sorry..."deployment" hooks. Not webhooks.

Activity icon

Started a new Conversation Which Deployment Hooks?

I have a site which I would normally run npm run production on before pushing to github. Is this still the way I should do it when using envoyer or should I have that as a webhook instead and never run that command locally?

Also, just wondering which cache:clear and xyz:cache commands I should or shouldn't run as webhooks.

e.g. I was thinking of setting up 4 more webhooks to do:

#1
php artisan cache:clear

#2
php artisan config:cache

#3
php artisan route:cache

#4
php artisan view:clear



Any thoughts on this?

Oct
03
3 months ago
Activity icon

Started a new Conversation Get Diffindays Split By Year

If I have two carbon dates, how can I get the number of days between them but split by year.

e.g. 30th december 2019 to 5th jan 2020 would be 6 days using diffInDays(), but then I want it split as:

2 days in 2019 4 days in 2020

Aug
29
4 months ago
Activity icon

Replied to Is It Safe To Disable VerifyCsrfToken Middleware On Login And Logout Pages ?

Its quite hard to explain what I mean without an example but imagine these scenarios:

  1. Without csrf protection I get an email asking me to login and update something. I click the link, see the familiar login page and login. It logs me in and I update stuff and log out then go about my day.

  2. With csrf protection I get the email, click link, login but it fails and shows me the real login page. I go back check the email and spot the dodgy url. I quickly change my password and delete the email

In scenario 1 the hacker can create a page to spoof the login, post to a script which stores the post data, then uses curl to post it directly to the real login post endpoint and the lack of csrf protection allows it

Maybe not a huge deal but still something to think about

Activity icon

Replied to Is It Safe To Disable VerifyCsrfToken Middleware On Login And Logout Pages ?

What I mean is, if the copycat page is a spoofed login page, it will fail csrf verification on your site (if it exists) when the user enters their details, basically alerting and getting their attention so they will spot the problem and change their login details.

If you don't have csrf on, the copycat page could harvest the login details then log them in seamlessly. So they might not know they've given away their credentials for a while longer...long enough for them to be exploited

Activity icon

Replied to Is It Safe To Disable VerifyCsrfToken Middleware On Login And Logout Pages ?

@snapey if there is no csrf on a login form does that not allow a much more convincing phish? e.g. send an email with a copy of login page on a different domain, user falls for that, fills it in, login details are captured then forwarded/reposted to the real login form and the user is logged in smoothly without any knowledge that something went wrong? As opposed to logging in and it failing first time making the user go back and question what they just did

Aug
03
5 months ago
Activity icon

Replied to Cache Certain Queries Results

Its public facing data and stats are made up from both visitor contributions and user activity. Doesnt need to be updated more than once a day but it would be a bonus if it could be updated more often though. No login required

Activity icon

Replied to Cache Certain Queries Results

How would something like that be set up? I suppose it has to run for each user. Some sort of queue??

I cant set a flag because the figures are calculated from a combination of thousands of rows across 8 tables and some queries are built based on the results of the previous so basically have to run the whole thing to just to see if anything is different. I was thinking of just using eloquent update() as Im pretty sure that will insert a record if it is a new user or update if it is existing and has changed

Activity icon

Replied to Cache Certain Queries Results

Problem is there are a lot of pages and that will continue to grow. So using the remember() helper works but one page for example will take 10 seconds to load first time until cached. After that it is fine. But in 24 hours time if nobody has visited that page again google could be the next one to visit and then it will lose its position in Googles index. Even if a human visits it first time it isnt good that it loads so slow for one person every day.

A cron has to be the way forward it is just which method is the best? I could run a foreach loop to update the stats as flat figures in a dB table but is that really the best way? And would the cron be subjected to the Php execution timeout?

Aug
01
5 months ago
Activity icon

Started a new Conversation Count And Order Relationship Values

I have posts with authors. Authors could be admin, editor, customer etc... I want to count posts by each type and find who which type posted the most and which one the least.

e.g. output I want is:


admin (43 posts)
customer (21 posts) //I don't actually need this one
subscriber (3 posts)

So I can end up with variables like


$mostPosts; // should be equal to 'admin' 
$leastPosts; // should be equal to 'subscriber'


//ideally I would have something like:

$array = [
    'mostPosts': {
        'type': 'admin',
        'count': 43
    },
    'leastPosts': {
        'type': 'subscriber',
        'count': 3
}
    ];


//starting from...

$posts->with('author')->....

With this, speed of execution is most important

Jul
31
5 months ago
Activity icon

Replied to Cache Certain Queries Results

Im leaning more towards the cron method tbh. It just seems like someone is going to suffer a slow load every day otherwise.

Any other ideas?

The reason the query is slow is because it needs to make 4 queries on massive amounts of data then make calculations based on the results of each so it will take longer as the site grows

Activity icon

Replied to Cache Certain Queries Results

I was thinking about this but does that not mean someone would have to visit every single page 1st for the cache to happen? i.e. the first visitor to each page would get the slow page load.

Then if I am pushing site updates every couple of days would each envoyer deployment not wipe that cache again?

Just thinking it isn't much good caching queries if google might be the first visitor to all the pages resulting in a big drop in page ranking

Activity icon

Started a new Conversation Cache Certain Queries Results

I have a section on a site that shows a calculated stat on each post/page. The queries that run to generate the number slow the page load down by about 1 second. What is the best way to serve this to users as a daily cache instead of running the query on every page load? It won't change massively over the course of 24 hours so a daily refresh would be fine.

This is a different figure on each page and there could be 10s of 1000s of pages