BryanK

BryanK

Member Since 1 Year Ago

Experience Points
50,180
Total
Experience

4,820 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
443
Lessons
Completed
Best Reply Awards
9
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 11
50,180 XP
Jun
02
1 day ago
Activity icon

Replied to Could Not Find Driver

What OS is the server?

Activity icon

Replied to Is WhereIn Possible With Eloquent On Array With A Null Value?

No problem!

Michal's solution conditionally checks if an empty string is in the array and then adds the NULL check orWhereNull().

Didn't realize that was a criteria.

Just realize that an empty string '' is not NULL in a database, so if you need to check for both, Michal's solution will not work.

Activity icon

Replied to Getting 500 Unable To Handle Requests

What event is being fired when you visit that page?

What are you fetching from https://instacks.in/superadmin/dashboard ?

Activity icon

Replied to Product Assignment To Category

That could certainly work. That's similar to a datalist.

Since you have 600 possible choices, it seems like you would want them to drill down into the subcategories after picking a main category.

But I cant answer that. It all depends on how you need to show the user the data.

Activity icon

Replied to Is WhereIn Possible With Eloquent On Array With A Null Value?

Go raw then:

$query->whereRaw('`search` IN ('.implode(',',$searchArray).') OR `search` IS NULL');

Just make sure the $searchArray isn't coming from user input.

Activity icon

Replied to Is WhereIn Possible With Eloquent On Array With A Null Value?

WHERE `field` IN does not support NULL in sql.

You need to add orWhereNull('search')

$query->whereIn('search', $searchArray)->orWhereNull('search');
Activity icon

Replied to 413 Payload Too Large Problem

How large is the file you're uploading? Is it larger than 9.76MB?

Do you have a reverse proxy for your front end?

Activity icon

Replied to Product Assignment To Category

I don't know what your users need to see when deciding on a category.

If all you need is the category name and its id, then just use that.

If they need to see more, you may want to use an autocomplete where they can start typing and you can display anything they need to see (description, image, etc) to help them make a decision.

Activity icon

Replied to Product Assignment To Category

You can have a datalist for the categories, then once chosen, either by refresh or ajax, show the list of subcategories.

That way at least the subcategories aren't shown until you know what cat they are picking (which I assume is the bigger number).

A datalist will let them click and dropdown and type.

<input list="category" name="category" />
    <datalist id="category">
        <option value="cat1">Category 1</option>
        <option value="cat2">Category 2</option>
        <option value="cat3">Category 3</option>
        <option value="cat4">Category 4</option>
    </datalist>
Activity icon

Replied to How To Send Confirmation Mail To New Email Address In Laravel?

Do you have domain authentication (under Send Authentication) in your sendgrid settings?

Activity icon

Replied to VueJS Chat, Broadcasting Doesn't Seem To Be Working....

Actually, looking again at your API message, I don't see the private word on the channel.

It should say Channel: private-groups.2 if private.

Try Echo.channel('groups.' + this.group.id)

Activity icon

Replied to VueJS Chat, Broadcasting Doesn't Seem To Be Working....

Does the console.log you have for the event listener ever fire?

Activity icon

Replied to VueJS Chat, Broadcasting Doesn't Seem To Be Working....

Can you comment out the Echo listenForWhisper section in created() and then move this.listenForNewMessage() from mounted() into created()?

See if that gets it initialized.

Activity icon

Replied to VueJS Chat, Broadcasting Doesn't Seem To Be Working....

Can you post your API message from pusher?

Activity icon

Replied to How To Send Confirmation Mail To New Email Address In Laravel?

Hmm...what server on you on?

You can turn tls off for testing, but I don't recommend keeping it that way:

MAIL_ENCRYPTION=null
Activity icon

Replied to VueJS Chat, Broadcasting Doesn't Seem To Be Working....

In Vue, created() is fired before mounted(), so you need to set your vars in data or above your Echo listener in created().

I would do it like this so that the data is set before you try to use it:

data() {
        return {
            message: '',
            messages: this.group_data.messages,
            typing: '',
            group: this.group_data,
            unReadCount: '',
            currentUser: this.user,
            groupId: this.group_data.id,
        }
    },
Activity icon

Replied to How To Send Confirmation Mail To New Email Address In Laravel?

Is your mail provider sendgrid?

You need to set all of the MAIL_ entries in .env

MAIL_DRIVER=smtp
MAIL_HOST=smtp.sendgrid.net
MAIL_PORT=587
MAIL_USERNAME=apikey
MAIL_PASSWORD=<yoursendgridapikey>
MAIL_ENCRYPTION=tls
MAIL_FROM_ADDRESS="[email protected]" #whatever is verified with sendgrid
MAIL_FROM_NAME="Some Name Here"
Activity icon

