hsl

hsl

Member Since 4 Years Ago

Experience Points 3,645
Experience Level 1

1,355 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 48
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.

06 Jan
7 months ago

hsl left a reply on UpdateOrCreate Does Not Create

@JLRDW - I don’t use the id field for auto incrementing columns anywhere in my apps so I didn’t think the origin of my data would be relevant.

hsl left a reply on UpdateOrCreate Does Not Create

Thanks, that was it,..

hsl left a reply on UpdateOrCreate Does Not Create

Why not? The item comes from a third party API and I need to store that with it's id.

hsl left a reply on UpdateOrCreate Does Not Create

The id doesn't need to be updated, it needs to be created with the right id, so it doesn't really make sense that it doesn't do that.

hsl left a reply on UpdateOrCreate Does Not Create

Model:

class TestModel extends Model
{   
    // protected $primaryKey = 'id';

    protected $fillable = [
        'id','owner_id','name','legacy','active','default','count','enabled'
    ];

    public function owner()
    {
        return $this->belongsTo('App\Owner', 'owner_id');
    }

}

call:

$newData = array(
    'id' => $item['id'],
    'owner_id' => $owner->id,
    'name' => $item['name'],
    'legacy' => $item['legacy'],
    'count' => 0,
    'enabled' => true,
);

Log::info( $newData );

$testModel = TestModel::updateOrCreate( ["id" => $item['id']], $newData );

Log::error( $testModel );

The log info will show the right ID, in this case this: 'id' => 14406778943, With the log error it will show "id":0

I've also tried to do the call without the id in the object and that gives the exact same result.

hsl left a reply on UpdateOrCreate Does Not Create

Unfortunately not, somehow the model that's returned by your example will have the id 0 and not the id 4 :(

hsl left a reply on UpdateOrCreate Does Not Create

Yeah that's not going to work, I need to do it with the id. But in the docs it doesn't state that it must be other fields than the id field, why wouldn't that work?

hsl started a new conversation UpdateOrCreate Does Not Create

Hi,

I'm trying to use updateOrCreate, I'm using the "id" as the field to check and if it needs to update it works fine, if it needs to create it tries to create a new row with the id 0.

Getting a bit lost here, anyone has an idea why this doesn't work?

30 Dec
7 months ago

hsl left a reply on Settings As Json In Database Null When Value Doesn't Exist.

The only disadvantage is that it won't work when adding new settings. :/ Then the only solution is this:

protected $casts = [
        'settings' => 'array',
    ];

Is there a way that supports both so that I don't have to manually call the optional everytime I want to get a setting?

29 Dec
7 months ago

hsl left a reply on Settings As Json In Database Null When Value Doesn't Exist.

Awesome, thanks! I've used that to do it in the model:

public function getSettingsAttribute($value)
{   
  return optional( json_decode($value) );
}

hsl left a reply on Settings As Json In Database Null When Value Doesn't Exist.

Thanks, already tried that, that still gives a "Undefined index"

hsl started a new conversation Settings As Json In Database Null When Value Doesn't Exist.

Hi,

I'm saving settings in a database and currently I'm always checking if a value that I need is present before I get it. let's say my Test model has a settings column with a json value, I cast it to an array, and let's assume I don't have the key "string" saved.

dd( $test->settings['string'] )

Right now I get: ErrorException : Undefined index: string

I would rather have it return null if it's not defined. Is there a way to do that? Would save me a lot of checks.

Thanks!

21 Jul
1 year ago

hsl left a reply on Middleware Throttle For Single Request

To make it a little more clear, my app has regular users and third party apps sometimes have access to that user data. So the apps are not authorised in the same way as the users.

I'm a bit lost, anyone has a suggestion how to get it working? :)

19 Jul
1 year ago

hsl left a reply on Middleware Throttle For Single Request

Thanks, I added that and it still doesn't work, but I found out what happens. The request has certain key and secret headers that I check in the middleware so I think the middleware sees each request as a separate user because I see this in the headers:

X-RateLimit-Limit: 2
X-RateLimit-Remaining: 1

What would be the best way to limit it for each "app-key" header? :)

hsl left a reply on Middleware Throttle For Single Request

Ah yeah, already tried that one as well, but it doesn't work :(

