Braunson

Member Since 5 Years Ago

Ontario, Canada

Founder at Geekybeaver

Experience Points 26,045
Experience Level 6

3,955 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 120
Lessons
Completed
Best Reply Awards 29
Best Reply
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 Mar
4 days ago

Braunson left a reply on Can't Update Config File

Config::set will set the value for runtime only. It won't save it to the config file.

If you want persistent configurations take a look at Update Config on Runtime Persistently

Braunson left a reply on How Search For Multiple Words In Eloquent?

If you wanted to use space as the the delimiter.. something like this

$query = Input::get('q'); //  'john doe';

// Let's split on 1+ whitespace & ignore empty (eg. trailing space)
$searchValues = preg_split('/\s+/', $query, -1, PREG_SPLIT_NO_EMPTY); 

$deviceInspections  = DeviceInspection::whereHas('sale', function ($query) use ($searchValues) {
    foreach ($searchValues as $value) {
        $query->orWhere('sale_number', 'like', "%{$value}%");
    }
})->paginate(20);
18 Mar
6 days ago

Braunson left a reply on Running Multiple Homestead Instances

Soo sorta. You can specify the (Homestead Supported) version of PHP you want in the Homestead.yaml file. However for 5.6 since that's no longer supported in Homestead, there's a (paid) option like Homestead Fifty Six which you can check out here https://laravel-news.com/homestead-fifty-six

Alternative options are using a Docker image or creating your own unfortunately :(

Braunson left a reply on What Happens To Team Subscription When Team Is Deleted?

Looking at the latest Spark code, when deleting a team, the event TeamDeleted is fired which has a listener called UpdateOwnerSubscriptionQuantity called.

Looks like it decreases the subscription there BUT only if your are charging PER SEAT. I agree if a team is deleted, it should cancel the Stripe subscription.

13 Mar
1 week ago

Braunson left a reply on Laravel Equivalent Helpers For Javascript

I haven't found any up to date NPM packages or plugins that do this. It would make a great package to build to match all (or most) helpers in Laravel but in JS :)

This library has pretty much all implementations of PHP functions in JS. So if you deconstruct the Laravel helpers and use this library, you can build a pretty closely matching NPM package!

http://locutus.io/php/

Braunson left a reply on How To Remove The # Tag Url In The Production Mode Angular Version 1.7.3

This is probably better in #javascript but if we check the docs for Angular, you'll want this info https://angular.io/api/common/HashLocationStrategy

In your code you'll want to find something like this..

RouterModule.forRoot(routes, { useHash: true })

Then change the boolean to false for useHash ;-)

Braunson left a reply on Queue:Restart Problem

Try clearing your framework cache

Braunson left a reply on Forge's Db.sh.swp File

A .swp file is ot a swap file in the OS sense but instead a state file. A type of lock file. It keeps your changes since the last save, buffers you have saved, unsaved macros, and undo structure.

Typically they are created with vim and should automatically be deleted when VIM is closed and exited.

Get in touch with Forge support and see if it's one of their files open perhaps otherwise I'd probably delete it.

Braunson left a reply on Date|Time|Timezone Best Practices?

Store everything as UTC, then set the timezone per user when they login. Laravel will take care of the rest. Here's some helpful links..

There are many other threads about this on the forum, give it a search :)

Braunson left a reply on Could Not Open Input File: /home/forge/dev.mysite.com/artisan

What user is it running as on Forge? I'm using the same syntax but Forge is the user running the task..

11 Mar
1 week ago

Braunson left a reply on Not Allow A User To Fill A Form Input Unless Previous Input Is Valid

Something like this..

var input1= document.getElementById("input1");
input1.onchange = function () {
   if (this.value != "" || this.value.length > 0) {
      document.getElementById("input2").disabled = false;
   } else {
      document.getElementById("input2").disabled = true;
   } 
}
02 Mar
3 weeks ago

Braunson left a reply on Create A Code With Expiration Time

You'll likely want to use something like Twilio to do this.. check this guide out https://www.twilio.com/docs/authy/tutorials/account-verification-php-laravel

