samiles

samiles

Member Since 4 Years Ago

Experience Points 1,050
Experience Level 1

3,950 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 18
Lessons
Completed
Best Reply Awards 0
Best Reply
Awards
  • Start Your Engines Achievement

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • First Thousand Achievement

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • One Year Member Achievement

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • Two Year Member Achievement

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • Three Year Member Achievement

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • Four Year Member Achievement

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • Five Year Member Achievement

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • School In Session Achievement

    School In Session

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

  • Welcome To The Community Achievement

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • Full Time Learner Achievement

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • Pay It Forward Achievement

    Pay It Forward

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

  • Subscriber Achievement

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • Lifer Achievement

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • Laracasts Evangelist Achievement

    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 Achievement

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • Laracasts Veteran Achievement

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • Ten Thousand Strong Achievement

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • Laracasts Master Achievement

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • Laracasts Tutor Achievement

    Laracasts Tutor

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

  • Laracasts Sensei Achievement

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • Top 50 Achievement

    Top 50

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

13 Mar
1 year ago

samiles started a new conversation Facade With A Dependency Causing Arguments Error

I am trying to access a function from anywhere in my app. But I get the following error:

Type error: Argument 1 passed to App\Helpers\AwsAutoscale::__construct() must be an instance of Aws\AutoScaling\AutoScalingClient, none given, called in /home/vagrant/Site/app/Providers/AwsAutoscaleProvider.php on line 31

My code is:

App/Helpers/AwsAutoscale.php

<?php

namespace App\Helpers;

use Aws\AutoScaling\AutoScalingClient;

class AwsAutoscale
{

    private $awsClient;

    public function __construct(AutoScalingClient $awsClient)
    {
        $this->awsClient = $awsClient;
    }

    public function groupStats()
    {
        $result = $this->awsClient->describeAutoScalingGroups();

        return collect([
            'desired' => $result['AutoScalingGroups'][0]['DesiredCapacity'],
            'min' => $result['AutoScalingGroups'][0]['MinSize'],
            'max' => $result['AutoScalingGroups'][0]['MaxSize'],
            'current' => count($result['AutoScalingGroups'][0]['Instances'])
        ]);
    }

}

App/Providers/AutoScalingClientProvider.php

<?php

namespace App\Providers;

use Aws\AutoScaling\AutoScalingClient;
use Illuminate\Support\ServiceProvider;

class AutoScalingClientProvider extends ServiceProvider
{
    /**
     * Register the application services.
     *
     * @return void
     */
    public function register()
    {
        $this->app->bind(AutoScalingClient::class, function () {
            return new AutoScalingClient([
                'AutoScalingGroupName' => config('aws.auto_scaling_client.name'),
                'region' => config('aws.auto_scaling_client.region'),
                'version' => config('aws.auto_scaling_client.version')
            ]);
        });

    }

}

App/Providers/AwsAutoScaleProvider.php

<?php

namespace App\Providers;

use Illuminate\Support\ServiceProvider;

class AwsAutoscaleProvider extends ServiceProvider
{
    /**
     * Bootstrap the application services.
     *
     * @return void
     */
    public function boot()
    {
        //
    }

    /**
     * Register the application services.
     *
     * @return void
     */
    public function register()
    {
        //
        $this->app->bind('autoscale', function()

        {

            return new \App\Helpers\AwsAutoscale;

        });
    }
}

config/app.php:

