bufferoverflow

Member Since 2 Years Ago

Experience Points
16,510
Total
Experience

3,490 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
128
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,510 XP
Dec
17
4 weeks ago
Activity icon

Awarded Best Reply on Can Temporary Signed Routes Be Used For Guest Users?

It's fixed now!

The problem was a TeamDomain::class middleware I have in order to assign team related data to the request.

...

if ($request->route()->getName() !== 'newsletter.subscribe.confirm') {
    $request->merge([
        'team' => $team,
        'custom_domain' => $customDomain
    ]);
}

return $next($request);

The fix was not to append the data if the request is the newsletter confirmation route. Then inside the controller, I just create the contact and redirect to the success screen.

Also applied @snapey 's recommendation.

Thanks!

Activity icon

Replied to Can Temporary Signed Routes Be Used For Guest Users?

It's fixed now!

The problem was a TeamDomain::class middleware I have in order to assign team related data to the request.

...

if ($request->route()->getName() !== 'newsletter.subscribe.confirm') {
    $request->merge([
        'team' => $team,
        'custom_domain' => $customDomain
    ]);
}

return $next($request);

The fix was not to append the data if the request is the newsletter confirmation route. Then inside the controller, I just create the contact and redirect to the success screen.

Also applied @snapey 's recommendation.

Thanks!

Activity icon

Replied to Can Temporary Signed Routes Be Used For Guest Users?

Thanks for your help @jeromefitzpatrick

I dumped the data inside theUrlGenerator class and I've seen that the $original variable has some extra data appended because the user team's routes file is inside a 'team' middleware which adds additional information about the team and domain.

Not fixed yet but I found the issue and it will be fixed soon. Thanks for your help! I'll post the fix here when its done.

Activity icon

Replied to Can Temporary Signed Routes Be Used For Guest Users?

Yep, I understand. The signature is failing (because I assume the expiration is still valid after 5 secs of sending the mail).

I was using ngrok with my app domain at that moment but I tested with local domain and still failing.

The generated URL looks like this: http://mydomain.test/newsletter/subscribe/2/confirm/[email protected]?expires=1608277901&signature=a1b6c27993706374dea35fff96b579d533c9f0f0b38c83a5bcbe3b0f9b882044, so i don't think there's SSL or domain problems.

The only thing I can think about is that I'm using multitenant and custom domains. This mydomain.test is not the APP_DOMAIN, is my customer team's domain. But as long as i know, only theAPP_KEY is used, right?

Activity icon

Replied to Can Temporary Signed Routes Be Used For Guest Users?

Thanks for the reply.

There's no middleware in that route/controller. The route is publicly accessible and I checked that the hasValidSignature() is returning false.

For the other questions, I just copied the VerifyEmail signed URL because I wanted to mimic the verify email functionality. And yes I forgot to remove the sha1 and just pass team and email or maybe store the contact with "unverified" status and set up a cron to clean old unverified contacts.

But I didn't want to store the newsletter contact for legal reasons until they confirm from their email.

My idea is to do something like this after the hasValidSignature:

public function storeContact(Team $team, string $email)
{
    $team->contacts()->create([
		'email' => $email,
                'sources' => [Contact::SOURCE_NEWSLETTER]
    ])
}

The problem is that the verification is failing. And as long as i know only the APP_KEY is used, so should be correct.

Activity icon

Started a new Conversation Can Temporary Signed Routes Be Used For Guest Users?

I'm sending a confirmation email to users signing up for a newsletter. I use a temporary signed url so when the user clicks the URL they are added to the newsletter.

The problem is that the signature validation is returning false but I'm using the temporary URL generator like always so I'm guessing that maybe the validation check uses the model id to verify if that email is related to the model?

This is how I generate the route in this case

// Link generation
       $confirmationLink = URL::temporarySignedRoute(
            'newsletter.subscribe.confirm',
            Carbon::now()->addMinutes(60 * 24),
            [
                'id' => $team->id,
                'hash' => sha1(request()->email),
            ]
        );

// Validation
Route::get('/newsletter/subscribe/confirm', [NewsletterController::class, 'store'])
    ->name('newsletter.subscribe.confirm');

    public function store()
    {
        if (! request()->hasValidSignature()) {
            abort(401);
        }

       //
    }

