mattsplat

mattsplat

Member Since 3 Years Ago

Experience Points
28,750
Total
Experience

1,250 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
209
Lessons
Completed
Best Reply Awards
13
Best Reply
Awards
  • start-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-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-token Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer-token Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • lara-evanghelist 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 6
28,750 XP
Sep
20
3 weeks ago
Activity icon

Replied to Best Laravel Package For Advanced Searching

Something simple that could handle what you are talking about is https://github.com/spatie/laravel-query-builder

If your not doing full text search you might not need something like Algolia.

Sep
19
3 weeks ago
Activity icon

Replied to Installing And Running Nova On Production

It looks you made changes on your server that are not in your repo. Just reset the changes and then pull from the repo again.

git reset --hard
git pull 
Activity icon

Replied to Update Last Login When Requesting Oauth/token

Create an event listener for AccessTokenCreated.

In your EventServiceProvider

protected $listen = [
       
        'Laravel\Passport\Events\AccessTokenCreated' => [
            'App\Listeners\APILogin',
        ],
    ];

Then in the event

 public function handle(AccessTokenCreated $event)
    {

        if(!empty($event->userId)){

                $user = User::find($event->userId);
        $user->saveLogin();
        }

    }

Yours may differ but this might get you there.

Activity icon

Replied to How To Find Nearest Users From Latitude And Longitude

Can you confirm you have valid values in $latitude and $longitude? What database are you using?

In MySQL you can you use.

ST_Distance_Sphere( point(longitude, latitude), point($longitude, $latitude) ) * 0.000621371192

Or Postgresql I have

2 * 3959 * asin(sqrt((sin(radians(($latitude - latitude) / 2))) ^ 2 
                            + cos(radians(latitude)) * cos(radians($latitude)) * (sin(radians(($longitude - longitude) / 2))) ^ 2))
Activity icon

Replied to How To Access Child Component Method

Where are you calling showAddTask? Is the ref coming up undefined when you call it?

Activity icon

Replied to Using Distinct Validation Rule In Nested Arrays

I can't think of a built in way to check this. You can however just provide a callback function. Something like this might work.

'array_field' => [
    'required', 
    function ($attribute, $value, $fail) {
        foreach($this->request('array_key') as $name) {
            if(count(array_unique($name))<count($name)) {
                $fail('Found duplicates')
            }
        }
    }
]
May
09
5 months ago
Activity icon

Replied to Problem When Running Seeders Laravel 5.5

try php artisan config:cache

Apr
23
5 months ago
Activity icon

Replied to Accessing A Relation In A Collection

It looks like you have multiple sub_jobs in a collection and you're trying to call company method on the collection. This won't work on a collection.

You would need to call the method on each instance of sub_jobs.

$job->sub_jobs->map(function ($sub_job) {
    return $sub_job->company->name
})
->unique()

Or better yet load the companies with sub_jobs first so you don't run a query every time.

$job->load(['sub_jobs' => function ($query) {
    $query->with('company');
}])
->sub_jobs
->pluck('company.name')
->unique();
Activity icon

Replied to HasMany() Does Not Connect To An Alternate User 'id' (5.8.13)

That looks correct. What is the code for the unit test?

Mar
08
7 months ago
Activity icon

Replied to Data From A Table Where Column 1 Equals To Column 2 Of The Same Row

Posts::whereRaw('posts.name = posts.author')->get()

I think this will work for you.

Feb
19
7 months ago
Activity icon

Replied to Adding A Subquery To An Eloquent Query

I think addSubSelect() might be what you are looking for. https://reinink.ca/articles/dynamic-relationships-in-laravel-using-subqueries

This is an example of how I have used this.

 public function scopeWithLeaderEmail(Builder $query)
    {
        return $query->addSubSelect('leader_email', User::select('users.email')
            ->join('group_user', 'group_user.user_id', '=', 'users.id')
            ->whereColumn('group_id', 'groups.id')
            ->orderBy('group_user.group_leader', 'desc')
        );
    }
Dec
26
9 months ago
Activity icon

Replied to Artisan Command For Fresh Migration On Custom Tables

I don't believe there is any easy way to selectively roll back migrations. They are designed to run sequentially. php artisan migrate:refresh however will only roll back the migrations of that are in your project. So if there are other tables in your database that were added not using a migration from that project it will not be dropped.

I'm not sure why you are not wanting to use a vps or a file based db as this would solve your problem.

Dec
25
9 months ago
Activity icon

Replied to Issue Pushing Array Into Arrays

Oh course because $productCategory is not an array lol.

You can try converting $productCategory to an array first. Or if you have a products relationship set for ProductCategory you could do something like.

$productCategory = ProductCategory::with('products')->all()->mapWithKeys(function ($category) {
        return [ $category->name => $category->products ];
    });
