Braunson

Founder at Geekybeaver

Member Since 6 Years Ago

Ontario, Canada

Experience Points
41,735
Total
Experience

3,265 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
121
Lessons
Completed
Best Reply Awards
52
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.

Level 9
41,735 XP
Aug
25
4 weeks ago
Activity icon

Replied to How Laravel Chunks Magic Methods Works?

You want to use the variable. Like so:

public function index()
{
    $allCategory = Category::latest()->get();

    DB::table('categories')
        ->orderBy('id')
        ->chunk(10, function () use ($allCategory) {

        // foreach ($allCategory as $cat) {
        //     dd($cat);
        // }
        // dd($allCategory);

        return view('cms.categories.index', compact('allCategory'));
        
    });
}

Though I'm not sure why you are doing it this way? You typically wouldn't chunk return a view.. What's your end goal?

Instead you'd do something this and then add a select or pluck on the $allCategory variable for the columns you want.

public function index()
{
    $allCategory = Category::latest()->get();

    return view('cms.categories.index', compact('allCategory'));
}
Activity icon

Replied to BadMethodCallException In Builder.php Line 2123: Call To Undefined Method Illuminate\Database\Query\Builder::visibleProjects()

You are using visibleProjects method as a scope when it's not actually a scope. Also please fix your formatting.

You can learn more about local scope here and how they are put together: https://laravel.com/docs/7.x/eloquent#local-scopes.

Your scope will likely look something like this:

public function scopeVisibleProjects($query)
{
    return $query->when($this->implementing_office_id != 1, function ($query) {
        return $query->when($this->district_id > 0, function ($query) {
                return $query->where('district_id', $this->district_id);
            }, function ($query) {
                if ($this->count() == 0) {
                    return $query->where('monitoring_office_id', $this->implementing_office_id);
                }
                return $query->where('implementing_office_id', $this->implementing_office_id);
            });
        }
    });
}
Aug
20
1 month ago
Activity icon

Replied to Error Help: Syntax Error, Unexpected End Of File, Expecting Function (T_FUNCTION) Or Const (T_CONST)

You didn't close your class with the } at the end.

Add } to the bottom of your fine on a new line. It should look like this:

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;

class ProfileController extends Controller
{
    /**
     * /username
     *
     * @param $username
     * @return Response
     */
    public function construct($user) {
        $this->user = $user;
    }

    public function show($user)
    {
        $user = $this->getUserByUser($user);

        return View::make('profile')->withUser($user);
    }

    /**
     * /profiles/username/edit
     *
     * @param $username
     * @return mixed
     */
    public function edit($user)
    {
        $user = $this->getUserByUsername($user);

        return View::make('editpro')->withUser($user);
    }

    /**
     * Update a user's profile
     *
     * @param $username
     * @return mixed
     * @throws Laracasts\Validation\FormValidationException
     */
    public function update($user)
    {
        $user = $this->getUserByUsername($user);
        $input = Input::only('location', 'bio', 'twitter_username', 'facebook_username', 'facebook_username');

        $this->profileForm->validate($input);

        $user->profile->fill($input)->save();

        return Redirect::route('editpro', $user->user);
    }

    /**
     * Fetch user
     * (You can extract this to repository method)
     *
     * @param $username
     * @return mixed
     */
    public function getUserByUsername($user)
    {
        return User::with('profile')->where('user', $user)->firstOrFail();
    }
}
Activity icon

Replied to Upload/Add Images To Laravel Markdown

That package is just a Laravel wrapper for the CommonMark package which is just a Markdown parser. While it supports embedding images in Markdown, it does not provide a UI to upload images. That would be up to you to add a UI into your editor interface to upload images and return the link and/or inject it into the editor's textarea or however you set it up in Markdown Format:

![Image](imageLink)
Activity icon

Replied to How To Start A Cron Job In A Docker Environment

Check the Laradock docs here https://laradock.io/documentation/#run-laravel-scheduler for more information on running the Laravel Scheduler.

Activity icon

Replied to Spark - Set Trial Days For Only One Plan

You can specify the trial days in three ways in Laravek Spark

  1. Per plan
    Spark::plan('Basic', 'team-basic')
        ->price(10)
        ->trialDays(10)
        ->features([
            'Five Team Members',
            'Feature 2',
            'Feature 3',
        ]);
    
  2. Globally

    Spark::noCardUpFront()->trialDays(10); (or teamTrialDays() depending on what you have setup)

  3. Both

