Braunson

Braunson

Founder at Geekybeaver

Ontario, Canada

Hire Me

Member Since 4 Years Ago

Experience Points 19,255
Experience
Level
Lessons Completed 119
Lessons
Completed
Best Reply Awards 18
Best Answer
Awards
  • Start Your Engines Achievement

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • First Thousand Achievement

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • One Year Member Achievement

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • Two Year Member Achievement

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • Three Year Member Achievement

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • Four Year Member Achievement

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • Five Year Member Achievement

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • School In Session Achievement

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • Welcome To The Community Achievement

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • Full Time Learner Achievement

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • Pay It Forward Achievement

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • Subscriber Achievement

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • Lifer Achievement

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • Laracasts Evangelist Achievement

    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 Achievement

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • Laracasts Veteran Achievement

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • Ten Thousand Strong Achievement

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • Laracasts Master Achievement

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • Laracasts Tutor Achievement

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • Laracasts Sensei Achievement

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • Top 50 Achievement

    Top 50

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

20 Nov
22 hours ago

Braunson left a reply on Email Using Mailgun

If you are using Mailgun as the mail driver in Laravel, then if you are using Mailables you can specifically set the plain text of an email.

See "Plain Text Emails" in the docs here https://laravel.com/docs/5.7/mail#configuring-the-view

However if you are using the MailGun plugin/package directly, then you should refer to that packages docs/repository.

16 Nov
4 days ago

Braunson left a reply on Forcing Downloads Is Not Working In All Browsers.

Have you tried using the Lumen download method? https://lumen.laravel.com/docs/5.2/responses#file-downloads

response()->download($pathToFile)

The download method may be used to generate a response that forces the user's browser to download the file at the given path. The download method accepts a file name as the second argument to the method, which will determine the file name that is seen by the user downloading the file. Finally, you may pass an array of HTTP headers as the third argument to the method:

I've had issues with certain browsers downloading files depending on the headers set.

Braunson left a reply on How To Make Custom Eloquent Relationship Classes

Yes you can create custom relationships.

Here's an example for BelongsToEmpty, a very simple example in this case to return a valid empty BelongsTo relation.

<?php

namespace App\Relations;

use Illuminate\Database\Eloquent\Collection;
use Illuminate\Database\Eloquent\Relations\BelongsTo;

class BelongsToEmpty extends BelongsTo
{
    public function getResults()
    {
        return Collection::make();
    }

    public function get($columns = ['*'])
    {
        return Collection::make();
    }
}

I just placed this in app/Relations/BelongsToEmpty.php composer will autoload it. I can then use it in my models as needed.

For another more complex example, check out this BelongsToMorph relation class here https://gist.github.com/thisdotvoid/3022fee8afa53e45a6b89da3f16b3815

Braunson left a reply on Database Design Suggestion

  • admins

  • users

  • surveys

    • admin_id
    • name
  • survey_questions

    • survey_id
    • question
    • survey_answer_id
  • survey_answers

    • survey_id
    • survey_question_id
    • answer
  • survey_user_answers

    • survey_id
    • survey_question_id
    • user_id
    • answer

A survey can/has many questions. You can make use of the JSON/array type to store the possible answer options.

That's just one way to do it..

18 Jul
4 months ago

Braunson left a reply on URL - Remove Square Bracket From Url While Using GET Method

@sanjay that is how browsers pass an array by default to the URL. If you want a custom format, you need to implement some JS that turns the array into a string and push that as the URL.

Here's a good thread with some examples on how to take care of this both in the frontend and backend.

https://stackoverflow.com/questions/33414413/right-way-to-construct-and-accept-get-request-in-laravel-with-long-parameter-ar

17 Jul
4 months ago

Braunson left a reply on Use Tinker With Code From File

Tinker isn't for running full files of code. Instead it's meant to be able to run a few lines at a time to interact with the application without having to spin up a local server.