28 Feb
3 weeks ago

Braunson left a reply on Mysql Not Restarting

First look would be to run journalctl -xe for details on WHY it's not loading, that should give you a starting point of where to look/whats going.

Braunson left a reply on After Installing New Nova:card Found 27 Vulnerabilities (1 High)

Well you have to find out what the vulnerabilities are. Run npm audit to see more details, from there you can make a judgement call (and/or post here).

While we don't know what they are, you do have 1 high which is what I'd probably focus on first to see what it is.

16 Feb
1 month ago

Braunson left a reply on Nested Object In Response API

Use the with method :)

Trainer::find(1)->with('fighters')->get();
15 Feb
1 month ago

Braunson left a reply on Ternery Operator Help

Ok let's break down this code, specifically everything inside the {{ }}

!empty($make->status)?($make->status==1)? 'selected':'':'selected'

The code is likely to not work as it's missing some brackets, technically this is a shorthand if statement. Really in longform what it's doing is..

// Is the make status FILLED?
if (! empty($make->status) {
        // Is the status == 1?
    if ($make->status == 1) {
            return 'selected';
        // else no it isnt
        } else {
                return '';
        }
// else default to selected
} else {
    return 'selected';
}

What you instead want is this line..

! empty($make->status) ? ($make->status == 1 ? 'selected' : '') : 'selected'

Used like so:

<option value="1" {{ ! empty($make->status) ? ($make->status == 1 ? 'selected' : '') : 'selected' }} >Active

If you wanted to visually break it down for easier understanding..

! empty($make->status) ? // If the status is not empty then run the line below
    // check if status == 1 and if so return 'selected' otherwise return nothing
    ($make->status == 1 ? 'selected' : '') 
: // else
    // return selected
    'selected'

Hope this helps you understand the statement better.

Braunson left a reply on Homestead : Homestead.yaml Config

This is what you want to do. You have to map your projects folder to a folder on the Virtual Machine/Homestead, that's under folders. Then you need to map a domain from the VM/Homestead to a folder within the VM which is undersites

So we first map the folder from LOCAL machine to VIRTUAL machine. Then we map a site from DOMAIN to VIRTUAL machine folder (that was previously mapped out from LOCAL machine the step before.


folders:
    - map: "D:/iaccs-admin-console"
      to: "/home/vagrant/code"

sites:
    - map: notification.test
      to: "/home/vagrant/code/public"

Then all you have to do is up the VM and add to your hosts file the IP from the Homestead.yaml file with your domain you defined under sites.

// in your hosts file
192.168.10.10 notifications.test

Braunson left a reply on Spark - Eloquent Relationships For Teams

Well this depends on what you want to do? Do you need to know which user from X team created it? Are you using that information (the user of the project) for any reason? If yes record both the user and team, otherwise just stick with the team.

13 Feb
1 month ago

Braunson left a reply on How Can Be Validated Any File Type In Laravel ?

You can only validate file (mime) type (not the contents of the file).

Check this for Mime Type https://laravel.com/docs/5.7/validation#rule-mimetypes

Check this for Mime Type by File Extension https://laravel.com/docs/5.7/validation#rule-mimes

11 Feb
1 month ago

Braunson left a reply on WhereNotIn Not Working

whereNotIn is not valid. You'd typically use whereIn with an array for example:

->whereIn('type', ['completed', 'failed', 'pending'])

Since you want to get all bookings that don't have error as the Payment_Status you would simply do this.

->where('Payment_Status', '!=', 'error');

Braunson left a reply on Get URL Changed By Pushstate

The reason your seeing the repeating ?page is because your getting the HREF which is getting the protocol, domain and any params.

Instead try something like this (with window.location.origin)..

function updateUrl() {
    history.pushState(null, null, `$(location.origin)/?page=` + this.page);
}

Braunson left a reply on Add Blank Spaces In A String For Input Value

Not a simple solution snippet but check this out https://niksmr.github.io/vue-masked-input/ for a simple (as they type) custom text mask in Vue.

10 Feb
1 month ago

Braunson left a reply on Laravel 5.7 : Clean Way To Apply Policy Scope Based On User Role

Try this :)


function scopeAdminAuthor($query)
{
    return $query->when(auth()->user()->isAdmin(), function ($q) {
            return $q->where('author_id', 'auth()->user()->id);
        });
}
08 Feb
1 month ago

Braunson left a reply on Ajax Call Every 10 Min

In your dev tools, watch for the ajax call and see what's exactly being returned to you (HTTP Code + Response)

Braunson left a reply on Send Email Using Notification In Laravel 5.4

You have to use Notify on the model with the Notifiable trait included on it. In this case your trying to run ->notify() on a strong from the request.

You are defining this just above the notify call:

 $emailSend = $request->emailCopy;

Instead you should be using notify() on an existing Contact instance.

Braunson left a reply on How Can I Not Use Facade In Controller?

Use the helper function.. auth()->check()

07 Feb
1 month ago

Braunson left a reply on Horizon Not Starting Up After Deploy (must Run `php Artisan Horizon`)

Hmm if the daemon isn't being terminated on deploy success and thus restarting the 'Horizon' process then I'd look at the supervisord/daemon logs to see what went wrong/why the daemon didn't restart Horizon.

Typically running horizon:terminate will kill the daemon, when the daemon is killed supervisor will realize this and boot up a new daemon.

I would suggest checking the log for the supervisor daemon as well as tailing it when you do a deploy to see what exactly happens when it tries to restart!

04 Feb
1 month ago

Braunson left a reply on Calling Functions Inside Same Controller

If I understand correctly, just call them within your if statement.. assuming the functions being called are in the same controller..

public function process(Request $request)
{
    switch($request->paymenttype) {
        case 1:
            $order = $this->processFoo($request);
            break;
        case 2;
            $order = $this->processBar($request);
            break;
        default:
            return view('checkout.error')->withError('No payment type was found');
    }

    return view('checkout.complete', compact('order'));
}

public function processFoo(Request $request)
{
    // ... Do stuff

    return $order;
}

public function processBar(Request $request)
{
    // .. Do stuff

    return $order
}
31 Jan
1 month ago

Braunson left a reply on Facing An Issue On SSL

What's your issue exactly? SSL is enabled work on that site provided?

Braunson left a reply on Dealing With Carbon Instance Before And After Saving

@eleven0 With one field, you could override the getters in the model, so if you have say:

  1. The field with date and time as datetime which includes the date and time stamp
  2. Append a new getter to the model for time and return $this->datetime->format('g:i A');
  3. Append a new getter to the model for date and return $this->datetime->format()->toFormattedDateString();
30 Jan
1 month ago
28 Jan
1 month ago

Braunson left a reply on Laravel Media Library Optimize Query

I'd suggest eager loading the media for the shops so you don't have to make a query per shop.

Braunson left a reply on Frontend For Laravel

This is a very broad question and varies depending on your requirements. I'd suggest taking a look at React Native and Vue Native as you can use it to build both a "Native" and web based frontend for your app.

Take it as a grain of salt, I'm sure other people here have better suggestions :)

Braunson left a reply on Most Revenue From Users.

Something along the lines of..

// Get within the current month
$month = Carbon::now()->startOfMonth();

// Eager load our orders for our users by month
// Then order by the sum of the orders total descending
// Take 5 and return
User::with(['orders', function($query, $month) {
        $query->where('created_at', '>=', $month)
    }])
    ->orderByRaw('SUM(orders.total) DESC')
    ->take(5)
    ->get();

Braunson left a reply on Dealing With Carbon Instance Before And After Saving

  1. Yes See "Date Formats" under "Date Mutators" here https://laravel.com/docs/5.7/eloquent-mutators#date-mutators

  2. https://github.com/briannesbitt/Carbon/blob/8bff6de7dc4f4cc4fde8fd7c5aebb0c14d13266d/src/Carbon/Traits/Creator.php#L118

  3. Depends on what you want to do/use it for. You can store just a timestamp or you can store just a datetime string. Personally i'd use datetime for storing the date and time rather t hen two separate fields.

26 Jan
1 month ago

Braunson left a reply on Laracast Lifetime Subscription

Yes it does, it's on the signup page under "Forever". It's $350 US. In the FAQ it mentions about paying with PayPal, and if PayPal is the only way you can sign up, Jeffrey will accept them manually. The link in the FAQ takes you to a page to pay $99, but since you want the lifetime/forever subscription I'd suggest you get in touch directly with Jeffrey!

You can do this by going to the home page, scrolling to the bottom and clicking 'Support'. A form will appear for you to fill out :)

25 Jan
1 month ago

Braunson left a reply on PHP CS Fixer With Homestead

AFAIK PHPCS requires PHP and to use it with the Sublime extension, you need PHP installed. It's fairly trivial to install PHP locally?

Braunson left a reply on Laravel Mix Upgrade Best-practices

Typically I keep it in sync with the framework releases (every other minor/major), but regardless I'd look at the Laravel mix changelog and see what you need to update (if you need to update any dependencies).

Braunson left a reply on How Do I Pass The Value Of The Token Inside The Transformer?

If the token is on the user model, it should be accessible in the transformer as ->token?

I believe you should be able to pass it as a param in new UserTransformer($fooParam) and then in the transformer..


    public function transform(User $user, $fooParam)
    {
        ...
     }

Braunson left a reply on Understanding Laravel Queue's Jobs When Failing..

You can use the method helper attempts() (if using 5.2 or older) or try ->attempts to get the number of times the job has been attempted.

Then inside your failed() method, you can adjust the seconds of release based on the attempt number.

I'm not sure why attempts() was removed after 5.2 but it should still be accessible on the job itself.

When releasing the job back into the queue, it's released into the back of the queue.

Braunson left a reply on SQL Error From Queue:work

Are you running out of storage? Sometimes write access can be disabled if there is not enough space to write anything.

Other plausible reason are:

  • being throttled somehow?
  • trying update statements on a read-only replica (e.g. the entire instance is read-only/is a follower)?

Try manually running SELECT pg_is_in_recovery() and logging the response (in the jobs) to see if when it does throw that error if it's in recovery mode. If it's true, then it's likely connected to a read-only replica server in hot_standby mode.

Otherwise I'd get in touch with Heroku

Braunson left a reply on Recommend Me A Beautifier For Atom (esp. For Blade)

atom-beautify is pretty decent/popular. I'd suggest filling out an issue on the GH repo https://github.com/Glavin001/atom-beautify/issues?q=is%3Aissue+is%3Aopen+sort%3Aupdated-desc

Braunson left a reply on Spark Setup

Sounds like your domain/host isn't pointed properly to the /public folder?

Braunson left a reply on SQLSTATE[40001]: Serialization Failure: 1213 Deadlock Found When Trying To Get Lock; Try Restarting Transaction (SQL: Delete From `jobs` Where `id` = 2592546)

This happens when two processes or more are trying to write to the same database table at the exact same time. Solutions can be complicated. Deadlocks are usually an application problem most of the time can either be solved by:

  1. changing the logic of your code (e.g. use transactions) or
  2. retrying the operation

If you are using the database queue driver, it may be you have two queue workers running and trying to complete the same job as each other. Try another queue driver (if your using Laravel Homestead, you can use redis)

Additionally I'd suggest looking into Transactions as they provide an automatic retry feature. Learn more at https://laravel.com/docs/5.7/database#database-transactions

Braunson left a reply on Bootstrap Clone Datepicker 'start Date' And 'end Date' Is Not Working In Javascript?

Is the js library/plugin included? Is it accessible from the developer tool console? Do you have any errors in the developer console of your browser?

When you say clone text box, are you loading the page, then cloning the text box that's suppose to be a date picker? If so when you clone the textbox, you need to re-initialize the datepicker in js for that element.

Braunson left a reply on Custom Validation Of Dates In Laravel 5.4

Why not use a form request and instead of a custom rule, using a FormRequest?

// in your rules method() of the form request
$after_date = now()->parse($this->departureDate)->addDays(3);
0days = now()->parse($this->departureDate)->addDays(180);

return [
      'departureDate' => 'required|date|after:now',
      'returnDate' => 'required|date_format:"Y-m-d"|after:' . $after_date->toDateString().'|before:' . 0days->toDateString()
]

// in your messages() method of the form request
return [
       'departureDate.after' => 'Your departure date should be tomorrow or any date in the future',
       'returnDate.after' => 'Your return date should be 3 or more days after the departure date',
       'returnDate.before' => 'Your return date should be no more than 180 days from the departure date',
];

Of course you'll want to change the date format to match yours.

Braunson left a reply on How To Dynamically Append Multiple Conditions To Laravel Query?

There's a great article related on what you want to do here https://laraveldaily.com/less-know-way-conditional-queries/

Pretty much you want to change the if statements into when statements. Here's a "optimized" version of your top code..


$page_slug = $request->get('page_slug');
$min_price = $request->input('min_price', false);
$max_price = $request->input('max_price', false);
$product_condition = $request->input('product_condition', false);
$products = null;
$products2 = null;

// Get the categories
$getCatlvl1 = Category::whereCategorySlug($page_slug);
$getCatlvl2 = SubCategory::whereCategorySlug($page_slug);
$getCatlvl3 = SubCategoryLvl3::whereCategorySlug($page_slug);

// Do we have a count?
if ($getCatlvl1->count()) {

    // Get the category levels
    $category_level1_id = $getCatlvl1->pluck('id')
                                        ->toArray();

    $category_level2_id = SubCategory::where('parent_category', $category_level1_id)
                                        ->pluck('id')
                                        ->toArray();

    $category_level3_id = SubCategoryLvl3::whereIn('parent_category', $category_level2_id)
                                        ->pluck('id')
                                        ->toArray();

    $product_lookup_1 = DB::table('products')
                    ->where('category_level', 3)
                    ->whereIn('category', $category_level3_id)
                    ->when($product_condition, function($query, $product_condition) {
                        $query->where('product_condition', $product_condition);
                    })
                    ->when(($min_price AND $max_price), function($query, $min_price, $max_price) {
                        $query->whereBetween('selling_price', [
                            $min_price,
                            $max_price
                        ]);
                    });

    $product_lookup_2 = DB::table('products')
                    ->where('category_level', 3)
                    ->whereIn('category', $category_level3_id)
                    ->when($product_condition, function($query, $product_condition) {
                        $query->where('product_condition', $product_condition);
                    })
                    ->when(($min_price AND $max_price), function($query, $min_price, $max_price) {
                        $query->whereBetween('selling_price', [
                            $min_price,
                            $max_price
                        ]);
                    })

    $products = $product_lookup_1->paginate(40);
    $products2 = $product_lookup_2->get();
}

Braunson left a reply on Route Redirection After Login

  1. Make sure your route is properly registered (the 404 tells me it likely isn't)
  2. Update the login() method to redirect to the route you want.

Braunson left a reply on How To Create Url Signature On The Place Of Parameters In Laravel 5.5

What you want is obfuscating/hash the IDs of your variables. Check this article out :) https://sampo.co.uk/blog/masking-ids-in-urls-using-hash-ids-in-laravel

23 Jan
2 months ago

Braunson left a reply on Reusable Query Parts

If you use Models (not DB) you can create global/scopes and relations. As for DB there's no easy helper like that AFAIK. What you could do is create a function that takes care of this once for you. Like so:

protected function dbQuery($table_name)
{
    return DB::table($table_name)
            ->join(...) //I want reuse this join
            ->join(...) //I want reuse this join
            ->join(...); //I want reuse this join
}
public function someQuery()
{
    return $this->dbQuery('some_table')
                ->select(...)
                ->where(...)
                ->groupBy(...)
                ->get();
}

public function someOtherQuery()
{
    return $this->dbQuery('some_table')
                ->where(...)
                ->count(...);
}