Can it be failing because I'm passing a team id (owner of the newsletter) and Laravel tries to validate doing a $team->email === sha1(request()->email) or something like this?

This article suggests that the singed URL may need a record in the database: https://pineco.de/inviting-users-with-laravels-singed-urls/

Seems like this is the issue then?

Dec
08
1 month ago
Activity icon

Started a new Conversation A Model HasMany Different Models

I'm having problems trying to decide the correct database structure for the following scenario:

I have a Canvas model which can have many different items related:

$shapes = $canvas->shapes

I need this relationship to retrieve different kinds of shapes on different database tables: The above query should return a collection of ShapeSquare, ShapeCircle, ShapeTriangle...

I was thinking to create a Shapes table with canvas_id, shapable_id, shapable_type and then do $canvas->shapes->shapable.

Is this approach correct?

Dec
04
1 month ago
Activity icon

Started a new Conversation Livewire Temporary File Upload Directly To S3 Is Crashing

File uploads are working if using local disk but when switching to s3 driver, I get the following error:

Call to undefined method League\Flysystem\Cached\CachedAdapter::getClient()

// GenerateSignedUploadUrl.php

$command = $adapter->getClient()->getCommand('putObject', array_filter([
        'Bucket' => $adapter->getBucket(),
        'Key' => $path,
        'ACL' => $visibility,
        'ContentType' => $fileType ?: 'application/octet-stream',
        'CacheControl' => null,
        'Expires' => null,
 ]));

My config is the following:

    'temporary_file_upload' => [
        'disk' => 's3',  
        'rules' => ['required', 'file', 'max:40000'], 
        'directory' => 'livewire-tmp', 
        'middleware' => 'throttle:10,1',  
        'preview_mimes' => [  
            'png', 'gif', 'bmp', 'svg', 'wav', 'mp4',
            'mov', 'avi', 'wmv', 'mp3', 'm4a',
            'jpeg', 'mpga', 'webp', 'wma'
        ],
    ],

I have this same s3 disk working for other uploads. It's just crashing for the temporary uploads from Livewire.

Nov
27
1 month ago
Activity icon

Started a new Conversation Don't Match Regex Expression If String IS Certain String

I want to use a regex match to find if a string is a domain/custom domain or my app domain. I've managed to match the domains with this expression:

Route::pattern('domain', '[a-z0-9.\-]+');

But I would like to don't match if the string IS my app domain.

user.com -> match
sub.mydomain.com ->match
mydomain.com -> no match

I've tried testing lookahead in https://regex101.com/ but I can not make it work. The best try is this one:

(?!domain\.com)[a-z0-9.\-]+
// but "omain.com" still selected

Screenshot -> https://imgur.com/b3h79Xs

Nov
20
1 month ago
Activity icon

Started a new Conversation Let's Finally Solve The Eternal Question About Routing The App, Subdomains And Custom Domains.

I've seen this question on the internet many times but seems like no one is able to give a solution.

The scenario is really simple:

Having routes for your app which allows your users to use either subdomains or custom domains. That means that we need a standard web.php routes file and then a user.php routes file containing the routes that custom domains and subdomains will use.

If someone accesses app.com will see your app (where users log in / register, update settings, manage data, etc...). If someone accesses user.app.com will see the user content. If someone accesses user.com will see the same user content if they configured a custom domain.

After many tries, I did this, which seemed to work:

// RouteServiceProvider

    public function boot()
    {
        $this->configureRateLimiting();

        $this->routes(function () {
            if (is_team_host()) {
                Route::middleware('team')
                    ->namespace($this->namespace)
                    ->group(base_path('routes/team.php'));
            } else {
                Route::domain(config('app.domain'))
                    ->middleware('web')
                    ->namespace($this->namespace)
                    ->group(base_path('routes/web.php'));
            }
        });
    }

Worked well because when accessed from a user host, the web routes are not registered. The problem is when you run php artisan route:cache, the helper method causes some issue and the routes return 404.

Another attempt. Also works but route:cache can not be triggered since it detects duplicated routes (since app and team pages have auth routes and views).

