MrMooky

Member Since 1 Year Ago

Experience Points
16,570
Total
Experience

3,430 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
144
Lessons
Completed
Best Reply Awards
0
Best Reply
Awards
  • start your 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-in-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 Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • evangelist 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.

  • Community Pillar

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

Level 4
16,570 XP
May
15
3 days ago
Activity icon

Replied to Database Seeder Question

Ok, that explains it. Thanks. What would be that best way to get the base_id in the RatingFactory then? Can this even be accomplished in one swoop, or would I need to create another seeder for ratings only?

Activity icon

Replied to Database Seeder Question

So when calling Model::factory() inside another factory, it does not use the id of the parent model automatically? I'm not sure anymore where I saw it or read about it.

Activity icon

Started a new Conversation Database Seeder Question

I'm currently writing a seeder with factories. Haven't done it this way before, so I'm kind of wondering about the following.

This creates 2 bases, 10 categories and 50 articles.

Base::factory()->count(2)->has(
    Category::factory()->count(5)->has(
    	Article::factory()->count(5)
	 )
 )->create();

But this creates 252 bases, 10 categories, 50 articles and 250 ratings.

Base::factory()->count(2)->has(
	Category::factory()->count(5)->has(
		Article::factory()->count(5)->has(
			Rating::factory()->count(5)
		)
	)
)->create();

I don't understand why there are 252 bases created.

This is my RatingFactory:

return [
	'reaction' => array_rand($reactions),
	'base_id' => Base::factory(),
	'article_id' => Article::factory(),
	'feedback' => $this->faker->text,
	'read' => 1
];

I assumed that this won't create new Base or Article entries, as they are part of the has method in the seeder.

Apr
22
3 weeks ago
Activity icon

Replied to POST Request With Json And GetResponse

With that I get "Required field empty" for all fields that are submitted. So name and email from my code are working, only compaignId needs to be different it seems.

I assume that Laravel Http produces the correct code for multi-arrays the way it is expected by GetResponse, as it seems to be standard.

Activity icon

Started a new Conversation POST Request With Json And GetResponse

I'd like to add a contact to GetResponse via their API. This is how the data should be structured, according to their docs:

{
    "name": "Jan Kowalski",
    "email": "[email protected]",
    "campaign": {
        "campaignId": "jf7e3jn"
    },
}

My code looks like this:

$response = Http::withHeaders([
    "X-Auth-Token" => "api-key my-api-key"
])->post('https://api.getresponse.com/v3/contacts', [
    "name" => $user->name,
    "email" => $user->email,
    "campaign" => [
        "campaignId" => "my-campaign-id"
    ]
]);

But $response is giving me "Given campaign is invalid". I tested this with Insomnia and the campaign id is correct. Is there anything special I have to do with the post data?

Apr
21
3 weeks ago
Activity icon

Replied to Shell Error With Imagick

Uhm, this is not about GD, but ImageMagick. GD is running just fine. IM is actually installed, but there is something else going wrong. And I don't get why this valet.php file is complaining.

Apr
20
4 weeks ago
Activity icon

Started a new Conversation Shell Error With Imagick

I just wanted to install ImageMagick with PHP 8 on my local machine. But I spend the last couple of hours trying to fix errors with brew and valet and boy oh boy – I could just set everything on fire right now!

Basically, I re-installed and re-everythinged a few times now but still end up with the following error when I run valet install.

Warning: PHP Startup: Unable to load dynamic library 'imagick.so' (tried: /usr/local/lib/php/pecl/20200930/imagick.so (dlopen(/usr/local/lib/php/pecl/20200930/imagick.so, 9): Library not loaded: /usr/local/opt/imagemagick/lib/libMagickWand-7.Q16HDRI.7.dylib
  Referenced from: /usr/local/lib/php/pecl/20200930/imagick.so
  Reason: image not found), /usr/local/lib/php/pecl/20200930/imagick.so.so (dlopen(/usr/local/lib/php/pecl/20200930/imagick.so.so, 9): image not found)) in Unknown on line 0
Could not open input file: 
Warning: PHP Startup: Unable to load dynamic library 'imagick.so' (tried: /usr/local/lib/php/pecl/20200930/imagick.so (dlopen(/usr/local/lib/php/pecl/20200930/imagick.so, 9): Library not loaded: /usr/local/opt/imagemagick/lib/libMagickWand-7.Q16HDRI.7.dylib
  Referenced from: /usr/local/lib/php/pecl/20200930/imagick.so
  Reason: image not found), /usr/local/lib/php/pecl/20200930/imagick.so.so (dlopen(/usr/local/lib/php/pecl/20200930/imagick.so.so, 9): image not found)) in Unknown on line 0

Parse error: syntax error, unexpected identifier "imagick", expecting ")" in Command line code on line 2/cli/valet.php

I don't know why it says "imagick.so.so" and I don't know why valet.php complains about an expecting ) there. I haven't even touched that file.

Anybody have some idea what could be wrong and how to fix this?

