skovmand

Member Since 5 Years Ago

Aarhus, Denmark

Experience Points 9,330
Experience Level 2

670 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 95
Lessons
Completed
Best Reply Awards 2
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.

11 Feb
2 years ago

skovmand left a reply on Using Php70-xdebug With Valet

I had to also remove the ticks in the checkboxes in PHPStorm (2017.1 EAP):

Preferences -> Languages & Frameworks -> PHP -> Debug ->

"Force break at first line when no path mapping is specified" "Force break at first line when a script is outside the project"

Or else it would break every time at server.php - a part of Laravel Valet.

02 Nov
2 years ago

skovmand left a reply on Is Flysystem Encrypting In Transit?

From https://github.com/aws/aws-sdk-php/blob/master/docs/guide/configuration.rst#scheme

scheme


:Type: ``string``
:Default: ``string(5) "https"``

URI scheme to use when connecting connect. The SDK will utilize "https"
endpoints (i.e., utilize SSL/TLS connections) by default. You can attempt to
connect to a service over an unencrypted "http" endpoint by setting ``scheme``
to "http".

.. code-block:: php

    $s3 = new Aws\S3\S3Client([
        'version' => '2006-03-01',
        'region'  => 'us-west-2',
        'scheme'  => 'http'
    ]);

See http://docs.aws.amazon.com/general/latest/gr/rande.html for a list of
endpoints whether or not a service supports the ``http`` scheme.

skovmand left a reply on Is Flysystem Encrypting In Transit?

I have just verified that the uploads from my server happen over HTTPS using tcpdump

skovmand left a reply on Is Flysystem Encrypting In Transit?

It's a pretty important issue if you're transmitting private data or taking backups, though..

skovmand left a reply on Is Flysystem Encrypting In Transit?

I believe that too, but I need to be sure. I can't find any documentation for whether the PHP AWS uses SSL in transit.

skovmand started a new conversation Is Fflysystem Encrypting In Transit?

Hi.

When uploading content using Flysystem and the S3 driver, is the content uploaded securely in transit (using SSL)? I'm using Laravel 5.2.

Thanks.

08 Oct
2 years ago

skovmand left a reply on Multiple Wheres In Query Builder

I solved it using ->whereNested in the Query builder. Can't post all code, sorry, but this is what fixed it.

        if ($tag->hasAlternateBpmLimits() && $tag->hasBpmLimits()) {
            return $query->whereNested(function ($query) use ($tag) {
                return $query->whereBetween('bpm', [$tag->bpm_min, $tag->bpm_max])->orWhereBetween('bpm', [$tag->alternate_bpm_min, $tag->alternate_bpm_max]);
            });
        }

skovmand left a reply on Multiple Wheres In Query Builder

Okay, dang! I have problems anyway.....

This is the query that is executed by the querybuilder:

select `tracks`.* 
from `tracks` 
inner join `tag_track` on `tracks`.`id` = `tag_track`.`track_id` 
left join `spotify_audio_features` on `tracks`.`id` = `spotify_audio_features`.`track_id` 
left join `spotify_records` on `tracks`.`id` = `spotify_records`.`track_id` 
where (`tag_track`.`tag_id` = 6 and `bpm` between 65 and 80 or `bpm` between 130 and 160) and `tracks`.`deleted_at` is null order by `tracks`.`bpm` desc

But that is not right. A paranthesis is missing on the second to last line which causes trouble.

This is what I want (only difference is the parenthesis!):

select `tracks`.* 
from `tracks` 
inner join `tag_track` on `tracks`.`id` = `tag_track`.`track_id` 
left join `spotify_audio_features` on `tracks`.`id` = `spotify_audio_features`.`track_id` 
left join `spotify_records` on `tracks`.`id` = `spotify_records`.`track_id` 
where (`tag_track`.`tag_id` = 6 and (`bpm` between 65 and 80 or `bpm` between 130 and 160)) and `tracks`.`deleted_at` is null order by `tracks`.`bpm` desc

Is there any way?

Thanks!

skovmand left a reply on Multiple Wheres In Query Builder