You can apply ->trialDays(10) to the plan definition itself OR you can define it globally on the Spark class.

See https://spark.laravel.com/docs/10.0/billing near No Credit Card Up Front.

Activity icon

Awarded Best Reply on Notifications Check Every 10 Minutes

In your Vue component, add a method to check for notifications. Add another to mounted to check every 600000 miliseconds (10 minutes).

mounted: function () {
  window.setInterval(() => {
    this.getNotifications()
  }, 600000)
}

This will only work assuming they leave the component open for 10+ minutes.

While this is a quick fix, if you intend on using "real-time" notifications and data elsewhere, looking into something using Sockets or Pusher would be better, as your then listing to events coming in not setting an interval. But if you only need to check for notifications, that would be overkill and not necessary.

Activity icon

Replied to Notifications Check Every 10 Minutes

In your Vue component, add a method to check for notifications. Add another to mounted to check every 600000 miliseconds (10 minutes).

mounted: function () {
  window.setInterval(() => {
    this.getNotifications()
  }, 600000)
}

This will only work assuming they leave the component open for 10+ minutes.

While this is a quick fix, if you intend on using "real-time" notifications and data elsewhere, looking into something using Sockets or Pusher would be better, as your then listing to events coming in not setting an interval. But if you only need to check for notifications, that would be overkill and not necessary.

Activity icon

Replied to Paddle Api Question Regarding Receipts

Have you setup webhooks? https://laravel.com/docs/7.x/cashier-paddle#handling-paddle-webhooks

To test a webhook, set them up on your end in Laravel, then set the URLs in Paddle. If you are working locally, you can use something like Homestead's share or Ngrok or Expose to expose your app with a public URL.

If you want to confirm you are getting a webhook call back, throw in a logger()->info() call into the webhook code and log the incoming Request. Then just tail your Laravel logs..

Activity icon

Awarded Best Reply on What To Do With Unused Crud Methods In Controller

Why keep them if they aren't being used. Delete them. Update your resource to specify only the methods available (Partial Resource Route)

You can use ->only([]) or ->except([]) which ever you feel fits better.

The docs on this are here https://laravel.com/docs/7.x/controllers#restful-partial-resource-routes

Activity icon

Replied to Make Changes To Spark Templates Persist Updates

Due to the nature of updates, assuming you are using a version control manager like Git, you are best to skim through and compare the updated templates to see if something important was added/edited/fixed on an as needed basis.

However the docs do mention:

When you upgrade your application using php artisan spark:update, any views that have been modified will not be updated. Instead, you will simply be notified that these views were skipped.

So they shouldn't necessarily be overwritten if they have been modified.

Docs @ https://spark.laravel.com/docs/10.0/client-customization

Activity icon

Replied to What To Do With Unused Crud Methods In Controller

Why keep them if they aren't being used. Delete them. Update your resource to specify only the methods available (Partial Resource Route)

You can use ->only([]) or ->except([]) which ever you feel fits better.

The docs on this are here https://laravel.com/docs/7.x/controllers#restful-partial-resource-routes

Activity icon

Awarded Best Reply on Updating A Request

Not entirely sure the context but you can merge an array into the requests array using merge. For example:

$request->merge([ 
    'contact_id' => 1,
    'user_id' => 2
]);

Works almost the same as PHP's array_merge.

If you need to create a new row in the db using Models for each pos* item, you could grab all array keys that start with pos and then iterate through them, something like this:

$filtered = array_filter($request->all(), function ($key) {
    return strpos($key, 'pos') === 0;
}, ARRAY_FILTER_USE_KEY);

foreach ($filtered as $pos) {
    // Do something
    SomeModel::create([
        'race_id' => $request->race_id,
        'user_id' => auth()->id(),
        'pos'     => $pos
    ]);
}

Hope this helps!

Aug
14
1 month ago
Activity icon

Replied to Print Array In Blade

The array you posted is in JSON format, if it was to be a PHP array, you could loop it out like this:

@foreach ($array as $k => $v)
    Key: {{ $k }} - Value:{{ $v }}<br />
@endforeach

Which will result in something like this..

Key: 09-08-2020 - Value:4
Key: 10-08-2020 - Value:4
Key: 11-08-2020 - Value:4
etc..
Aug
08
1 month ago
Activity icon

Replied to Mix Documentation Wrong/outdated ?

No it is correct, I can confirm as I use .version() and it does indeed hash my .js/css files. What does your Laravel Mix webpack file look like, can you post it? also what version of Laravel Mix do you have in your package.json/package-lock.json?