// RouteServiceProvider

    public function boot()
    {
        $this->configureRateLimiting();

        $this->routes(function () {
            Route::domain(config('app.domain'))
                ->middleware('web')
                ->namespace($this->namespace)
                ->group(base_path('routes/web.php'));

            Route::middleware('team')
                ->namespace($this->namespace)
                ->group(base_path('routes/team.php'));
        });
    }

For now, I can only make it work without the route cache.

Any suggestions?

Nov
19
1 month ago
Activity icon

Replied to Laravel Jetstream Ignore Routes Not Working

Yes! Seems I used the wrong method. Thanks!

Activity icon

Started a new Conversation Laravel Jetstream Ignore Routes Not Working

I started a new Jetstream app where I need to use team uuid instead of the id. For this reason, I'm trying to override the default routes so i can point to custom controller and retrieve the team model by uuid.

The problem is that after doing this...

// JetstreamServiceProvider
public function boot()
{
    $this->configurePermissions();

    Jetstream::ignoreRoutes(); // this
}

... I can still access the /tems/{teamId} show route.

I can't understand why the routes are still being registered.

Nov
07
2 months ago
Activity icon

Started a new Conversation Livewire + Alpine Equivalent Of Axios Call + Do Something With The Return

I recently started playing with Livewire. There's one scenario where I can not find the right solution at the documentation and I need some advice from a more experienced Livewire + Alpinejs user.

For example, when working with Stripe, what I usually do is post an ajax request that will generate the session id at the backend and then return to the front where the Stripe code redirects the user to the payment page.

How would you implement this with Livewire and Alpine?

I've tried this but it doesn't work:

<div>
    <button wire:click="$wire.checkout().then(result => console.log(result))">
        <span>{{ $pricing->name }} ({{ $pricing->type }})</span>
        <span>
                {{ $pricing->price }} {{ $pricing->currency }}
            </span>
    </button>
</div>

Finally used this approach but, is there any better approach?

// Livewire method
$this->dispatchBrowserEvent('checkout-created', $session->id);

// Front
window.addEventListener('checkout-created', event => {
      goToCheckout(event.detail)
})
Oct
20
2 months ago
Activity icon

Replied to Good Video Service For An Education Saas

I really appreciate your feedback @sinnbeck

Actually, I already know the technical part, I just wanted to open a discussion about video hosting and streaming providers because I'm new to the e-education world and maybe I missed some important services while researching online.

Really interested in services that I can pay per user or per usage. Because I don't want to pay Vimeo 600$ while having 0 users. I need something that i can know the cost per user so I can charge it in their fee.

Thank you

Activity icon

Replied to Good Video Service For An Education Saas

Thanks for the feedback.

I think Laracasts use Vimeo. But the scenario is a bit different because Laracasts is the only one uploading videos. I will take a look at this resource but I'm not sure if this will fit my scenario since every user is uploading their content and serving from their custom domain.

Thanks

Activity icon

Started a new Conversation Good Video Service For An Education Saas

I'm building an educational saas app where my users are going to upload videos.

I don't want to host and stream them, so I'm trying to find a good service with nice API. Has anyone been in this spot before or has some recommendations?

Thanks!

Sep
09
4 months ago
Activity icon

Replied to Subdomains And Authenticated Actions On The Main Domain

What do you mean?

Sorry if my explanation was not good. What I mean, is that the users of my saas, can chose a subdomain or domain where their content will be displayed.

I solved it using a route pointing the main Laravel app.

Aug
25
4 months ago
Activity icon

Started a new Conversation Subdomains And Authenticated Actions On The Main Domain

I'm building an app where my users can create their own page in a subdomain or custom domain.

The challenge here is that in those pages, the visitors can click a button that does a certain action in the main website/domain, the app domain. And that action needs to check whether they are logged in or not in order to decide if redirect them to login or proceed with the action.

Obviously now it doesn't work because the code is checking if the user is authenticated in the subdomain or custom domain of the user, which is always going to be false. I'm trying to find a clean and standard way to execute authenticated actions in the main app from those custom pages.

The first thing it comes to my mind is using the API. Although I am not an expert working with API I think I should put some kind of limitation, so only calls from my user's domains can be executed? But also I think the only way to check if a visitor of those websites is authenticated is to check the cookies in his browser from my main domain, is that correct?

