mattsplat

mattsplat

Member Since 3 Years Ago

Experience Points 27,380
Experience Level 6

2,620 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 201
Lessons
Completed
Best Reply Awards 12
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.

09 May
1 month ago

mattsplat left a reply on Problem When Running Seeders Laravel 5.5

try php artisan config:cache

23 Apr
2 months ago

mattsplat left a reply on 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();

mattsplat left a reply on HasMany() Does Not Connect To An Alternate User 'id' (5.8.13)

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

08 Mar
3 months ago

mattsplat left a reply on 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.

19 Feb
4 months ago

mattsplat left a reply on 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')
        );
    }
26 Dec
6 months ago

mattsplat left a reply on 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.

25 Dec
6 months ago

mattsplat left a reply on 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 ];
    });

mattsplat left a reply on 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
17 Dec
6 months ago

mattsplat left a reply on 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

15 Dec
6 months ago

mattsplat left a reply on Submitting Post Request From Vue Throwing MethodNotAllowedException

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

14 Dec
6 months ago

mattsplat left a reply on 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();

mattsplat left a reply on 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.

mattsplat left a reply on Request Unique

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

mattsplat left a reply on 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

11 Nov
7 months ago

mattsplat left a reply on Larvel: Single Data Is Not Showing With Ajax In Modal

Is the data getting returned in the ajax response correctly?

09 Oct
8 months ago

mattsplat left a reply on Storage/app Not Readable CentOS

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

mattsplat left a reply on Unique Rules

No I did

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

but your method totally worked.

Thanks

mattsplat 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` = mwakisambwe34@gmail.com 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.

06 Oct
8 months ago

mattsplat left a reply on When I Press The Buy Button I Get This Error

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

mattsplat left a reply on 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.

mattsplat left a reply on When I Press The Buy Button I Get This Error

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

mattsplat left a reply on 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.

mattsplat left a reply on 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')

05 Oct
8 months ago

mattsplat left a reply on DB Query Question

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

mattsplat left a reply on 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.

mattsplat left a reply on Why It's Showing Null In My Model Relationship

Try using whereRaw instead of where.

mattsplat left a reply on 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.

27 Sep
9 months ago

mattsplat left a reply on MVC Routing Question

This might help

28 Jun
11 months ago

mattsplat left a reply on Problem In Export Option Using Maatwebsite/laravel

Are you using Maatwebsite\Excel\Facades\Excel ?

27 Jun
1 year ago

mattsplat 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/

mattsplat left a reply on Unable To Access Phpmyadmin

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

26 Jun
1 year ago

mattsplat left a reply on Relations And Soft Delete

Can a User have multiple Devices or Contracts?

mattsplat left a reply on Problem With Saving Password During Edition User As Admin

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

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

mattsplat left a reply on I Can Not Run Php Artisan Migrate

Are you using MySQL or PostgreSQL?

mattsplat left a reply on I Can Not Run Php Artisan Migrate

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

mattsplat left a reply on I Can Not Run Php Artisan Migrate

Look at the migration that references "categoria".

14 May
1 year ago

mattsplat left a reply on 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

11 May
1 year ago

mattsplat 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.

21 Nov
1 year ago

mattsplat left a reply on 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'])
19 Nov
1 year ago

mattsplat left a reply on 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){
    $campaigns['partner_id] = $id;
    $campaigns['statistics']['waiting_validation'] = $results->where('partner_id', $id)->where('status', 'waiting_validation')->count;
    $campaigns['statistics']['published'] = $results->where('partner_id', $id)->where('status', 'published')->count;
    $campaigns['statistics']['do_not_published'] = $results->where('partner_id', $id)->where('status', 'do_not_published')->count;
    $campaigns['statistics']['finished'] = $results->where('partner_id', $id)->where('status', 'finished')->count;
}

$campaigns = json_encode($campaigns);

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

mattsplat left a reply on 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?

mattsplat left a reply on 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(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()

mattsplat left a reply on Query On My Model Taking Too Much Time To Finish.

Usually when my queries take that long it's because I'm not using indexes on the fields I am searching by. If you don't have an index on 'AcctStartTime' you should try creating one. To check what fields have indexes from tinker you can use

 DB::select('show index from table-name')

mattsplat left a reply on Create This Funtion In Larvarel

This looks like something that could be used as a helper function. You can register a file with your function in your composer.json. Then run composer update.

"autoload": {
        "classmap": [
            "database"
        ],
        "psr-4": {
            "App\": "app/"
        },
        "files" : ["path-to-your-file-here"]
    },

mattsplat left a reply on Execute Laravel Cron Jobs In Ubuntu

I'm not sure how it relates to cron jobs but app log level in part of the .env file. You might check there.

08 Nov
1 year ago

mattsplat left a reply on Authenticate Middleware Not Working

Have you assigned the middleware to your route?

By route

Route::get('admin/profile', ['middleware' => 'auth', function () {
    //
}]);

or by the controller

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

mattsplat started a new conversation Temporary Tables

I was trying to improve the performance of some queries by utilizing a temporary table. I can create the using.

DB::unprepared(DB::raw('create temporary table new_labs as (select * from patient_dbspoctest_records where year(date_of_test) > 2014);'));

but I'm unable to determine if the table exists.

I tried using

 DB::getSchemaBuilder()->hasTable('new_labs')

but it seems to not work on temporary tables;

Is there a way to determine if the table exists? Or are there other suggestions for doing this?

05 Nov
1 year ago

mattsplat left a reply on Missing: "name"

You are missing the name of your migration.

php artisan make:migration create_some_table