Absolutely beautiful, thanks!

skovmand started a new conversation Multiple Wheres In Query Builder

Hi!

I need to make a query similar to this in the Query Builder:

SELECT * FROM tracks WHERE (tracks.bpm > 58 AND tracks.bpm < 73) OR (tracks.bpm > 115 AND tracks.bpm < 145)

However I can't find any documentation on whether this combination of wheres is possible. I would like to write it as something like:

Track::where('bpm','>',50)->where('bpm','<',70)->.....->get()

Can it be done, or do I need to use DB::select(...)?

Thanks!

09 Aug
2 years ago

skovmand left a reply on Cache:clear Also Clear Redis Sessions

Thanks. I assume it's ok setting the database value to for example 'database' => 2 or anything unique. Just tested, and my sessions are no longer cleared :-)

skovmand left a reply on Cache:clear Also Clear Redis Sessions

Yeah. I think I have. I didn't realise you could use different databases. Can you give me a hint on how to set that up?

skovmand started a new conversation Cache:clear Also Clear Redis Sessions

I use redis for both sessions and caching in my production app. When running cache:clear during deployment all my sessions are cleared from redis as well. Does anyone know if this is intended behavior?

19 Jul
3 years ago

skovmand started a new conversation Any Thoughts On The HTTPoxy Vulnerability?

Should we take any action when running our apps Forge-provisioned servers? Any thoughts on the problem?

Digital Ocean states that only HTTP and not HTTPS is affected and has a general guide on fixing the vulnerability: https://www.digitalocean.com/community/tutorials/how-to-protect-your-server-against-the-httpoxy-vulnerability

skovmand left a reply on What Kind Of Relation Would You Choose?

I would just make a polymorphic relation. It will also let you store the same photo/video in multiple albums. Perhaps the table should be called album_items.

Then give the table the entries id - item_type - item_id - album_id - whatever you need - created_at - updated_at

13 May
3 years ago

skovmand left a reply on Why Not Base Laravel On Hack?

Yeah, but Hack already had a high speed, as well as many other cool and useful language features before that. I really wish there was a Laravel-fork taking advantage of the Hack language features.

skovmand started a new conversation Why Not Base Laravel On Hack?

Hi.

Facebook has taken PHP to a new level with Hack, which introduces many good language features. I don't understand why Laravel isn't based on Hack instead of PHP to take advantage of these language features, like async, pipes, generics, etc. Or why it doesn't "make the jump".

Or is it time for hackavel.com?

What's your thoughts?

25 Mar
3 years ago

skovmand left a reply on Multiple SELECTs

Ok, thank. I added it to the original question, however I need an example. I still can't get SELECT('...') to work.

skovmand left a reply on Multiple SELECTs

Yes but I need to sort by it from the database. Then it wouldnt work very well.

24 Mar
3 years ago

skovmand left a reply on Multiple SELECTs

Oh yeah, that's right. Thanks.

My relations are

In Track.php:

    /**
     * @return \Illuminate\Database\Eloquent\Relations\HasOne
     */
    public function echoNestRecord()
    {
        return $this->hasOne(EchoNestRecord::class);
    }

In EchoNestRecord:

    /**
     * @return \Illuminate\Database\Eloquent\Relations\BelongsTo
     */
    public function track()
    {
        return $this->belongsTo(Track::class);
    }

skovmand started a new conversation Multiple SELECTs

Hi!

Can anyone help me do this query with Eloquent? SELECT tracks.*, (artist_hotttnesss+song_hotttnesss)/2 as popularity from tracks LEFT JOIN echo_nest_records ON tracks.id = echo_nest_records.track_id

I have this - only missing including the (artist_hotttnesss+song_hotttnesss)/2 as popularity

        $query = Track::select('tracks.*')
            ->leftJoin('echo_nest_records', 'tracks.id', '=', 'echo_nest_records.track_id')
            ...

Thanks!

17 Feb
3 years ago

skovmand left a reply on Config:cache Makes Variables In .env Null

Thanks. That's it. I have been pulling my hair out over this one.