Activity icon

Replied to Issue Pushing Array Into Arrays

If I understand you correctly you want $productCategory to be array of array with the key being each category and the values to be an array of product matching that category.

You are overwriting the value of $productCategory[$category] each iteration. I think what you want is to append the product array each time.

$productCategory[$category] []= $product
Dec
17
9 months ago
Activity icon

Replied to How To Host Laravel Application On Digital Ocean.

Forge is great and totally worth the cost especially if you have multiple apps but sometimes you have to struggle with something to appreciate it enough to pay for it. I can't provide you a step by step for Laravel but here are some resources to get started.

Start with a LAMP application https://www.digitalocean.com/docs/one-clicks/lamp/ Or LEMP if you prefer https://www.digitalocean.com/docs/one-clicks/lemp/

Install Laravel dependencies https://laravel.com/docs/5.7#installation

Here is a slightly outdated guide. https://www.digitalocean.com/community/tutorials/automatically-deploy-laravel-applications-deployer-ubuntu

Dec
15
10 months ago
Activity icon

Replied to Submitting Post Request From Vue Throwing MethodNotAllowedException

You might try changing the order of your routes and put login first.

Dec
14
10 months ago
Activity icon

Replied to Sql Raw In Model::method()

You should just need to wrap the raw selects in DB::raw()

$return = Leader::leadertiles()
            ->select(
                'seq_no', 'tile_type', 'tile_name', 'links_to', 'isactive', 'relation_id','sort_order',
                DB::raw("MAX(GREATEST(l1_created,l2_created,l3_created,l4_created)) as created_at"),
                DB::raw("MAX(GREATEST(l1_updated,l2_updated,l3_updated,l4_updated)) as updated_at")
            )
            ->groupBy('seq_no', 'tile_type', 'tile_name', 'links_to', 'isactive', 'relation_id','sort_order')
            ->get();
Activity icon

Replied to Request Unique

If I understand you correctly you wan to check if there is an entry in product_nutritional_facts with the same product_id and nutrient_id and send an error if there is. Replace 'nutrient_id' => 'required', with the code above.

https://laravel.com/docs/5.7/validation#rule-unique

Although you I think you would actually access product_id with $this->request->product_id assuming your passing it in the request.

Activity icon

Replied to Request Unique

Maybe using this in your rules array.

'nutrient_id' => ['required', Rule::unique('product_nutritional_facts')->where(function ($query) {
    return $query->where('product_id', $request->product_id);
})]
Nov
12
11 months ago
Activity icon

Replied to Query Works Fine Via Php Artisan Tinker But Not In Browser?

Try running php artisan config:cache it looks like its not reading your .env

Nov
11
11 months ago
Activity icon

Replied to Larvel: Single Data Is Not Showing With Ajax In Modal

Is the data getting returned in the ajax response correctly?

Oct
09
1 year ago
Activity icon

Replied to Storage/app Not Readable CentOS

Did you create the symlink with php artisan storage:link?

Activity icon

Replied to Unique Rules

No I did

->updateRules('unique:users,email, user_id'),

but your method totally worked.

Thanks

Activity icon

Started a new conversation Unique Rules

I have a User model that uses user_id as the primary key. I have defined this in my model and everything works fine on that side. However in nova with update rules applied to email

->updateRules('unique:users,email,{{resourceId}}'),

I get an error

Column not found: 1054 Unknown column 'id' in 'where clause' (SQL: select count(*) as aggregate from `users` where `email` = [email protected] and `id` <> user_id)

I have tried specifying the field as user_id in the update rules method but it seems it still uses id.

Oct
06
1 year ago
Activity icon

Replied to When I Press The Buy Button I Get This Error

You actually only want the request part use dd($request->all()) instead

Activity icon

Replied to Why It's Showing Null In My Model Relationship

I guess I used this with a belongs to many but maybe you could try. whereRaw("item_backups.location_id = {$this->location_id}") Not sure but I think it's worth a try.

Activity icon

Replied to When I Press The Buy Button I Get This Error

Oh I see. Try dd($request) in your controller and see what you get.

Activity icon

Replied to When I Press The Buy Button I Get This Error

It looks like the column is called quantity but you are setting the value to $order->qty.

Activity icon

Replied to Why It's Showing Null In My Model Relationship

You don't need $this you should be able to use something like whereRaw('items.location_id = item_backups.location_id')

Oct
05
1 year ago
Activity icon

Replied to DB Query Question

I have done something similar to this with 15 columns and 10000 rows. I have not noticed any performance problems.

Activity icon

Replied to Group By Categories

You could do something like

$truck->customers->map(function($customer){
    return $customer->name . implode(' ', $customer->products->pluck('name')->toArray());
});