Aug
01
1 month ago
Activity icon

Awarded Best Reply on Laravel - Collection Of Routes With Modification From Str::of

Just a suggestion, check out how Laravel does this (already) via the php artisan route:list command.

See the code here https://github.com/laravel/framework/blob/eacc34162b4cd7c1648f3029e8861e3add01f9ef/src/Illuminate/Foundation/Console/RouteListCommand.php

Jul
30
1 month ago
Activity icon

Replied to String Given Notification

@browniecoffee Are you calling showReply method directly from a route? What does it look like?

Activity icon

Replied to Sanctum Or Passport

Depends on the requirements of your project.

There is a great video about the differences of each https://www.youtube.com/watch?v=LE1TC4WS4CY.

Passport provides a full OAuth2 server implementation for your Laravel application in a matter of minutes. It is therefore necessary to have a brief knowledge of OAuth2.

Sanctum it is a simple package to issue API tokens to your users without the complication of OAuth. Sanctum uses Laravel's built-in cookie based session authentication services.

Activity icon

Replied to Old And Error Data Not Showing In Blade In Redirect Back With Input And Validator

What does your view look like. It's up to you in the view to display the error bag.

See https://laravel.com/docs/7.x/validation#quick-displaying-the-validation-errors

You will need something like this in your view that your redirecting back to:

@if ($errors->any())
    <div class="alert alert-danger">
        <ul>
            @foreach ($errors->all() as $error)
                <li>{{ $error }}</li>
            @endforeach
        </ul>
    </div>
@endif
Activity icon

Replied to (Cache) Get Expiration Remaining By Key ?

As far as I know there is no build in way to do this. Looks like there is a laravel/framework tissue on this https://github.com/laravel/framework/issues/13772 that was updated recently.

Activity icon

Replied to Separate Table Or 'signature' Column On Each Table?

Depends if your saving signatures for re-use. Having one signature per for vs multiple signatures changes things.