skovmand left a reply on Config:cache Makes Variables In .env Null

Yeah. Thanks! Where did you find it?

skovmand started a new conversation Config:cache Makes Variables In .env Null

I'm confused and hope you can help!

When I run php artisan config:cache the variables set in my .env-file are not being read properly in the application and if I do php artisan tinker I get:

>>> env('S3_KEY');
=> null

after doing php artisan config:clear everything is back to normal:

>>> env('S3_KEY');
=> "AERIAOEBNOIAERGOIEAJRI" // not my real key

How come config:cache has this effect? Is it because I use e.g. S3_KEY in a config.php-file? Which is then set to null?

skovmand left a reply on .env Not Reading Variables Sometimes

I had trouble with config:cache, when it is run, the app (Laravel 5.2) doesn't read files from the .env-file. I ran config:clear, and everything works again.

skovmand left a reply on .env Not Reading Variables Sometimes

+1 It is VERY annoying and periodic!

09 Jan
3 years ago

skovmand left a reply on The Input:: Facade

It doesn't in the newest Laravel 5.2, if you look at the config/app.php. However, if you upgrade (like I did) it will still exist, because the alias in configured in app.php. So it still works.

My problem was that I had imported the new aliases from the laravel/laravel repository on Github.

So the problem was only that, no big deal....

skovmand started a new conversation The Input:: Facade

Has the Input facade (silently) disappeared in 5.2? Where was that mentioned?

I no longer see it in the Facade Docs

I usually use dependency injection of Request $request in the controllers, however a lot of my legacy code uses Input::only or similar.....

08 Jan
3 years ago

skovmand left a reply on Error When Upgrading To 5.2 - 'Class Log Does Not Exist'

I also had the problem. In the end I debugged it from the console by running php artisan and tracing the execution path from the artisan.php-file in the project root.

I debugged it like this: In the file /vendor/laravel/framework/src/Illuminate/Foundation/Application.php I changed the method bootstrapWith to

    public function bootstrapWith(array $bootstrappers)
    {
        $this->hasBeenBootstrapped = true;

        foreach ($bootstrappers as $bootstrapper) {
            var_dump('bootstrapping: ' . $bootstrapper);
            $this['events']->fire('bootstrapping: '.$bootstrapper, [$this]);

            $this->make($bootstrapper)->bootstrap($this);

            var_dump('bootstrapped: ' . $bootstrapper);
            $this['events']->fire('bootstrapped: '.$bootstrapper, [$this]);
        }
    }