Replied to How To Send Confirmation Mail To New Email Address In Laravel?

Is your .env set or did you change config/mail.php?

MAIL_FROM_ADDRESS=
MAIL_FROM_NAME=
'from' => [
        'address' => env('MAIL_FROM_ADDRESS', '[email protected]'),
        'name' => env('MAIL_FROM_NAME', 'Example'),
    ],
Activity icon

Replied to Getting 500 Unable To Handle Requests

It's coming from the Event dispatcher. What event get's fired when visiting the page?

Your server seems to be on a Digital Ocean server in India. From what is listed below, the guzzle IP is on a cellular network. Is this your home broadband connection? Does this look familiar?

IP:	27.59.219.249
Decimal:	456907769
Hostname:	27.59.219.249
ASN:	45609
ISP:	Airtel
Organization:	Airtel
Services:	None detected
Type:	Wireless Broadband
Assignment:	Likely Static IP
Blacklist:	
Continent:	Asia
Country:	India in flag
State/Region:	Telangana
City:	Hyderabad
Activity icon

Awarded Best Reply on Updating Computed Within Vue

Ok, so does this.group.messages ever = 0? props are not reactive.

I don't know exactly what you're trying to do or what the data is, but what about setting something like this:


props: ['group'],

data() {
        return {
            message: '',
            typing: '',
	    messages: this.group.messages,
	    unReadCount: 0
        }
},

created() {
	this.unReadCount = this.filterUnreadCount()	

},

methods: {
	
	filterUnreadCount() {
		if(this.group.messages) {
                	return this.group.messages.filter((message) => {
                    	return message.read_at === null && Laravel.user.id != message.user_id;
                }).length;

                return 0;
	}

}

Use this.messages as the reactive component. Then set unReadCount to whatever you like after your api call.

Jun
01
2 days ago
Activity icon

Replied to "php Artisan Migrate" Gives Error

Like @tray2 said, make sure you have the extension installed.

apt list --installed | grep "php.*-mysql"

If not there, install it:

sudo apt install php-mysql	

If you're missing this, you may be missing more.

Check here: https://stackoverflow.com/questions/40815984/how-to-install-all-required-php-extensions-for-laravel

Activity icon

Replied to Updating Computed Within Vue

Ok, so does this.group.messages ever = 0? props are not reactive.

I don't know exactly what you're trying to do or what the data is, but what about setting something like this:


props: ['group'],

data() {
        return {
            message: '',
            typing: '',
	    messages: this.group.messages,
	    unReadCount: 0
        }
},

created() {
	this.unReadCount = this.filterUnreadCount()	

},

methods: {
	
	filterUnreadCount() {
		if(this.group.messages) {
                	return this.group.messages.filter((message) => {
                    	return message.read_at === null && Laravel.user.id != message.user_id;
                }).length;

                return 0;
	}

}

Use this.messages as the reactive component. Then set unReadCount to whatever you like after your api call.

Activity icon

Replied to Updating Computed Within Vue

When do you set the data group: [] from the prop group? I have found that reactivity doesn't work well or at all when you initialize it as nothing.

Why not set it directly in data? Are you manipulating it and setting it in Vue's created() method?

I think you have a disconnect of reactivity. The computed property will become 0 when the length of this.group.messages is 0. I am assuming that is what you want?

How are you setting this.group.messages when you get a response back from the server?

Activity icon

Replied to Updating Computed Within Vue

You are checking if messages exists, meaning that it initially doesn't exist. I'm am suggesting that it you check for length instead of "does it exist" because it always needs to exist for reactivity.

Can you show how you initialize the data?

Specifically, what do you have in:

data() {
        return {

            //how are you initializing here?
                
            }),
            
        };
    },
Activity icon

Replied to Updating Computed Within Vue

You can't directly set a computed property. You need to set the data that adjusts the computed.

So if this.group.messages is what sets it, then that is what needs to change.

Seems to me that you should be checking the length of messages instead of does it exist? It should always exist to remain reactive. How are you initializing it?

May
28
6 days ago
Activity icon

Replied to Update Query Throws "SQLSTATE[HY093]: Invalid Parameter Number" Error. Parameters Don't Get Passed On

Whenever you are using raw, you must make sure you validate the data properly and you should be good.

May
27
1 week ago
Activity icon

Replied to Update Query Throws "SQLSTATE[HY093]: Invalid Parameter Number" Error. Parameters Don't Get Passed On

I have noticed Laravel has several limitations when trying to use more complex queries, so you have to stay within those limits.