Route::group(['middleware' => ['api.auth', 'throttle:2,1']], function () {
    Route::get('api/test.json', '[email protected]');
});

hsl left a reply on Middleware Throttle For Single Request

How would I use that in my example route?

I've tried both these and they didn't work:

Route::get('api/test.json', '[email protected]')->middleware('api.auth','throttle:2,1');
Route::middleware('api.auth','throttle:2,1')->group(function () {
    Route::get('api/test.json', '[email protected]'); 
});

hsl started a new conversation Middleware Throttle For Single Request

Hi,

I'm handling api authentication in a middleware:

Route::get('api/test.json', '[email protected]')->middleware('api.auth'); 

I want to limit that certain endpoint to a certain amount per minute. Is that possible? I'm trying to do it using the documentation, but can't get it to work. :)

Thanks!

08 Jul
1 year ago

hsl left a reply on Auth:: With Custom Login Flow

Thanks, yeah I already found out that I have to rebuild my complete app as I don't have a User model at the moment. I have a Auth model where all the oauth data is in :)

hsl left a reply on Auth:: With Custom Login Flow

Where $id is the $id for the user in my own Auth model?

hsl started a new conversation Auth:: With Custom Login Flow

Hi,

I've got a test application where users log in through a third party through oauth. When they initially installed the app they are entered in my database. When they login through the oauth flow I fetch the userdata and save it in the session to keep the browser logged in.

What's the best way to also use the auth facades to get the current user and to use with the private channel broadcast routes?

I've googled, but I can't find any similar use cases, does anyone have some links to reading materials?

Thanks!

07 Jul
1 year ago

hsl started a new conversation Maintenance Mode Events?

Is there a way to fire an event when the maintenance mode goes up or down?

05 Jun
1 year ago

hsl left a reply on Maintenance Mode With --allow=[ip] Behind Load Balancer Doesn't Work

Thanks, but unfortunately that doesn't make a difference :/

04 Jun
1 year ago

hsl left a reply on Maintenance Mode With --allow=[ip] Behind Load Balancer Doesn't Work

Yeah, it's been included since 5.5, but for maintenance mode it doesn't do the trick.

hsl started a new conversation Maintenance Mode With --allow=[ip] Behind Load Balancer Doesn't Work

I'm trying to set my own ip so that I can access my app while they are in maintenance mode. My app is running on multiple servers behind a digital ocean load balancer and the php artisan down --allow=[ip] doesn't work properly as it doesn't see the original IP for the client.

Anyone knows how to fix this?

29 Apr
1 year ago

hsl started a new conversation Get Queuename From Within Job

Hi,

I'm trying to get the queuename right from my job. I have the same type of job on different queues and in the job I need to know on what queue that specific job was queued.

When I look in the laravel/api documentation I see a getQueue() function, but I can't get that to work. Does anyone know what the best way is to get the queuename?

Thanks!

27 Jul
2 years ago

hsl left a reply on Issues With Consuming Own API Authenticated With Laravel Passport

Same here. Using both headers as described in the documentation and still getting the 401 Unauthorized error.

Does anyone have the solution?

hsl left a reply on 5.3: Api Routes, Auth Middleware Confusion

Just ran into this, what's the best approach if you want to have an "internal" API that only works when the user is logged in? The token approach looks a little complex for that.

04 Apr
2 years ago

hsl started a new conversation Laravel Passport As SSO Server

Hi,

I'm busy with a number of projects and they all require to be able to login through the same user info. I was thinking of using a separate Laravel Passport app as SSO server.

Now I am able to arrange the first step, so I can authorise the app (app1) for a current user on the passport server. Then I save the access key and the userinfo for the user in the session so the user can use app1.

Not sure if that's possible, but once the user is logged out of app1 I would love to get a new access token without going through the whole authorization flow, is that possible? And if possible, what part of the documentation am I missing?

Cheers,

Harold

16 Feb
2 years ago

hsl left a reply on UnexpectedValueException In Request.php

In my nginx conf

02 Nov
2 years ago

hsl left a reply on 5.3 Upgrade Error: BroadcastServiceProvider Contains Abstract Method

Same issue here, and proposed solutions above don't work :/

22 Apr
3 years ago

hsl left a reply on Scheduled Tasks And Multiple Instances Of App