Oh and the folder 20200930 did not contain the image, but I copied the one from my PHP 7.4 folder, so it is not empty.

Apr
18
1 month ago
Activity icon

Replied to Livewire Refresh After Form Submit

I got it working with a combination of jQuery and Livewire.

So my jQuery code looks something like this:

$.post('/user/two-factor-recovery-codes', function(response){
    Livewire.emit('regeneratedCodes');
});

And I added this line to my component:

protected $listeners = ['regeneratedCodes' => 'showCodes'];

I'd still like to know if this is possible without any "workarounds".

Activity icon

Started a new Conversation Livewire Refresh After Form Submit

All demos show Livewire handling the post logic. So essentially something like this:

<form wire:submit.prevent="doSomethingInLivewire">

But my form action looks like this:

<form action="/user/two-factor-recovery-codes" method="post" wire:submit.prevent="regenerateCodes">

My component (PHP) looks like this right now:

class RecoveryCodes extends Component
{
    public $codes = [];

    public function showCodes()
    {
        $this->codes = auth()->user()->recoveryCodes();
    }

    public function regenerateCodes()
    {
        $this->codes = auth()->user()->recoveryCodes();
    }

    public function render()
    {
        return view('livewire.recovery-codes');
    }
}

The showCodes method works just fine, but what I would like to do is to actually submit the form action (without page reload) and when that is done, refresh the component with the new codes. Is that possible with Livewire? Or does Livewire have to handle the logic inside the component and cannot submit and actual form action?

Apr
17
1 month ago
Activity icon

Started a new Conversation Password Confirmation Via Ajax Request

I‘m currently struggling to find a solution for the following problem:

I want to make a post request via Ajax to a controller action that will give me the html of a view (partial). That action needs to be restricted by the password.confirm middleware. I‘d like to show the password confirmation dialog inside a custom overlay, but of course only if needed (session timeout value expired).

How can I „ask“ Laravel if the user has to confirm the password via Ajax? And show a custom dialog when appropriate? I checked Jetstream as it does what I want, but I can‘t figure it out. They use Livewire or Inertia for this.

Activity icon

Replied to Implementing Two-Factor-Authentication

I checked out Fortify but did not want to rebuild the logic. So I installed Fortify along with the existing Breeze setup I had when I originally started the project. Everything is working fine so far, QR code is generated, recovery codes are generated, I can enable and disable 2FA.

But when I enable 2FA, then logout and login again, there is no 2FA challenge. It's probably due to the fact that Breeze was installed before. But how can I enable the 2FA challenge with both Breeze and Fortify?

So my login route currently uses App\Http\Controllers\Auth\[email protected], but should probably use the Fortify route. How can I change that?

Update: Got it. Just had to remove the login routes from my auth.php

Activity icon

Started a new Conversation Implementing Two-Factor-Authentication

I'm aware that there are many packages out there that "support" 2FA for Laravel. But some of them are outdated, seem insecure or are only available for Google Authenticator.

Via Medium I found the Package Laraguard and was excited to implement it as it seems to do exactly what I wanted. But it seems insecure as my password was visible in plain-text while logging in. Plus, when trying with Authy, some strange name appeared as my logo.

I wanted to give Authy a try, but it is outdated and I cannot install it with my current Laravel 8 project. There is a PR since late last year, but the project seems abandoned.

What are your recommendations? Btw, I'm using Laravel Breeze.

Apr
07
1 month ago
Activity icon

Replied to Get Count Of Relation In Where Clause

Yes, just saw that a few seconds after I hit the send button. Ended up with this:

$users = User::whereHas('topups', function(Builder $query) {
    $query->where('created_at', '<', now()->subDays(10));
}, '>=', 1)->orWhereDoesntHave('subscription', function(Builder $query) {
    $query->where('created_at', '<', now()->subDays(10));
})->get();

Still need to figure out why the created_at won't work, but I can go on with that now. Thanks.

Activity icon

Replied to Get Count Of Relation In Where Clause

But does orDoesntHave respect the created_at query?

Activity icon

Started a new Conversation Get Count Of Relation In Where Clause

My User model has two relations: TopUp (hasMany) and Subscription (hasOne).

Within a Task, I'd like to get all users who do not have either a subscription or at least one top up and signed up at least 10 days ago.

I can get the count with $user->topups->count() or $user->subscription->count() but I don't want to get all users and then filter them afterwards. So the query should only load the relevant users.

This one is not working obviously, but I figure I need to do this in two parts?

$users = User::with(['topups' => function($query) {
    $query->where('topups', '>=', '1');
    $query->where('created_at', '<', Carbon::now()->subDays(10));
}])->orWhere('subscription', '=', '1');->get();

UPDATE

Ended up with this one-liner:

$users = User::doesntHave('topups')->doesntHave('subscription')->where('created_at', '<', now()->subDays(10))->get();
Apr
02
1 month ago
Activity icon

Replied to Redeploy Let's Encrypt SSL/TLS Certificate