If your code is a class you want to interact with, include it in your app (e.g. Autoload it in) and in Tinker you can call the class and do what you need there.

tldr:: Tinker is a tool to help interact with the app without needing to spin up a server. It's a simple feature you can use to test a couple of lines you'd normally delete from your project.

Braunson left a reply on Brainstorm Help - Using Pluck In A Form::select For Default Value When It Is Null

The error means the categories collection/result is empty. There are no categories for the card.

You could instead try using the optional helper in that case. However think if there's no values you need a default. So try this out.

{{ Form::select('primary_category_id', $categories, optional($card->categories()->where('primary', 1)->first())->id ?? 1, ['class' => 'form-control', 'placeholder' => 'Please select a Primary Category']) }}

This will check for the first category with that condition and return the ID otherwise if there's no category we use the null coalescing operator (??) (PHP 7.0+) to return a (default) 1 ID, you can change this to the default you want.

Braunson left a reply on Dynamic Plan Creation

Perhaps this is closer to what you are looking for:

https://github.com/WebleIT/LaravelSparkDynamicPlanProvider

LaravelSparkDynamicPlanProvider - Laravel Spark Service Provider that allows to create Plans with Eloquent and have them created on Stripe, automatically loading them into Spark.

If you were looking to limit functionality by plan, you could use middleware/policies.

The reason for plans being setup to be static is because they reference a Stripe plan in Stripe for a set price so if you want different plans, you'll need different plans in both Stripe and Spark.

If you want to filter the plans offered to the user based on user selection just update your view that shows plans and only show the plans with X,Y,Z based on your filtering criteria. If you need to create dynamic plans, use the package linked above.

16 Jul
4 months ago

Braunson left a reply on Problem With Setting Route In Aplication

Can you post your routes.php line where it set's the route for the route your having an issue with first?

Braunson left a reply on Store An Array Of JSON Data In Mysql Database

Is your table your storing the json data set to json? You should be able to pass it a normal PHP array and it should encode and store it/return it for you accordingly. Make sure to set it as an array in your Model's casts array.

Learn more about it https://mattstauffer.com/blog/new-json-column-where-and-update-syntax-in-laravel-5-3/