Depending on how many items you have this might work.

Activity icon

Replied to Why It's Showing Null In My Model Relationship

Try using whereRaw instead of where.

Activity icon

Replied to Having Big Issues With Recursive Relationship On Many To Many

You said you can do this this in a raw query so you might try this in tinker to see what your actual sql query looks like.

 $courses->courses()->toSql()

or better yet before your query run DB::enableQueryLog() before your query and then DB::getQueryLog()after. This will show you the bindings as well.

Sep
27
1 year ago
Activity icon

Replied to MVC Routing Question

This might help

Jun
28
1 year ago
Activity icon

Replied to Problem In Export Option Using Maatwebsite/laravel

Are you using Maatwebsite\Excel\Facades\Excel ?

Jun
27
1 year ago
Activity icon

Started a new conversation Disable Functions For Eval()

I want to build a page for code puzzles or challenges so I need to run eval() in the script. How can I make sure the user doesn't use malicious functions (such as touch, system or exec). I have noticed some sites do this such as https://returntrue.win/ http://phptester.net/

Activity icon

Replied to Unable To Access Phpmyadmin

Did you create a symlink ? sudo ln -s /usr/share/phpmyadmin /usr/share/nginx/html

Jun
26
1 year ago
Activity icon

Replied to Relations And Soft Delete

Can a User have multiple Devices or Contracts?

Activity icon

Replied to Problem With Saving Password During Edition User As Admin

Are you assigning the hashed value or $request->password? Try this.

$request->password= Hash::make($request->password);
        $user->update($request->all());
Activity icon

Replied to I Can Not Run Php Artisan Migrate

Are you using MySQL or PostgreSQL?

Activity icon

Replied to I Can Not Run Php Artisan Migrate

Does this error come up calling php artisan as @akLearn suggested?

Activity icon

Replied to I Can Not Run Php Artisan Migrate

Look at the migration that references "categoria".

May
14
1 year ago
Activity icon

Replied to Laravel App In Subdirectory Of Project

Thanks. Also should be noted is I had to adjust the deployment script to use src. cd /home/forge/default/src

May
11
1 year ago
Activity icon

Started a new conversation Laravel App In Subdirectory Of Project

Is there a way to deploy on forge with the laravel app in a subdirectory? My existing projects have laravel contained in a subdirectory call src. I'd like to start using Forge without changing my folder structure and losing my git history.

Nov
21
1 year ago
Activity icon

Replied to Query On My Model Taking Too Much Time To Finish.

Is AcctStartTime a datetime? Like @shez1983 said you shouldn't use like with a date. The reason I believe is it requires additional conversion on every row and doesn't allow the index to work. Try using.

->whereDate('AcctStartTime' ,  $data['date'] )

or maybe

->whereBetween('AcctStartTime' ,[ $data['date'] . '00:00:00',  $data['date']. ' 23:59:59'])
Nov
19
1 year ago
Activity icon

Replied to Friends, I'm In Need Of Help To Solve A Problem With Grouped Queries

I'll give it shot since no one else has.

$results = DB::table('campaigns')
        ->select('partner_id', 'status', DB::raw('count(status) as count'))
        ->groupBy('partner_id', 'status')
        ->get();
$ids = $results->unique('partner_id')->pluck('partner_id');
$campaigns = [];
foreach($ids as $id){
    $partner_id] = $id;
    $statistics['waiting_validation'] = $results->where('partner_id', $id)->where('status', 
             'waiting_validation')->count;
    $statistics['published'] = $results->where('partner_id', $id)->where('status', 
             'published')->count;
    $statistics['do_not_published'] = $results->where('partner_id', $id)->where('status', 
             'do_not_published')->count;
    $statistics['finished'] = $results->where('partner_id', $id)->where('status', 'finished')->count;
        $campaigns[] = [$partner_id, $statistics];
}

$campaigns = json_encode($campaigns);

There might be a better way but I think that might work for you.

Activity icon

Replied to Need Code Suggestion To Identify Similar News Articles

Can you explain in more detail what data you have and how you are able to verify if one article is the same as another?

Activity icon

Replied to How To Make This Query In Eloquent

This might get you closer

DB::table('vehicles_v as v')
    ->select(DB:raw('COUNT(v.ID)'), v.SITE_NAME, DB::raw('YEAR(v.REGISTRY_DATE)') )
    ->where(DB::raw('YEAR(v.REGISTRY_DATE)'), '>', 2012)
    ->whereNull('v.LAST_CANCEL_ID)
    ->groupBY(v.SITE_NAME, DB(DB::raw('YEAR(v.REGISTRY_DATE)'))
    ->orderBy(2)
    ->get()