'providers' => [
    ...
    App\Providers\AwsAutoscaleProvider::class
    ...

'aliases' => [
    ...
    'autoscale'=> App\Facades\AutoscaleFacade::class,
    ...

Code in controller:

return autoscale::groupStats();

Calling this results in the error:

Type error: Argument 1 passed to App\Helpers\AwsAutoscale::__construct() must be an instance of Aws\AutoScaling\AutoScalingClient, none given, called in /home/vagrant/Site/app/Providers/AwsAutoscaleProvider.php on line 31

04 May
1 year ago

samiles started a new conversation Access Laravel Queued Job's Payload Data

How can I access the payload from within the Laravel job class?

I have tried in the handle() section of my job class:

$payload = $this->payload(); //undefined method
$payload = $this->payload; //undefined property
$payload = json_decode($this->getRawBody(), true); //undefined method

Anyone know how the payload can be accessed? Thanks.

13 Jan
2 years ago

samiles started a new conversation Redis Queue Not Respecting Timeout And Creating Dozens Of Processes

Hi,

I have my Redis queue configured as such:

'redis' => [
    'driver' => 'redis',
    'connection' => 'default',
    'queue' => 'default',
    'retry_after' => 350,
],

In Laravel Forge, I have 3 queue workers configured like:

Timeout: 250
Sleep: 10
Tries: 1

These are quite long jobs and typically take around 20-200 seconds to complete (95% within 45 seconds). I am happy for jobs which take more than 250 seconds to simply die.

According to the docs, --timeout should be shorter than retry, which is the case.

The problem is that my server becomes clogged with many processes after 20-60 mins of running. At the moment, there are 64 queue processes taking up most RAM and CPU. Running top -c shows them with full commands.

Here is a screenshot of the top result, showing just a few of these processes. As you can see, some have been running for some time.

The commands running are:

/usr/bin/php7.1 artisan queue:work redis --once --queue=crawlqueue --delay=0 --memory=128 --sleep=10 --tries=1 --env=local

Why does this happen? As I have 3 queue processors, I assumed there would just be 3 processes? Don't they just take the job, complete it, and move on - why are there so many processes, and what are they doing? If there is a timeout, should these processes simply not die within 250 seconds? Is there something wrong in my configuration? It's wrecking my server.

Thank you!

04 Jan
2 years ago

samiles left a reply on Braintree Payment

There's a reason they charge that much.

You'll need to be a payment gateway yourself - basically a bank. You'll need to do insane security compliance, which will cost you an untold fortune.

Depending on your country of operation, you will almost certainly need to be licensed and regulated to do this.

It's certainly cheaper, and 1000x faster, to just use Braintree/Stripe/PayPal etc.

Alternatively, your bank may provide more old fashioned merchant processing services which could be cheaper than Braintree etc, but they will only talk to you if you plan to process LOTS of money, and it will be very difficult to implement.

samiles left a reply on Connect To Redis On Homestead From Host Machine

I incorrectly had:

U: homestead

Worked it out - the username is actually vagrant, not homestead. Switched to Vagrant and it works great and I can manage Homestead's Redis with the GUI.

samiles started a new conversation Connect To Redis On Homestead From Homestead

Hello,

I am trying to connect to Redis running on the Homestead machine from my Mac. Usually I SSH into the machine and use redis-cli. I want to view Redis in a GUI like Medis or FastoRedis.

How do I configure this? Currently I am using:

SSH tunnel: 192.168.10.10 (my homestead IP as set in Homestead.yml) U: homestead P: vagrant

Redis host: 192.168.10.10 Redis post: 22

But this will not connect with either app. It gives an error about authentication failing.

Do I need additional details here? Is there a password, or authentication stuff I need to change? I think Redis auth is off on the Homestead install - do I need to provide a Redis password or something?

Has anyone successfully got to Redis from the host machine?

Thanks!

30 Nov
2 years ago

samiles started a new conversation Channel Descriptions

I'd love to see some short descriptions on the channel pages for discussions.

Of course some are obivous (Eloquent, Elixir) but some less so. For example, is 'Tips' for sharing your tips, or asking for advice (seems to include both now). Lots of people post Qs in guides, although it doesn't seem to be what it is for. Same with code review - is it for checking code, or asking Qs before you start writing, etc.

Maybe a single sentence when you select the Channel drop down when adding a new discussion? Just think it might clear up the channels a little...

29 Sep
2 years ago

samiles started a new conversation Gulp '--production Is Not A Task'

Hi,

I'm trying to run gulp in production mode according to the docs.

// Run all tasks...
gulp

// Run all tasks and minify all CSS and JavaScript...
gulp --production

gulp works fine, but when I run gulp --production to get the minified versions, I get the error:

Task '--production' is not in your gulpfile

Any ideas why this is?

13 Sep
2 years ago

samiles left a reply on How Do I Add The Beaver Slider To A Laravel App

Ah, I see. The minimum code you need for the slider is:

    <div id="my-slider"></div>

When the Beaver Javascript runs, it looks for the matching DIV, and builds the HTML itself at runtime. So, if you open up the demo HTML file they give you in a text editor, you'll see it only has <div id="my-slider"></div>, but open it up in Chrome and view the Developer Tools, and you'll see that it's added in all the other HTML required itself.

You simply have to judge what the CSS classes do based on their names.

samiles left a reply on How Do I Add The Beaver Slider To A Laravel App

Well, it looks like there's a demo.css file included in the slider download which gives it basic styling. If you wanted to include this, you'd save it in your /public/demo.css folder, and it would then be accessible at yourdomain.com/demo.css.

Simply include the CSS file in the normal way, in between your <head> and </head>:

It looks like they provide as little style as possible so you can customize it. Include the demo style, along with the JS, and you should get what you're looking for.

samiles left a reply on Updating Ubuntu Version Of Homestead Box

Ah, nice catch, thank you. So it can't just be updated from 1 to 2 with homestead update, there's some manual process involved? I'll try to find some info online. Thank you.

samiles left a reply on How Do I Add The Beaver Slider To A Laravel App

Your Blade file is just a HTML file, and your slider can be installed on it like any other HTML page. Their docs seem fairly good. We'll need more info if you have a specific question?

Really the only code in a Blade file not treated like regular HTML is anything in the control structures.

Is there a specific Laravel/PHP issue, such as are you trying to load the images from a database or something?

samiles started a new conversation Updating Ubuntu Version Of Homestead Box

Hello,

I am trying to get up to Ubuntu 16.04 for my Homestead box as I need to test a feature of it. I set up my box when it was still using 14.04.

After running vagrant box update 1575db9 I get the following result:

==> default: Checking for updates to 'laravel/homestead'
    default: Latest installed version: 0.5.0
    default: Version constraints: >= 0.4.0
    default: Provider: virtualbox
==> default: Box 'laravel/homestead' (v0.5.0) is running the latest version.

So it seems to get up to date. But when I SSH into the box and run lsb_release -a it tells me that the box is 14.04:

No LSB modules are available.
Distributor ID: Ubuntu
Description:    Ubuntu 14.04.4 LTS
Release:    14.04
Codename:   trusty

I don't know if the box is up to date or not - it says it is running the latest version, but it's still on 14? Will I have to create a brand new box or something, or is it possible to upgrade the OS this way?

Many thanks

25 Jul
2 years ago

samiles left a reply on Using A Global Scope When Creating New Model

@martinbean Ah that makes much more sense, nice one. I've been meaning to learn Eloquent relations for a while... Looks like I've found my reason now. Thank you

samiles started a new conversation Using A Global Scope When Creating New Model

Hi,

Pretend I'm making a to do app. I've made a nice global scope on my Task model which compares the userid to the logged in user's ID. This works fine.

However, is there a way to make this work in the opposite direction - to add some query segment each time a model is CREATED. So, I want to be able to create a task, use my owned() scope or whatever, and have it automatically include userid=* when inserting a new model?

Or am I right in my assumption that global scopes are only for retrievals, and not for creates/updates?

Thanks

13 Jun
2 years ago

samiles started a new conversation Encrypting Database Content When Key Is Stored On The Server

Hello.

I was wondering what the point, or security reason, of using Laravel's encryption helper to encrypt database content is? My understanding is that the key is kept in your .env file - if a hacker gets access to my server, they could just read the key right out of the .env file and decrypt everything themselves, right...?

Is it purely useful for setups where the web server and database server are separate? Presumably then if they got web server access they would get DB access and crack it, but if they only accessed the DB server, the data would be useful? Is it pointless if you're using a Forge server where the database and app are on the same machine?

Just trying to get an idea of what the security use case is.

Thanks.

07 Mar
3 years ago

samiles left a reply on Setting On Node.js Socket.io On Laravel Forge

@Ronster Hmm couldn't make that work. Is our code different?

samiles started a new conversation Setting On Node.js Socket.io On Laravel Forge

Hi,

I have had a Socket.io server running just fine with my Forge site over HTTP. Since upgrading to HTTPS the connection has broken. I need to set up Socket.io running on my server with SSL. I have multiple sites installed on the server.

I was originally connecting to http://socket.mydomain.com but simply switching to https://socket.mydomain.com and installing SSL on the sub domain doesn't work. It gives a Nginx Bad Gateway error.

Does anyone know how to set this up? My front end code to connect is:

var io = io('https://socket.example.com', { secure: true });

The code of my Socket.io script is:

var https = require('https'), fs = require('fs');

var options = { key: fs.readFileSync('/etc/nginx/ssl/default/54082/server.key'), cert: fs.readFileSync('/etc/nginx/ssl/default/54082/server.crt') }; var app = https.createServer(options);

var io = require('socket.io').listen(app);

app.listen(3000);

Any ideas on how to achieve this set up and fix the SSL issue? I've found no tutorials on setting up with SSL. Thanks

30 Nov
3 years ago

samiles left a reply on Service To Send Highly Custom Emails

You can specify the view to use when sending email in Laravel. Check out this example from the docs, where 'emails.welcome' is the view and $data is what you pass to the view.

Mail::send('emails.welcome', $data, function ($message) {
    $message->from('us@example.com', 'Laravel');
    $message->to('foo@example.com')->cc('bar@example.com');
});

I believe you can also get the HTML from a view, just by setting the view to a variable rather than returning it. You can probably Google the specifics.

samiles left a reply on Service To Send Highly Custom Emails

Well, Mandrill and other mail sending solutions essentially accept raw HTML to send, so you can hand it whatever you want.

The way I do email templates is to generate my emails as Laravel Blade views, just as if you were returning a view for the browser, then send that via Mandrill. That way you can implement any template you can think of just using Laravel. Then perhaps use Artisan command line task to generate the actual emails.