Is this approach correct? Am I missing something?

Thanks!

Edit:

I found this answer here, but I'm not sure if that is a good practice... https://laracasts.com/discuss/channels/laravel/authentication-across-different-subdomains

Activity icon

Replied to Mailgun Driver Not Sending Email And Not Giving Any Error

And maybe the manual config:cache worked, because i can see the logs after that.

I found what's the issue I think. I don't know why it is randomly sending the mails to the spam folder. Some end up there and some end up at the inbox.

Activity icon

Replied to Mailgun Driver Not Sending Email And Not Giving Any Error

Yes, it's in my deploy script and also tried manually from terminal.

My deplay script has: php artisan config:cache

Not sure if I have to add php artisan config:clear before that

Activity icon

Started a new Conversation Mailgun Driver Not Sending Email And Not Giving Any Error

I'm using the Mailgun api driver for sending the transactional emails. I followed the documentation and it's working in my local machine.

I pushed to production but no emails are sent and the Mailgun dashboard shows no activity.

I checked other questions from people with similar problems but seems like everything is okay.

This is what I've done:

  • Check Laravel logs and Mailgun logs
  • Make sure Guzzle is installed
  • Define env varaibles
MAIL_MAILER=mailgun
MAILGUN_DOMAIN=mg.domain.com
MAILGUN_SECRET=my_secret
MAILGUN_ENDPOINT=api.eu.mailgun.net
[email protected]
MAIL_FROM_NAME="${APP_NAME}"

What else can i do to debug this issue?

Aug
09
5 months ago
Activity icon

Replied to Cashier With Stripe Webhook Not Updating The Model

Thank you so much. I've solved the problem now.

Not extending the original class I've realized that the original one was still hit. That's because my endpoint was /stripe/inbox since i changed many times for testing and i forgot to update it in Stripe's dashboard so it was still using the old /stripe/webhook endpoint.

Activity icon

Replied to Cashier With Stripe Webhook Not Updating The Model

Same result.

I thought maybe some other method, file or route overriding or something. But I can not find anything that makes sense for now.

Activity icon

Replied to Cashier With Stripe Webhook Not Updating The Model

Yes.

[2020-08-09 14:33:13] local.INFO: method doent exits: handleCheckoutSessionCompleted

Activity icon

Replied to Cashier With Stripe Webhook Not Updating The Model

Yes, sorry. I should have given some code.

After investigating more about it, I think I've found the problem. Seems like the method I extended can not be found.

Basically Stripe is posting to this endpoint: Route::post('/stripe/inbox', [CashierWebhookController::class, 'handleWebhook']); which has the following code:

<?php

namespace App\Http\Controllers;

use App\Models\User;
use Illuminate\Support\Arr;
use Illuminate\Support\Str;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\DB;
use Laravel\Cashier\Events\WebhookHandled;
use Laravel\Cashier\Events\WebhookReceived;
use Laravel\Cashier\Http\Controllers\WebhookController as CashierController;

class CashierWebhookController extends CashierController
{
    public function handleWebhook(Request $request)
    {
        $payload = json_decode($request->getContent(), true);
        $method = 'handle'.Str::studly(str_replace('.', '_', $payload['type']));

        WebhookReceived::dispatch($payload);

        if (method_exists($this, $method)) {
            $response = $this->{$method}($payload);

            WebhookHandled::dispatch($payload);

            return $response;
        } else {
            info('method doent exits: ' . $method);
        }

        return $this->missingMethod();
    }

    // this method is not found!
    public function handleCheckoutSessionCompleted(array $payload)
    {
        info('stripe is posting');
    }
}

For some reason the method_exists($this, 'handleCheckoutSessionCompleted') returns false.

Aug
07
5 months ago
Activity icon

Started a new Conversation Cashier With Stripe Webhook Not Updating The Model

I create a checkout session, complete the payment and get redirected to the success URL.

Then, I'm expecting Stripe to hit the endpoint i defined at the Stripe dashboard (using ngrok since its in my local machine), but it never hits and the code doesn't get exectued.

Also I tried to send a test request inside the Stripe's webhook dashboard and it says: "Success. Webhook Handled" but it never hits my code since I have a log inside the method.

I'm kind of new with webhooks. Am I missing something?