Sadly, no. My example was too simplified. sorry. Basically, it can be ANY domain for the user domain. So something.domain-one.com and other.url.de and so on.

Activity icon

Started a new Conversation Redeploy Let's Encrypt SSL/TLS Certificate

This is a general setup related question where I don't know what the best approach is. Let's say I have a service where people can sign up and use their custom domains for their public profile, ie. username.domain.com.

I'm currently using RunCloud for server management and attach those domains via API to the application and re-deploy the Let's Encrypt certificate, also via API. Due to the limitation of 20 re-deploys per week, this is not really something I can use on the long run. So I was wondering what the best way to accomplish something like this would be, where I need to allow users to have their own subdomain with SSL encryption.

I'm not really into issuing Let's Encrypt certificates myself on the server (I know there are certain PHP and Laravel packages).

I'd be really happy if someone could give me a nudge on how to do this.

Mar
25
1 month ago
Activity icon

Replied to Check If Route Is Category

Ah yes, on my production server I have 3 jobs set up. I forgot about that. That might have been the cause. Will give this another shot. Thanks for your help.

Mar
24
1 month ago
Activity icon

Replied to Check If Route Is Category

I did not guard it against app()->runningInConsole(), no. This was caused by users visiting the frontend. The error log filled up to ~500MB in about 10 minutes. I have a FrontendController where I applied this logic now when I'm in either the category, or article view. No errors there. So I guess it must had something to do with the fact that this was inside the AppServiceProvider file.

Still don't know why, though. When I debugged that on my production server !Request::route()->category gave me null when I was not viewing a category and the category "slug" when I was viewing one. In fact, it actually worked fine, except the error log was filling up.

Activity icon

Started a new Conversation Check If Route Is Category

I had this line in my AppServiceProvider.php

$currentCategory = (!Request::route()->category ? 'none' : Request::route()->category);

It is working just fine on my local machine, but on my production server, it throws this error:

live.ERROR: Trying to get property 'category' of non-object {"exception":"[object] (ErrorException(code: 0): Trying to get property 'category' of non-object at /home/mooky/webapps/eniston-bases-custom/app/Providers/AppServiceProvider.php:33)

Basically, I need to know the current route name here in my file. Can anybody explain why this works without errors on my local machine, but hogs the log file on my production server?

Latest Laravel version on both local and live.

Mar
20
1 month ago
Activity icon

Replied to Best Practice Blade String Conversion

That worked like a charm. Thanks!

Activity icon

Started a new Conversation Best Practice Blade String Conversion

Not sure if the title is misleading... With TinyMCE I implemented a custom link_list of internal articles. So a link could look this this:

article:a058d67a-2108-4ec3-a7ea-135b867a3f7b

I want to replace this "link" with the actual link to the article when the page is rendered. My idea was to use a custom helper function in my Blade view, that would look like this: {!! Helper::transformInternalArticleLinks($article->text) !!}

But now I'm not sure what to do next. Basically, I don't know if there are internal links or not. But if there is something like the one above, grab the uuid of it and generate the link. My issue is not with generating the link, but rather how to find article:somethingin the body text and transform it.

I was thinking of something like Str::contains for this? And if so, how would it work in this case? I'm not sure where to go next.

Feb
28
2 months ago
Activity icon

Started a new Conversation API Connection From Provider

I'd like to connect Statamic CMS with my Laravel app and grab some data via the Content API. In my HelperServiceProvider (I also tried AppServiceProvider.php) I have this code:

$footerNav = CMSConnect::getJsonData("/cms/collections/pages/entries");

My Service file looks like this:

    public static function getJsonData($endpoint)
    {
        $connection = config('app.url').$endpoint;

        if (App::environment('local')) {
            $response = Http::withOptions(['verify' => false])->get($connection);
        } else {
            $response = Http::get($connection);
        }

        if ($response->successful()) {
            return $response->json()['data'];
        }
    }

When I load this page, it takes about a minute and returns a "504 Gateway Time-out". Is it not possible to make an API connection that "early" in the code, or why am I not getting any data here? The endpoint works perfectly fine when I use the same code within any Controller.

Jan
29
3 months ago
Activity icon

Started a new Conversation Best (secure) Way To Let Users Insert Custom Javascript In Laravel App

We're looking for a secure way for users to implement their own Javascript. I think this is a somewhat big security concern and we want to make sure nothing shady can be done here.

Basically, we want to have a basic field a user can insert custom javascript that then outputs on their (tenant) website. This can be trackers, chat bots and whatnot.

Is there anything we should keep in mind and look out for when allowing our customers to add their own scripts to their frontends?

Jan
11
4 months ago
Activity icon

Started a new Conversation Weird Issue With Count()

I've been trying to find out this "problem" for two hours now and I have no answer yet. The problem is within a blade view.

I have this relationship:

$categories->articles

In my blade view I loop through them and also want to show the count of the articles with {{ $categories->articles->count() }}.

On my local machine, this works just fine, but earlier today I saw that on my production server, that count was 0. Same code, same Laravel version, same PHP version.

How can this be?