Migrations support json and jsonb columns (https://laravel.com/docs/5.6/migrations#creating-columns)

Docs + Articles:

Braunson left a reply on Registration Signup Queue

Add the bool as a flag to the users table which you could call let_in which is true once they are let in. In the view you would use it to show or to hide them in the collection.

Keep a user's points for actions taken in a separate table e.g. user_points with columns like user_id, action_taken, points_added, complete_date, etc..Use a hasMany relation User -> hasMany -> user_points.

Braunson left a reply on How To Redirect Without Http?

Something like this?

redirect('https://play.google.com/store/apps/details?id=com.rovio.angrybirds&hl=en');

Or if you want to redirect to a custom URI:

redirect('example://test');
11 Jul
4 months ago

Braunson left a reply on Connection For Controluser As Defined In Your Configuration Failed In PHPMyadmin.

Sounds like your config details in phpMyadmin/config.inc.php may be incorrect.

This can occurs if you have another MySQL instance installed and the username and the password that you use in this config are different. You have to change the username and the password in the above file to match.

/* Authentication type and info */
$cfg['Servers'][$i]['auth_type'] = 'config';
$cfg['Servers'][$i]['user'] = 'root'; // << Change this to your values
$cfg['Servers'][$i]['password'] = 'root';  // << Change this to your values
$cfg['Servers'][$i]['extension'] = 'mysql';
$cfg['Servers'][$i]['AllowNoPassword'] = true;
$cfg['Lang'] = '';

Braunson left a reply on Print Dynamic Message In Session Variable

You'll want to echo out the session message in your view.

More info at https://laravel.com/docs/5.6/session#flash-data

@if(Session::has('message'))
    {{ Session::get('message') }}
@endif
10 Jul
4 months ago
09 Jul
4 months ago

Braunson left a reply on Loading A Relationship Collection

Try using whenLoaded instead of relationLoaded

Braunson left a reply on Spark Routes On Subdomain

You'll want to look into updating existing or adding new middleware ;-)

Braunson left a reply on If Users Owns A Team Show All Team Members Data

What you want to do is check in the controller if this user owns the team, then if so get all team member's IDs and use whereIn. This is assuming you only store user_id on the Timesheets table (not team_id).

public function index()
{
    $user = auth()->user();
    $team = $user->currentTeam;
    $userids = [$user->id];

    // Check if the user owns the team or not?
    if ($user->ownsTeam($team)) {
        $userids = $team->users->pluck('ids');
    }
    
    $currentweektotal = \App\Timesheets::whereIn('user_id', $userids)
                                        ->whereBetween('date', [Carbon::now()->startOfWeek(),Carbon::now()->endOfWeek()])
                                        ->sum('total');

    $previousweektotal = \App\Timesheets::whereIn('user_id', , $userids)
                                        ->whereBetween('date', [Carbon::now()->subDays(7)->startOfWeek(),Carbon::now()->subDays(7)->endOfWeek()])
                                        ->sum('total');

    $previousweekcount = \App\Timesheets::whereIn('user_id', , $userids)
                                        ->whereBetween('date', [Carbon::now()->subDays(7)->startOfWeek(),Carbon::now()->subDays(7)->endOfWeek()])
                                        ->count('total');
                       

     return view('Timesheets.index', compact('currentweektotal', 'previousweektotal', 'previousweekcount'));
}

Braunson left a reply on Password Forget Recover Using Phone

This has been addressed already https://laracasts.com/discuss/channels/laravel/send-reset-password-link-by-sms

Unless you hook a mobile phone to your server, you're going to need an external party (sms gateway) for this: https://www.google.nl/search?q=sms+gateway+laravel

There are a few to choose from, and most are easy to install.

Braunson left a reply on Composer Update Not Working In Laravel 5.6

What error do you get when you try to run composer update? More details are needed.

Braunson left a reply on Axios Not Working Though The Data Is Saved In Database.

If you watch your network calls when you save, (Chrome dev tools > Network) what is the server response? Is the call even made to the server?

Braunson left a reply on Raw Query Relationship Trouble On View

The error says assignedUsersisn't a valid property.. Try dumping the $ticket param out to see what is there. Is it an object, array or collection?

06 Oct
1 year ago

Braunson left a reply on Storing Uploaded Images

I'm thinking the best method at this point is to use the storage directory and referencing the docs at https://laravel.com/docs/5.5/structure#the-storage-directory symlink storage/app/public to public/storage.

Thoughts on any better way to do this?

05 Oct
1 year ago

Braunson started a new conversation Storing Uploaded Images

Running Laravel 5.5 on Forge. This is current flow of an image upload

  1. Uploaded to server in a temporary directory (resources/uploads/tmp)
  2. Queue process images into multiple sizes (original, large, medium, small, thumb)
  3. Queue process then moves saves those new sizes and moves the original to (public/images/large, etc.)

In the future S3 or something similar for storage is probably recommended but for now it's a side project :)

Can anyone suggest a better method to managing and serving images in this case? I'm moving 12k images over pre-launch to be resized and re-saved but wanted to see if there's a better method to do this.

03 Aug
1 year ago

Braunson left a reply on Laravel Mix And Glob

Bump, any update on this?

27 Apr
1 year ago

Braunson left a reply on On MAC : Memcached Class Not Found

Run phpinfo() and see where the config there is located to make sure it's the same you are getting in the CLI.

NOTE: There are two extensions for memcached in PHP, this may be where your having the issue.

  1. memcache
  2. memcached

It looks like you may be trying to use memcache but have the memcached extension installed.

Braunson left a reply on Route Not Find When I Use Other Function In Controller To Return View

First you should have a route, which then calls a controller method, which then displays a view. Something like this..

routes/web.php

Route::get('display', '[email protected]');

MyController.php

class MyController extends Controller { public function display() { return view('myview'); } }


You can then pass in a query into the controller method `display` like so..

$products = Product::all(); // For example return view('myview')->withProducts($products);


Then in the view you can take `$products` and loop through it and display it as you please.

Hope this guides you a bit :)