Ok, I think I found a better solution, I'll just remove the cronjob for the task scheduling out on the frontend and worker servers :)

hsl started a new conversation Scheduled Tasks And Multiple Instances Of App

Hi Guys, At the moment I have three instances for one application, since I don't want to build and maintain 3 different apps that are almost the same I installed the same app for: #1 The frontend that my customers see. #2 The backend that receives and processes webhooks. #3 A separate server that only gets and processes jobs from a redis server.

Right now I have automated some stuff with tasks, but the tasks run on all three servers, what would be the best way to make sure that only one server processes the tasks? I was thinking about adding a .env variable RUN_TASKS = true/false and add a check for that in /app/Console/Kernel schedule() method.

Is that the best solution or is there a better way?

01 Apr
3 years ago

hsl started a new conversation Central Logging For Multiple Instances Of L5.2 App

Hi,

I'm running one of my projects (L5.2) on several servers, one for the frontend, one for the backend (receives webhooks), and two to run the different worker queues. Right now to monitor them I have several terminal screens open to see the different log files.

But instead of tailing the different log files I would rather do a tail of the log files in one location, is there a solution for that? And if possible I'd rather not switch to a external logging service.

Thanks,

Harold

20 Mar
3 years ago

hsl left a reply on Log Rotate

@martinbean Sorry for the late reply, but I want that because I want to be able to leave a tail -f laravel.log open on my server.

I fixed it by just using logrotate logrotate and use that to keep the log files for a week, todays log file is always laravel.log, yesterdays log file is laravel.log.1 and so on. :)

01 Mar
3 years ago

hsl left a reply on UnexpectedValueException In Request.php

I think I "fixed" it, I added this to my nginx conf.

server {
  ## Deny illegal Host headers
  if ($host !~* ^(myapp.tld)$ ) {
    ## 444 to make sure to return no data at all.
    return 444;
  }
}
09 Jan
3 years ago

hsl left a reply on Log Rotate

Thanks guys, I already found the daily option but with the daily option today's logfile name is not laravel.log but has today's date. Is there any way to override that so it will be just laravel.log for todays logs?

08 Jan
3 years ago

hsl started a new conversation Log Rotate

Hi Guys,

Right now I'm using a single log file, but that gets quite big quite fast when I add a lot of logging in my project.

Is it possible to get the logs daily, but named like this?

laravel.log

While the older (up to a week) are named like this:

laravel-2016-01-08.log
laravel-2016-01-07.log
laravel-2016-01-06.log
laravel-2016-01-05.log
laravel-2016-01-04.log
laravel-2016-01-03.log

I tried to use logrotate with the single log file, but after logrotate ran all my jobs except one stopped adding lines in the log file. And yes I did add the right filepermissions in the logrotate config.

Anyone has a suggestion how I can best achieve this?

Thanks!

19 Nov
3 years ago

hsl left a reply on UnexpectedValueException In Request.php

No one has this error and a solution for it?