And ran php artisan again from the terminal. The last provider that started loading (but didn't finish) was LoadConfiguration provider. It gave me a clue where to look.

And so I changed the file /vendor/laravel/framework/src/Illuminate/Foundation/Bootstrap/LoadConfiguration.php in the method loadConfigurationFiles to:

    protected function loadConfigurationFiles(Application $app, RepositoryContract $repository)
    {
        foreach ($this->getConfigurationFiles($app) as $key => $path) {
            $repository->set($key, require $path);
            var_dump('loaded key: ' . $key . ' -- path: ' . $path);
        }
    }

After which it was clear that the last configuration key loaded was /config/queue.php string(87) "loaded key: queue -- path: /home/vagrant/Code/traeningsprojekt.dk/site/config/queue.php"

So it must be the file after that. And it was indeed - in my /config/services.php where I had the array key:

    // One key is for testing (doesn't send any actual mail), the other for real mails.
    'mandrill' => [
        'secret' => app()->environment() === 'testing' ? 'hidden-in-this-post' : 'also-hidden-in-this-post'
    ],

Phew what a journey. But in the end I solved it, and it was indeed a configuration issue.

09 Oct
3 years ago

skovmand left a reply on Reflashing Session Data

I tried it out, the problem is the same. I think the two methods do the same thing, but keep($array) just allows you to keep specific keys only.

08 Oct
3 years ago

skovmand started a new conversation Reflashing Session Data

Hi.

I am redirecting to a registration page with Session flash data using

        return redirect(route('registration.student.token.create'))
            ->with(['authToken' => $token]);

And in the registration controller I want to reflash this data to keep it in the next session also. I do that this way:

    public function create(Request $request)
    {
        $request->session()->reflash();

        return view('registration.student.token.create');
    }

If the user refreshes the page in the browser the session authToken sticks around only for the first refresh, then it disappears.

Am I wrong in thinking it should stick around no matter how much the page is refreshed?

Or am I doing it wrong?

04 Oct
3 years ago

skovmand started a new conversation Set XSRF-TOKEN On Beta.mydomain.com Instead Of .beta.mydomain.com

Hi everyone.

I have three domains on my server: Production URLs: www.mysite.com + mysite.com Beta URL: beta.mysite.com Demo URL: demo.mysite.com

On purpose I have set the production domain in Session.php to:

'domain' => env('SESSION_COOKIE_DOMAIN', ".mysite.com"),

on beta.mysite.com to beta.mysite.com and demo.mysite.com on the demo site.

Now for the problem! The XSRF-token for .mysite.com is taking precedence over the beta.mysite.com XSRF-token. Therefore I get TokenMismatchExceptions all the time on these sites. The Session works fine because I use three different names for it, but the XSRF-tokens do not since they use the same name.

Is there some clever way to prevent this?

Regards, Niels.

30 Sep
3 years ago

skovmand left a reply on Testing A Package

I couldn't make it work due to the bootstrapping process, so I decided to make the package framework agnostic, which was a really fun challenge. Now I'm running composer install and everything's setup correctly.

skovmand left a reply on Testing A Package

Okay? So should I just add this to the package and run composer install? Can't try it right now, but I will try it later today.

"require": {
    "laravel/framework": "5.1.*",
  },

Regards, Niels.

skovmand started a new conversation Testing A Package

Hi!

I'm writing a package for my Laravel app. I would like to add tests to it, but how do I do that when the package is dependent on the Laravel framework since it uses a ServiceProvider, publishes a Config-file and a view and it uses app() for dependency injection.

How do I go about testing it? Should I make a fresh Laravel install, require the package and then run the tests?

What is the best practice?

28 Aug
3 years ago

skovmand left a reply on [5.12] G Chrome Causes TokenMismatchException On Form Submit

I have updated my post with some strategies I have used for preventing it. It has helped so far, although the problem is not gone:

https://laracasts.com/discuss/channels/laravel/random-tokenmismatchexceptions

skovmand left a reply on Random TokenMismatchExceptions

I have had some luck with different strategies and now I have only a few mismatchs per day. Though I am not sure which one of these are more effective - and maybe some of them are not related at all. However I see a big difference now.

For info: I am running my site on a week old Laravel Forge provisioned Ubuntu 14.04 server on DigitalOcean. It is the default setup.

Strategies:

  1. Editing the CRON-job which clears out old sessions in PHP to only run once every night at 04:01 GMT+2 instead of every 30 mins. All my clients are Danish, so no one is active there. I think this plays a big role. You can't disable it entirely since that will slowly eat up your disk space.

sudo nano /etc/cron.d/php5 and changing the line to 01 04 * * * root [ -x /usr/lib/php5/sessionclean ] && /usr/lib/php5/sessionclean

  1. Setting the garbage collection maxlifetime in php.ini located in /etc/php5/fpm/php.ini from 1440 seconds (=24 minutes) to 86400 seconds (24 hours). session.gc_maxlifetime = 86400
  1. Disabling CSRF checking on routes where it's not necessary, e.g. on the login-form. In VerifyCsrfToken.php:
class VerifyCsrfToken extends BaseVerifier
{
    /**
     * The URIs that should be excluded from CSRF verification.
     *
     * @var array
     */
    protected $except = [
        'sessions/store'
    ];
    ...
  1. Detecting whether the request is a JSON-request. In that case my site would normally redirect to the login page and then the ajax request would generate 4-5 requests all generating TokenMismatchExceptions. But for JSON-requests it will now respond with HTTP_FORBIDDEN. In Handler.php:
        if ($e instanceof TokenMismatchException) {
            if($request->isJson() || $request->ajax()) {
                return Response::json(['Session expired. Please log in again.'], HttpCodes::HTTP_FORBIDDEN);
            }

            return redirect(route('login'))
                ->with('flash_message', 'Session expired. Please log in again.');

        } 
  1. Setting my cookies on the root domain. I found out that if my cookies were set on www.mysite.dk, they would not be set on the root domain mysite.dk. The same of course goes for the sessions. I solved it by changing this line in Session.php. Note that when you do this, you should also change the SESSION_COOKIE_NAME to something else, or your client will get two may potentially conflicting cookies (the old + the new).
    'domain' => env('SESSION_COOKIE_DOMAIN', ".traeningsprojekt.dk"),
26 Aug
3 years ago

skovmand left a reply on Set Cookies On Root Domain

Thanks! I'll try it out.

Also, found it myself in CookieServiceProvider.php. It is indeed set from Session.php:

    /**
     * Register the service provider.
     *
     * @return void
     */
    public function register()
    {
        $this->app->singleton('cookie', function ($app) {
            $config = $app['config']['session'];

            return (new CookieJar)->setDefaultPathAndDomain($config['path'], $config['domain']);
        });
    }

skovmand started a new conversation Set Cookies On Root Domain

Hi!

I have a website which allows both access to www.mywebsite.com and mywebsite.com.

However this gives me a cookie problem, because a user which logs on to www.mywebsite.com does not have a session on mywebsite.com, because the cookie domain is set to the domain in use.

Is there a way in Laravel to force cookies to be set on mywebsite.com, which would remove the problem? I tried changing the session domain in Session.php without luck.

Thanks!

23 Aug
3 years ago

skovmand left a reply on [5.12] G Chrome Causes TokenMismatchException On Form Submit

I don't agree. It is the session being restarted randomly, which shouldn't happen.

Also I think you should be careful about opening a get-route for tokens, since that could be a security problem if it is discovered. That could open the door for CSRF again.

20 Aug
3 years ago

skovmand left a reply on Random TokenMismatchExceptions

Thanks for your input. I consider this an option to get a new token via javascript, however it is very strange that the server initiates a new session on its own.

So I would definately prefer not to get new tokens dynamically, and that the server session would just persist.

This github thread seems related: https://github.com/laravel/framework/issues/8172

skovmand left a reply on Random TokenMismatchExceptions

Thanks, I'll try out the database driver today. It's a very annoying issue! Crossing my fingers when viewing my Bugsnag status page tonight.

19 Aug
3 years ago

skovmand left a reply on [5.12] G Chrome Causes TokenMismatchException On Form Submit

This is a copy of my post from my own question, but it is worth repeating here? Did anyone find a solution?

TL;DR: It is not session timeout.


The last two days I have done an experiment and put a hidden input field into my login-page. This field contains the time of the page load, so I can see how old the session is.

I just got a fresh TokenMismatchException thrown - and the session was only about 20 seconds old. This means that for some reason a new session had been initialised on the server, since the csrf_token has changed.

So, the error doesn't have anything to do with session expiration.

Any ideas? Any help would be very appeiciated!

skovmand left a reply on Random TokenMismatchExceptions

The last two days I have done an experiment and put a hidden input field into my login-page. This field contains the time of the page load, so I can see how old the session is.

I just got a fresh TokenMismatchException thrown - and the session was only about 20 seconds old. This means that for some reason a new session had been initialised on the server, since the csrf_token has changed.

So, the error doesn't have anything to do with session expiration.

Any ideas? Any help would be very appeiciated!

16 Aug
3 years ago

skovmand left a reply on Random TokenMismatchExceptions

I have recently set

'lifetime' => 1440, in config/session.php

It does not help, so I think it is not related to expiration of the session.

skovmand left a reply on Taylor's Book Relevant For Laravel 5?

I read the book in december 2014 when Laravel 5 was just about to be released. I think it is very well written, and most of the principles can still be used, since it covers a lot of OO-patterns and how they can be made with Laravel.

I would still recommend it, because it covers general Laravel principles still in action as well as code principles. However some of the code would be written differently today with L5.