Braunson left a reply on Changing Color Of Menu Bar

If your trying to change the color of the InfyOm generator, take a look at their docs specifically on changing the template.

Take a look at this, it tells you to publish your template so you can customize the templates.

http://labs.infyom.com/laravelgenerator/docs/5.3/publish-templates

21 Apr
1 year ago

Braunson left a reply on Laravel Mix - Jquery-ui / Sweetalert2 / Jquery-validation / Lity Install

@DShannon @livijn

To use the JS of the package you've installed, you'll need to add this line to include a package in say your app.js file

require('package-name');

Regarding CSS styles, depending on how you use them, you can require them in JS/TypeScript OR include them like so in your app.css/scss

// For example, bootstrap that comes default with Laravel 5.4
@import "node_modules/bootstrap-sass/assets/stylesheets/bootstrap";
27 Mar
1 year ago

Braunson started a new conversation Navigation - Two Items 'active'

When going to this thread.. presumably others the Apparel and Discussions nav items are highlighted / have the class is-active.

https://laracasts.com/discuss/channels/general-discussion/best-shopping-cart-class

17 Nov
2 years ago

Braunson left a reply on Laravel 5.3 Maintenance Mode "message" Option Not Work

@dengdeng It looks like php artisan down simply displays this view https://github.com/laravel/laravel/tree/master/resources/views/errors

As per the docs The message value may be used to display or log a custom message which sounds confusing, doesn't it?

By default the 503.blade.php view doesn't use this message.

To read this message you should read a JSON formatted file named storage/framework/down that is generated by php artisan down command.

You need to do something like this to access the message in your view:

{{ json_decode(file_get_contents(storage_path('framework/down')), true)['message'] }}

Braunson left a reply on Stripe Webhooks Cannot Be Tested In Cashier

@bheath That's for 5+, I'm on a project that's still 4.2 (converting soon..)

Just got thinking, you could extend the WebhookController, override the handleWebhook() function to check for the environment which would dictate if it should run existsOnStripe or not.

Good to note for 5.x tho, thanks!

Braunson left a reply on Laravel Cashier Stripe Webhook Help

Yes this is 1+ years old, but having this issue with PHP 5.6.14. I made sure to run php artisan clear-compilerd; php artisan dump-autoload.

It seems the method_exists() function doesn't recognize my extended method. However if I run before it class_methods('WebhookController') it's listed first. Now if I run class_methods($this) in the same place, it doesn't show my extended method.

Anyone have any suggestions on how to resolve/fix this? I'm curious if this is PHP version related?

Braunson left a reply on Stripe Webhooks Cannot Be Tested In Cashier

@bheath I know this thread is old, I ran into this issue also.

Perhaps a workaround if your testing locally, is to open up the laravel/cashier under the vendors folder then the WebhookController.php and temporarily comment out the if statement for eventExistsOnStripe and test.

Editing vendor/core files is frowned upon but this seems like a workaround for now, unless I'm wrong and someone else has any other suggestions.

04 Nov
2 years ago

Braunson left a reply on Laravel 5.1 Remember User Country

@fant0m You'll want to look into using http://lyften.com/projects/laravel-geoip/ to get the Country/Local Currency. As for saving look at this and saving the data you want in a cookie https://laravel.com/docs/4.2/requests#cookies. Middleware would be a great use for this!

03 Nov
2 years ago

Braunson left a reply on Why Composer.lock Is Not In The .gitignore?

@willvincent As noted in the article linked above:

Don’t commit the composer.lock file if you are working on a library or package that is intended to be used only as a dependency for other projects, usually in very different projects. Furthermore, you should ensure that you list properly the package versions that your project depends on, in order to avoid conflicts in the projects where it will be installed and to maximize its compatibility. This is why you shouldn’t use the composer require command to install the dependencies, or, in case you do it, you should review manually the version added to the composer.json and ensure that it covers all the versions that are compatible with your project.

02 Nov
2 years ago

Braunson left a reply on Laravel Installation

@madala

This may be a bug. Can you tell us what packages you are requiring (composer.json)? What version of PHP are you running exactly? Are you running this on your local computer or in a Vagrant instance? Can you run php composer diagnose and post the results?

Here's a related issue thread from the Composer repo https://github.com/composer/composer/issues/2574 that may be informative

Braunson left a reply on Get All Parent Categories In A Root Parent First Order

@melkhior

So let's assume this is the structure...

Parent Category
    |- Child Category

Which looks like this in the db..

id   |    name                          |    category_id (parent category id)
------------------------------------------------
1    |    parent category   |    null
2    |    child category       |    1

What you'll want to do is have the cartegory_id as a foreign key to it's parent. Secondly you will want to setup the proper model relations.. here's an example:

class Category extends Model {
    // Each category may have one parent
    public function parent() {
        return $this->belongsToOne(static::class, 'category_id');
    }

    // Each category may have multiple children
    public function children() {
        return $this->hasMany(static::class, 'category_id');
    }
}

So now that the model relations are defined and you want to display the categories in a view, you'll do something like this to pass them to your view..

view()->composer('homepage', function($view) {
    $view->with('categories', Category::with('children')
            ->whereNull('category_id')
            ->orderBy('name', 'asc')
            ->get());
});

And finally displaying them like so..

<ul>
    @foreach ($categories as $parent)
        <li>{{ $parent->name }}
            @if ($parent->children->count())
                <ul>
                @foreach ($parent->children as $child)
                    <li>{{ $child->name }}</li>
                @endforeach
                </ul>
            @endif
        </li>
    @endforeach
</ul>

Hope that helps give you some insight in how to create same table relations :)

Braunson left a reply on Cashier: How To Create Subscription W/ PayPal Info

@Ackirb Currently Cashier only supports Stripe (https://github.com/laravel/cashier/issues/7)

I did find this repo for Braintree support at https://github.com/laravel/cashier-braintree and was last updated ~5 days ago.

Braunson left a reply on Decrypt Data Coming From API

@dneykov If you manage the script (assuming it's PHP) t hat posts to the Laravel API, why not use the same Symfony package Laravel is using but use it standalone.

If you take a look at the API docs for Laravel under the Encrypter area, https://laravel.com/api/5.3/Illuminate/Encryption.html you'll see it uses this package https://github.com/illuminate/encryption

Braunson left a reply on Retrieve Log-In Attempt Number In Laravel 5.2

This is for 5.1 but should be the same and should give you some more insight into how the Login Throttling works:

https://mattstauffer.co/blog/login-throttling-in-laravel-5.1

Braunson left a reply on Looking For A Good Youtube API Wrapper

The alaouy/Youtube is a fairly flexible package that should be able to do what you want. You can make use of searchAdvanced() to create a custom search. Alternatively, why not fork and extend the package and add new functions for what you want to do.

The package already has examples, is easy to read through, well documented and so is the YouTube V3 API https://developers.google.com/youtube/v3/

SO: Getting a User's Videos: http://stackoverflow.com/questions/22613903/youtube-api-v3-get-list-of-users-videos

27 Oct
2 years ago

Braunson left a reply on How To Use Geoip2 In Laravel 5.3 ?

@Hassan_Baloch

Have you checked out this package https://github.com/Torann/laravel-geoip? The docs are located at http://lyften.com/projects/laravel-geoip/doc/ and will help you get setup.