[2015-11-16 19:24:27] lumen.ERROR: exception 'UnexpectedValueException' with message 'Invalid Host "*.domain.tld"' in /app/vendor/symfony/http-foundation/Request.php:1291
Stack trace:
#0 /app/vendor/symfony/http-foundation/Request.php(1088): Symfony\Component\HttpFoundation\Request->getHost()
#1 /app/vendor/symfony/http-foundation/Request.php(1120): Symfony\Component\HttpFoundation\Request->getHttpHost()
#2 /app/vendor/symfony/http-foundation/Request.php(1796): Symfony\Component\HttpFoundation\Request->getSchemeAndHttpHost()
#3 /app/vendor/symfony/http-foundation/Request.php(1104): Symfony\Component\HttpFoundation\Request->prepareRequestUri()
#4 /app/vendor/symfony/http-foundation/Request.php(1848): Symfony\Component\HttpFoundation\Request->getRequestUri()
#5 /app/vendor/symfony/http-foundation/Request.php(974): Symfony\Component\HttpFoundation\Request->prepareBaseUrl()
#6 /app/vendor/symfony/http-foundation/Request.php(1914): Symfony\Component\HttpFoundation\Request->getBaseUrl()
#7 /app/vendor/symfony/http-foundation/Request.php(930): Symfony\Component\HttpFoundation\Request->preparePathInfo()
#8 /app/vendor/illuminate/http/Request.php(108): Symfony\Component\HttpFoundation\Request->getPathInfo()
#9 /app/vendor/illuminate/http/Request.php(156): Illuminate\Http\Request->path()
#10 /app/app/Http/Middleware/AdminMiddleware.php(16): Illuminate\Http\Request->is('v1/data/*')
#11 [internal function]: App\Http\Middleware\AdminMiddleware->handle(Object(Illuminate\Http\Request), Object(Closure))
#12 /app/vendor/illuminate/pipeline/Pipeline.php(124): call_user_func_array(Array, Array)
#13 [internal function]: Illuminate\Pipeline\Pipeline->Illuminate\Pipeline\{closure}(Object(Illuminate\Http\Request))
#14 /app/vendor/illuminate/pipeline/Pipeline.php(103): call_user_func(Object(Closure), Object(Illuminate\Http\Request))
#15 /app/vendor/laravel/lumen-framework/src/Application.php(1411): Illuminate\Pipeline\Pipeline->then(Object(Closure))
#16 /app/vendor/laravel/lumen-framework/src/Application.php(1185): Laravel\Lumen\Application->sendThroughPipeline(Array, Object(Closure))
#17 /app/vendor/laravel/lumen-framework/src/Application.php(1125): Laravel\Lumen\Application->dispatch(NULL)
#18 /app/public/index.php(28): Laravel\Lumen\Application->run()
#19 {main}
11 Aug
4 years ago

hsl left a reply on UnexpectedValueException In Request.php

I also did a clean lumen install and when just leaving that open on a production server (with nothing else installed) it also gave the same errors.

hsl left a reply on UnexpectedValueException In Request.php

Nope, there is no way to reproduce it, it looks like someone or a bot is trying to access my application through *.domain.tld instead of app.domain.tld and Laravel throws the error for that.

hsl left a reply on UnexpectedValueException In Request.php

This is completely random, I'm not doing anything with my app at the moment of the error and it looks like as if someone tries to access my app.

hsl started a new conversation UnexpectedValueException In Request.php

Hi Guys,

Every couple of days I get this entry in the error logs for my lumen app (latest version):

[2015-08-11 06:57:12] lumen.ERROR: exception 'UnexpectedValueException' with message 'Invalid Host "*.[DOMAIN].[TLD]"' in /apps/[APPNAME]/vendor/symfony/http-foundation/Request.php:1291

Does anyone know what causes this and how I can fix this?

Thanks!

29 Jul
4 years ago

hsl left a reply on Install Bootstrap Through Composer

I genuinely hate NPM because NPM often doesn't work properly when developing the same project on different machines, but I'll give it a go again. :/

Regarding to my original question: The composer package for bootstrap has an assets folder in "vendor/twbs/bootstrap-sass/assets", I expected that it was possible to use "php artisan vendor:publish" to link or copy the assets from the bootstrap-sass package to the regular resources folder.

28 Jul
4 years ago

hsl left a reply on Install Bootstrap Through Composer

Guys please, I'm asking how the vendor:publishing part works for when I want to install it through composer. I know I can use npm, but I really don't want to.

hsl left a reply on Install Bootstrap Through Composer

Nope, I'm not using npm to pull in other packages.

hsl left a reply on Install Bootstrap Through Composer

@mstnorris That's what I said and that's also why I want to install bootstrap through composer and not through npm.

hsl left a reply on Install Bootstrap Through Composer

Thanks! I'll never run npm on my production server, so that's not an ideal solution. :)

hsl started a new conversation Install Bootstrap Through Composer

Hi Guys,

Normally I would install bootstrap-sass manually, but because it might be a good idea to do it through composer I decided to go that way for my new project.

Now the question, how do I "publish" the vendor assets? I've tried to do it with: php artisan help vendor:publish --path="vendor\twbs\bootstrap-sass\assets" But that doesn't do anything, does anyone know how I can get it to work?

Thanks!

30 Jun
4 years ago

hsl left a reply on Invalid Host Exceptions Weekly

Same problem here, I would also love to get rid of the Exceptions.

23 Jun
4 years ago

hsl left a reply on Model Not Found From Job

Thanks!

Argh,.. that's stupid, in my normal controllers I also use that. I guess I've been staring to this code too long ;)