One signature per form - One (form) has One (siagnture) Multiple signatures per form - One (Form has many (Signatures)

It also depends what data your saving with the signature which will change how you'll want to save it. If your saving other data like, IP, signature, date, etc, a separate table is likely good to have that would belong to the form form_signature

Activity icon

Replied to String Given Notification

The error tells you exactly what the issue is.

The method showReply the second parameter is expecting (via type hinting) $notification to be an instance of DatabaseNotification class, but instead it's getting a string.

Check the parameters your passing to showReply and make sure the second parameter is an instance of the DatabaseNotification class. Don't forget to import/use it in the class containing showReply.

Jul
27
1 month ago
Activity icon

Replied to Page Settings In Chrome

I don't think that's possible from the page side, it's browser-to-browser dependent.

Jul
26
1 month ago
Activity icon

Awarded Best Reply on How To Show The Most Downloaded Pictures Within A Week

You need to record the "download" date, from there you can determine a "between" timeframe and use the whereBetween Eloquent helper.

Activity icon

Replied to How To Show The Most Downloaded Pictures Within A Week

You need to record the "download" date, from there you can determine a "between" timeframe and use the whereBetween Eloquent helper.

Jul
24
2 months ago
Activity icon

Replied to Updating A Request

Not entirely sure the context but you can merge an array into the requests array using merge. For example:

$request->merge([ 
    'contact_id' => 1,
    'user_id' => 2
]);

Works almost the same as PHP's array_merge.

If you need to create a new row in the db using Models for each pos* item, you could grab all array keys that start with pos and then iterate through them, something like this:

$filtered = array_filter($request->all(), function ($key) {
    return strpos($key, 'pos') === 0;
}, ARRAY_FILTER_USE_KEY);

foreach ($filtered as $pos) {
    // Do something
    SomeModel::create([
        'race_id' => $request->race_id,
        'user_id' => auth()->id(),
        'pos'     => $pos
    ]);
}

Hope this helps!

Jul
23
2 months ago
Activity icon

Replied to Updating A Request

Try using the merge method.

Jul
20
2 months ago
Activity icon

Replied to Where Should I Configure Trusted Proxies?

Check out this article that documents the config https://laravel-news.com/trusted-proxy

Jul
17
2 months ago
Activity icon

Awarded Best Reply on How To Get Results Of `Explain` Query In Laravel ?

You need to select the raw query..

DB::select(DB::raw('explain select * from "cats" where ("keywords")::jsonb @> forum'));
Activity icon

Replied to How To Get Results Of `Explain` Query In Laravel ?

You need to select the raw query..

DB::select(DB::raw('explain select * from "cats" where ("keywords")::jsonb @> forum'));
Jul
16
2 months ago
Activity icon

Replied to Forge Custom Provider With Custom Port

https://forge.laravel.com/docs/1.0/accounts/cookbook.html#forge-is-unable-to-access-git-repository

There are several reasons Forge may not be able to access your GitHub, GitLab or Bitbucket repository. First, you should try refreshing the source control API token that is linked to Forge via your account profile's "Source Control" tab.

Forge attempts to access your repository using your source control provider's API. The API credentials that will be used are the credentials tied to the account of the person who owns the Forge server. Note that if the Forge server is shared with you via a circle, it will use the circle owner's API credentials. You should ensure this person has full access to the repository on GitHub.

Also if it's under an organization, you need to grant Forge access to the organization to access the repository.

If all else fails, see if you have auth logs for Gitlab or contact Forge for help with the port.

Jul
14
2 months ago
Activity icon

Replied to Copy Vendor Folder Via Ftp

Looks like your composer lock file is referencing a package that is not on the FTP server.. specifically infyomlabs/laravel-generator.

Did you copy your vendor folder over to the server?

Activity icon

Replied to Tailwindcss Height Animate Transition Using Alpinejs

Take a look at this tutorial https://www.jesper.dev/posts/creating-a-dropdown-with-alpinejs/ :)

Specifically this part:

x-transition:enter="transition-transform transition-opacity ease-out duration-300"
x-transition:enter-start="opacity-0 transform -translate-y-2"
x-transition:enter-end="opacity-100 transform translate-y-0"
x-transition:leave="transition ease-in duration-300"
x-transition:leave-end="opacity-0 transform -translate-y-3"
Activity icon

Replied to Composer Error

We'll need more information than this. Is this a fresh Laravel app. What's the stack trace?

Not sure if your using this package but exact same error here https://github.com/botman/driver-facebook/issues/98

Possibly you are missing an .env key for Facebook?

Activity icon

Replied to CTO Is Strongly Pushing Selenium For Testing, What Are Your Thoughts?

I'd suggest you use what suits your needs, and your experience. If you are experienced with Dusk and it suits the requirements, then by all means use that, why be forced to learn Selenium if it's not needed. Sounds like the CTO is opinionated and likely has prior experience with Selenium.

The important question to ask:

  • is he working on the code base or building any tests?
  • what are his reasons for using Selenium instead of Laravel Dusk?

The difference between Dusk and Seleium are:

Dusk:

  • PHP
  • Browser Automation
  • Used for browser automation and testing API
  • Does not support Fixtures, Group fixtures, Generators unlike Selenium

Selenium:

  • Python
  • Web Automation
  • Used for testing web applications
  • Supports everything Dusk dues in addition to Fixtures, Group fixtures, Generators.

Other than that they are pretty much the same. Depends on what you are testing and your requirements really.

Jul
11
2 months ago
Activity icon

Replied to PHPUnit Alias Windows

@oleonides You have many options:

  1. Create an alias in Windows like @paparascal2020
  2. Using composer, globally install phpunit so you access to phpunit
  3. Create a composer "script" in the composer.json file. Like so.. (you would run composer phpunit or whatever the key value you set it.
{
    "scripts": {
        "phpunit": "vendor/bin/phpunit"
    },
}
Jul
06
2 months ago
Activity icon

Replied to File Uploads Failing On The Server

Looks like your trying to read a directory? (Notice in the error Is a directory).

Activity icon

Replied to How To Cancel $timeout Function After Load Response In It Angular Js

This is in the docs.. https://docs.angularjs.org/api/ng/service/$timeout

To cancel a timeout request, call $timeout.cancel(promise).

In tests you can use $timeout.flush() to synchronously flush the queue of deferred functions.

Jun
30
2 months ago
Activity icon

Replied to How To Get Latest In This Case?

@danlog You can lazy load with a closure. Something along these lines.

return new GroupResource(
    $group->load(['messages.user', function($query) {
        $query->orderBy('created_at'); // or $query->latest(); depending on what you want to do.
    }])
);
Jun
26
2 months ago
Activity icon

Awarded Best Reply on How To Run Npm Run Production From Model Class

While not ideal, you can use exec to execute the command.

Activity icon

Replied to How To Run Npm Run Production From Model Class

While not ideal, you can use exec to execute the command.

Jun
24
3 months ago
Activity icon

Replied to Laravel Inertia Js Error

The "u" is from undefined. Can you try logging app.dataset.page and see what returns, I have a feeling that may be the cause, dataset or page of the app object isn't defined.

Make sure you include <div id="app"></div> In your layout blade file.

Activity icon

Replied to Customizing Sanctum Unauthorized Response

If we take a look at the package's repo, specifically the src/Guard.php you'll see it's using (by default) the web guard, unless you set a specific guard in config/scantum.php line with guard.

So you can either override/modify the Authenticate.php middleware to output the message you want OR catch the AuthorizationException to output the message you want in the Exception/Handler

eg.

public function render($request, Exception $exception)
{
    if ($exception instanceof AuthorizationException) {
        return response()->json([
         'message' => 'your error message'
        ],401);
    }

    return parent::render($request, $exception);
}

Something along those lines :)

Activity icon

Replied to How To Go Incorporate Different Projects Into One?

This is a big conversation. It's hard to give advice on combining multiple projects without knowing the scope, functionality, requirements, etc.

If you want to have one "authentication gateway", you could just create an oAuth server with Laravel Passport and have all sites authenticate through that but they are still separate standalone sites.

It's hard to answer your question about using one database, scalability without more in-depth detail on what each site does, the requirements, functionality and scope. That you have to decide based on those factors.

Jun
23
3 months ago
Activity icon

Replied to Working With Large Xml/xlsx Files ?

Suggestions (some you already have done)

  • Upload file to server
  • Queue process
  • Chunk things
  • You could use updateOrCreate but I see you have a comment about checking diff between old/new data
  • Index the data
Activity icon

Replied to Confirming Successful Stripe Checkout Payments In Laravel

Your guide is https://stripe.com/docs/webhooks

So webhooks just take in the "success" from the Stripe end, what you do with it or need to do with it is up to you.

.......

You need to setup a webhook on a Laravel endpoint that's publicly accessible, then go to Stripe and set the Webhook URL for your user to that URL.

Next look at the package, follow the steps to install and this part is important...

Route::stripeWebhooks('webhook-route-configured-at-the-stripe-dashboard');

Finally, take care of the routing: At the Stripe dashboard you must configure at what url Stripe webhooks should hit your app. In the routes file of your app you must pass that route to Route::stripeWebhooks

This you would update with the webhook url you put in Stripe as the webhook.

Then under the package's Usage it shows how to handle webhook requests using jobs or an event listener (also displayed in the package Usage area of the docs). You can specify 'events' to specific jobs.

You'll want to likely use the events checkout.session.completed or checkout.session.async_payment_succeeded (both taken from the Stripe API event types docs linked above) depending on what you are looking to do.

So assuming you want to use Listeners for the event checkout.session.completed you'd do this:

  1. Create an event listener
  2. Add the event -> listener relation in the Event Service Provider
  3. Setup the webhook URL in your routes file.
  • Update your EventServiceProvider and add this..
/**
 * The event listener mappings for the application.
 *
 * @var array
 */
protected $listen = [
    'stripe-webhooks::checkout.session.completed' => [
        App\Listeners\StripeCheckoutSessionCompleted::class,
    ],
];
  • Create this app\Listeners\StripeCheckoutSessionCompleted.php with the following code:
<?php

namespace App\Listeners;

use Illuminate\Contracts\Queue\ShouldQueue;
use Spatie\WebhookClient\Models\WebhookCall;

class StripeCheckoutSessionCompleted implements ShouldQueue
{
    public function handle(WebhookCall $webhookCall)
    {
        // do your work here

        // you can access the payload of the webhook call with `$webhookCall->payload`
    }
}

Update the handle method with your logic..

We highly recommend that you make the event listener queueable, as this will minimize the response time of the webhook requests. This allows you to handle more Stripe webhook requests and avoid timeouts.

  • Setup the webhook URL in your routes file
Route::stripeWebhooks('stripe-webhooks');
  • Go to Stripe and update the webhook endpoint to be yourapp.com/stripe-webhooks

Now your done.

Activity icon

Replied to Enable Enchant Spelling In PHP?

I've never used the extension but installing it into your local instance is easy, check out this article on installing it:

https://zoomadmin.com/HowToInstall/UbuntuPackage/php-enchant

As for making use of it within your TinyMCE Editor, you'll have to look into how to use the extension.