So why not just keep it simple:

Category::where('hierarchy', 'like', $old_hierarchy.'>%')
		->update([
		'hierarchy' => DB::raw("REPLACE(hierarchy, '$old_hierarchy', '$new_hierarchy')"
	]);

Or go full raw if thats your preference:

DB::raw("
	UPDATE categories 
	SET 
    		hierarchy = REPLACE(hierarchy,
        		'$old_hierarchy',
        		'$new_hierarchy'),
		updated_at = NOW()
	WHERE
    	hierarchy LIKE '$old_hierarchy>%';
");

Either one is more readable than ? and bindings.

May
25
1 week ago
Activity icon

Replied to Update Query Throws "SQLSTATE[HY093]: Invalid Parameter Number" Error. Parameters Don't Get Passed On

I'm not sure why you are using raw sql. Why cant you just do this?

Category::where('hierarchy', 'like', $old_hierarchy.'>%')  //is > supposed to be there?
		->update([
		'hierarchy' => $new_hierarchy
	]);

Also, when you do it this way, updated_at will update properly.

May
22
1 week ago
Activity icon

Replied to Using Mysql Load Data Query As A Raw Laravel Query

Only problem I can see is always leaving that option enabled instead of setting it when it's actually needed. It's disabled by default for a reason (security).

As far as $request->table, that's fine as long as you let Laravel validate it first.

You could also check:

Schema::hasTable($request->table);
Activity icon

Awarded Best Reply on Using Mysql Load Data Query As A Raw Laravel Query

I suggest writing a helper function to get around that...something like this:

protected function loadDataFile(string $query)
    {

	if (config(database.default) != 'mysql') return;

        $pdo = DB::connection()->getPdo();
        $pdo->setAttribute(\PDO::ATTR_EMULATE_PREPARES, true);
        $statement = $pdo->prepare($query,[\PDO::ATTR_CURSOR=>\PDO::CURSOR_SCROLL]);

        $exec = $statement->execute();
        if (!$exec) return $pdo->errorInfo();

        return $statement;

    }

Then call it ($this assumes method in same class):


$this->loadDataFile("LOAD DATA INFILE '$file' INTO TABLE `$request->table` FIELDS TERMINATED by ',' LINES TERMINATED BY '\n' IGNORE 1 ROWS");

Activity icon

Replied to Using Mysql Load Data Query As A Raw Laravel Query

I suggest writing a helper function to get around that...something like this:

protected function loadDataFile(string $query)
    {

	if (config(database.default) != 'mysql') return;

        $pdo = DB::connection()->getPdo();
        $pdo->setAttribute(\PDO::ATTR_EMULATE_PREPARES, true);
        $statement = $pdo->prepare($query,[\PDO::ATTR_CURSOR=>\PDO::CURSOR_SCROLL]);

        $exec = $statement->execute();
        if (!$exec) return $pdo->errorInfo();

        return $statement;

    }

Then call it ($this assumes method in same class):


$this->loadDataFile("LOAD DATA INFILE '$file' INTO TABLE `$request->table` FIELDS TERMINATED by ',' LINES TERMINATED BY '\n' IGNORE 1 ROWS");

Activity icon

Replied to Using Mysql Load Data Query As A Raw Laravel Query

Either don't use the single quotes around the table name, or use backtick `

$upload = DB::raw("LOAD DATA INFILE '$file' INTO TABLE `$request->table` FIELDS TERMINATED by ',' LINES TERMINATED BY '\n' IGNORE 1 ROWS");
Activity icon

Replied to Extend Str Helper

Thats because Str::of() is actually a new instance of Stringable

https://github.com/laravel/framework/blob/7.x/src/Illuminate/Support/Str.php#L50

Try putting the macro on Stringable instead.

Apr
10
1 month ago
Activity icon

Replied to Redirect To Another Route Returns Error "The GET Method Is Not Supported For This Route."

Because you have Route::post instead of Route::get for the named route paymentFail in your web.php.

You need to have a GET route on a redirect, not a POST.

Apr
08
1 month ago
Activity icon

Replied to How To Use Vue & Blade Without Flash Of Unstyled Content?

I don't understand what you're trying to do.

If JS is disabled, then <flash message="Hi"></flash> will remain. It will not be transformed into the template data.

Are you trying to get this working without JS? Or are you trying to get this working with Vue?

Activity icon

Replied to How To Use Vue & Blade Without Flash Of Unstyled Content?

The <flash></flash> will get replaced by what you have in your template area on the component.

Since you didn't share your Flash.vue code, it's impossible to say what is going on. You need to make sure that v-show is set to some var that is initially false and then is only set true if there's a message from the session or an event.

<template>
    <div class="alert alert-flash"
         :class="'alert-'+level"
         role="alert"
         v-show="show"
         v-html="body">
    </div>
</template>

You have your message set to a permanent "Hi".

Your styling should be in the <style></style>area of the component and can alter anything you wish.

Activity icon

Started a new Conversation Select And WithCount Issues

Just ran into this problem, not realizing at first what was going on.

I have a model that has $withCount on it.

protected $withCount = ['multiple_choice_is_na'];

I was querying for something specific from the model:

Review::select('id')->where('relationship_id', '!=', 8)->setEagerLoads([])->get()->pluck('id');

Since I have a specific select, the withCount code (see below) was not there, but laravel was still injecting the binding:

array (
    'query' => 'select `id` from `reviews` where `relationship_id` != ?',
    'bindings' => 
    array (
      0 => -1,
      1 => 8,
    ),
    'time' => 7.02,
  ),

My question is: Is this supposed to be normal behavior? I see others complaining about it, but I don't see a resolution. As you can see, this can cause a lot of problems. Are we just supposed to be aware of this?

I am running framework v6.17.1

withCount code that is not there because of the specific select:

(select count(*) from `multiple_choice_answers` where `reviews`.`id` = `multiple_choice_answers`.`review_id` and `value` = ?)
Apr
03
2 months ago
Activity icon

Replied to Can't Connect To BD After Upgrading MAMP Server From 4 To 5

@nhayder

Change your port in the .env to 8889. For whatever reason, your config is not on the default port.

DB_PORT=8889
Apr
02
2 months ago
Activity icon

Replied to Can't Connect To BD After Upgrading MAMP Server From 4 To 5

You might want to verify your setup.

See what's running and its location:

ps -ef | grep mysqld

See what port it's on:

sudo lsof -Pnl +M -i | grep mysqld

Activity icon

Replied to Execute A Value Twice From The Database

You're not using route model binding correctly. If you are viewing a single post, there is no need to get multiple. Laravels route model binding will get the one post you need, then you can pass it to the view.

Also, you can use authorization checks in the middleware. Using the Authenticate middleware, it will redirect them to login.

In your PostsController, it should look like this:


public function __construct()
{
     $this->middleware('auth');
}

public function viewUserQuestion(Post $post) { 
     
     return view('viewQuestion', compact('post'));
}

In your viewQuestion.blade.php view, you will have the $post variable available. No need for a @foreach when its a single item.

{{ $post->title }}
From userID: {{ $post->user_id }}
Created at: {{ $post->created_at }}
{{ $post->content }}
Mar
09
2 months ago
Mar
05
2 months ago
Activity icon

Replied to Phpunit Error Help!

Remove the route method.

$response->assertRedirect('/login');
Mar
04
2 months ago
Activity icon

Awarded Best Reply on Validation Passed On Required_if

You could also just do this:

$this->validate(request(), [
	'type' => 'required|string',  //is this always a string?
 ]);

if (request('type') == '1:5') {
	$this->validate(request(), [
		'time_frame_type'   => 'required|array|min:1',  //how deep in the array?
		'time_frame_type.*'   => 'required|integer' //or whatever type it needs to be
		'description_type'  =>  'required|array|min:1',
		'description_type.*'  =>  'required|integer' //or whatever type it needs to be
	]);
}
Activity icon

Replied to Validation Passed On Required_if

You could also just do this:

$this->validate(request(), [
	'type' => 'required|string',  //is this always a string?
 ]);

if (request('type') == '1:5') {
	$this->validate(request(), [
		'time_frame_type'   => 'required|array|min:1',  //how deep in the array?
		'time_frame_type.*'   => 'required|integer' //or whatever type it needs to be
		'description_type'  =>  'required|array|min:1',
		'description_type.*'  =>  'required|integer' //or whatever type it needs to be
	]);
}
Activity icon

Replied to Validation Passed On Required_if

Yeah the ternary should extend to the array validation as well.

Can you show both scenarios of the sent data? When something is sent equal to "1:5" and what is sent when not equal?

Activity icon

Replied to Validation Passed On Required_if

Try it like this:

'type' => 'required',
'time_frame_type'   => (string) $request['type'] == '1:5' ? 'required|array' : 'nullable',
'time_frame_type.*'   => 'required|integer' //or whatever type it needs to be
'description_type'  =>  (string) $request['type'] == '1:5' ? 'required|array' : 'nullable',
'description_type.*'  =>  'required|integer' //or whatever type it needs to be

https://laravel.com/docs/6.x/validation#validating-arrays