MThomas

MThomas

Member Since 4 Years Ago

Eindhoven, The Netherlands

Experience Points 115,680
Experience Level 24

4,320 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 856
Lessons
Completed
Best Reply Awards 61
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.

15 Aug
5 days ago

MThomas left a reply on Urgent Whoops

@pdc I wish you a long and happy life as a developer and kindly request you to stop bashing a framework without any substantial evidence :)

Good Day

14 Aug
6 days ago

MThomas left a reply on Casts

Casts can be used to convert (cast) a JSON string to a native array, or a mysql boolean (tiny int) to a php boolean (true/false).

In order to prevent users from entering invalid data, you need to validate the users input.

https://laravel.com/docs/5.8/validation

On a side note, you never should store or handle phone numbers as integers, this will get you in trouble:

https://stackoverflow.com/questions/24353778/which-is-best-data-type-for-phone-number-in-mysql-and-what-should-java-type-mapp

And remember that php does not play nice with long integers

13 Aug
1 week ago

MThomas left a reply on Urgent Whoops

@pdc why open a 2 year old post for these kinds of discussions...

If you so strongly believe that Laravel is an insecure framework, show some evidence, make security reports or issues on GitHub... in stead of complaining... nobody here forces you to use it.

On the topic of Whoops. By default Laravel will disable Whoops for production... you have to enable it manually in order to show on production.

07 Aug
1 week ago

MThomas left a reply on Vue.js (Laravel + Vue) Not Working On IPhone.

Please elaborate on the issue...

What response do you get? Is it a Laravel issue? Have you tried turning on Debug Mode?

30 Jul
3 weeks ago

MThomas left a reply on AssertSee Videos?

Great you got it to work!

As a rule of thumb, if you run into an issue, share the code your are working on, in this case the test method, the controller action etc :)

Good luck!

MThomas left a reply on 401 Unauthenticated In Ajax Login...

If you want us to help you, show us the code you have written, what routes you have defined etc.

A 404 means that it can't find the requested url, so that might be a start in your debugging.

MThomas left a reply on AssertSee Videos?

As far as I know you can assert the response contains a certain HTML string using assertSee().

https://laravel.com/docs/5.8/http-tests#assert-see

And please realize and accept(!) that you need to provide the forum with information, we don't know what you want etc, only in your last post you mentioned the use of YouTube and iframes, prior to that, it could have been an Laravel model etc...

MThomas left a reply on Authentication In An SPA

What about https://laravel.com/docs/5.8/socialite

And if the default drivers don't cover your use case you can find many others here: https://socialiteproviders.netlify.com

And if you want to add your own OAuth server, take a look at https://laravel.com/docs/5.8/passport

24 Jul
3 weeks ago

MThomas left a reply on Dynamically Create Subdomain

I guess, the best way to find out is to give it a try.

But as you need to record the subdomain somewhere there is no reason you could not redirect there (its nothing more than a regular redirect).

MThomas left a reply on How Can I Use Pagination In Laravel Vuejs?

Just the two first google results for: laravel vue pagination:

In other words, what did you try, where did you get stuck?

MThomas left a reply on Dynamically Create Subdomain

Sounds like a Multi tenant approach might help you. This will also enable you to isolate all tenant/company data in seperate databases or tables.

Take a look at https://laravel-tenancy.com/ or https://github.com/orchestral/tenanti for composer packages doing the heavy lifting.

If you like to do it yourself take a look at these two great blog posts:

21 Jul
4 weeks ago

MThomas left a reply on Route [admin.categories.index] Not Defined.

You namespace and file path are connected :).

If it solved your issue, please mark it as the answer, that helps others.

MThomas left a reply on Connection Could Not Be Established With Host Smtp.mailtrap.io [Connection Refused #111]

Two things, please tell us what you did, how does the code look that invoked the email.

Secondly you exposed you Mailtrap SMTP/API username and password, might best to remove them from the post and renew them on Mailtrap's side.

MThomas left a reply on Route [admin.categories.index] Not Defined.

What is the path of your controller?

It should be in app/Http/Controller/Auth/Admin.

MThomas left a reply on Route [admin.categories.index] Not Defined.

Within the route group you prefix all controllers with Auth/Admin and your CaregoriesController is just in App/Http/Controllers and not in App/Http/Controllers/Auth/Admin.

So if you want it to work move the file for the Admin directory and update the namespace accordingly.

MThomas left a reply on Variable Not Passing To View

What url are you visiting? How dis you install Laravel? Are you using Homestead or Valet?

21 Jun
1 month ago

MThomas left a reply on Conditional Filtering On Related Model

@andersb Not sure what you're asking. You said, that if there is a post, you would like to get all comments not just the comments of the post you're viewing, that is what that query does.. it only uses the timestamp of the post the user is viewing.

If the user is not viewing a post, but you just want comments that are a month old, Isn't that not just this:

$comments = Comment::whereDate('created_at', '>', now()->subMonth())->get();

MThomas left a reply on Get Data From 3 Tables With Relationship Laravel

@ABDULBAZITH - As mentioned in my earlier comment. Assuming you have created the relationship on your order model. The comments shows you don't have the following relationship:

// In your order model
public function products()
{
    return $this->hasMany(Product::class);
}

// In your product model
// Or type is even better but then you need to update the eloquent query accordingly
public function product_type() 
{
    return $this->belongsTo(ProductType::class);
}

20 Jun
2 months ago

MThomas left a reply on Conditional Filtering On Related Model

Not sure if I get it right, but isn't it as simple as:

$post = Post::find(123);

$comments = Comment::whereDate('created_at', '>', $post->created_at->addMonth());

MThomas left a reply on Hoping For Pointers On CRUD Logging...

OK, I get your point. Can you explain why you want to do that? In the case you mention, you could easily resolve the Country's name based on its ID.

I'm not entirely sure why you want to log for example that piece of data. Just thinking out of the box and filling in some information. But in case you try to log: "MThomas (Netherlands) updated his profile", you could do something like this:

activity()
   ->performedOn($user)
   ->causedBy(auth()->user())
   ->withProperties(['country_id' => $user->country_id])
   ->log("{$user->name} ({$user->country->name}) updated his profile.");

If this is not the case, let me try a different idea (have not tested or tried this). Assuming there is not an endless list of fields from related models you'd like to log. Why not create an accessor attribute for the item you like to log, and add it to the luggable attributes:

use Illuminate\Database\Eloquent\Model;
use Spatie\Activitylog\Traits\LogsActivity;

class User extends Model
{
    use LogsActivity;

    protected $guarded = [*];
    
    protected static $logAttributes = ['name', 'country'];

    protected static $logOnlyDirty = true; // Only log created and changed fields

    public function country()
    {
        return $this->belongsTo(Country::class);
    }

    public function getCountryAttribute()
    {
        $this->country->name;
    }
}

MThomas left a reply on Get Data From 3 Tables With Relationship Laravel

Why not use the GroupBy functionality of Eloquent, assuming your Order model has a product relationship and your Product model a product_type relationship.

Order::with(['product.product_type' => function($query){
        $query->groupBy('id');
    }])->get();
19 Jun
2 months ago

MThomas left a reply on Hoping For Pointers On CRUD Logging...

The package will log all or a selection of fields for models (that have a certain trait and implementation) every time you create or update the model. So if you add the trait to all models you want to track, you should be fine.

Yes, you might log more that you need, but you could create a artisan job that deletes unnecessary logged items or something like it (if it is really a problem). Otherwise using a standard package that fits 80% of your need vs the downside of building and maintaining your own implementation might not weigh up.

17 Jun
2 months ago

MThomas left a reply on Azure AD Authentication In My Laravel Web App

@lxg Most of the time there will be package for such a feature.

Good luck!

MThomas left a reply on Azure AD Authentication In My Laravel Web App

Any reason you're not using on of the Azure AD packages? For example?

https://github.com/metrogistics/laravel-azure-ad-oauth -- Extension of Socialite https://github.com/rootinc/laravel-azure-middleware -- Based on middleware

12 Jun
2 months ago

MThomas left a reply on Is There A Way To List All Relationships Of A Model?

@sonoma Why are you responding to posts that have been inactive for years...

07 Jun
2 months ago

MThomas left a reply on Check If Model Has Changed Since First Save

Not build in (as far as I know). But I can highly recommend this package by Spatie:

https://github.com/spatie/laravel-activitylog

it enables you to track changes for specified attributes.

MThomas left a reply on Open A Register Form Only In Sunday

@BELHEDI - Please mark it as the accepted Answer, this helps others identifying questions that have been answered :)

MThomas left a reply on Open A Register Form Only In Sunday

Even more elegant is:

if(now()->->isSunday()) {
    return view('foo.bar');
}

You leverage Carbon and the Laravel helper which makes it even more expressive.

05 Jun
2 months ago

MThomas left a reply on Select Inputs Ignored By Validation

Are you sure your request data includes the field?

Try a return $request->all() before validating to check it is in your request data.

If you want to include user input in your validated data array, you can add it without any rules:

'email' => 'required|email',
'data_not_validated' => '',

If you want to manually add something to a create method you could do this:

$data = $request->validate([
    //
    'email' => ['required', 'email'],
    //
]);

$data['foo'] = 'bar';

$model = Post::create($data);
28 May
2 months ago

MThomas left a reply on How To Install This IBAN Validator In LARAVEL

Why not use this package: https://github.com/Intervention/validation

This is tailormade for Laravel.

MThomas left a reply on Role-based Multi-tenant With Tenant Subscription To Selected Features

Yes, the can directive can limit access to resources, and you can also scope queries down to the teams (could even add a global scope for this).

With regard to the subscriptions. You could add that functionality to the team model instead of the user model.

25 May
2 months ago

MThomas left a reply on Role-based Multi-tenant With Tenant Subscription To Selected Features

You should take a look at https://github.com/spatie/laravel-permission this works great with Laravels permission system.

And as you said, combine it with Laravel cashier and you will have the most flexible integration you can wish for.

Just asign users roles and teams, and link permissions to roles and teams. You could use the Laravel's gate/authorization features to check the acces to a certain resource based on there presence in a team.

MThomas left a reply on Thoughts On Subscribing To Laracasts?

If you are still in doubt, why not register for a monthly subscription and find out yourself. I found I extremely useful, and if you take a look around at the forum and the users badges, you will see there are very experienced developers and juniors here. For everyone there will be something useful.

MThomas left a reply on How Can I Hide Or Remove Id From Url In Laravel?

Take a look at this package, will leverage a lot of work for you:

https://github.com/cviebrock/eloquent-sluggable

23 May
2 months ago

MThomas left a reply on How To Configure Laravel Passport's '/oauth/token' Rate Limit?

Isn't this what you are looking for: https://laravel-news.com/laravel-5-6-dynamic-rate-limiting

Route::middleware('auth:api', 'throttle:60,1')->group(function () {
    Route::get('/user', function () {
        //
    });
});
18 May
3 months ago
17 May
3 months ago

MThomas left a reply on VUE.js | Reload Page On External Server After Update.

You need to inform the client (that is where the JavaScript is rendered) that it needs to refresh. You can do this using Broadcasting in Laravel. You’ll need a service like Pusher or Laravel-Websockets to make it work.

Those are needed to establish a connection from the client to your server in order to push an update without a trigger from the user.

An totally different option is to reload the page (or perform an Ajax request) every x seconde or minutes to your server.

MThomas left a reply on Task Scheduling Runs Every Minute Despite My Directions

The idea is that the cron job is called every minute. And that you set the timeframe/interval on your jobs. If there is no job set in your code base for the moment the cronjob runs, no jobs will be executed. If there is a job set in the codebase for that moment, it will run.

Or have I completely missunderstood your problem?

MThomas left a reply on Differents Between Eloquent ORM And Query Builder?

They are linked. Eloquent lets you use models to query your database. The query builder is what is used under the hood in Eloquent. And you can use) to query your database directely and build upon eloquent queries.

https://laravel.com/docs/5.8/eloquent https://laravel.com/docs/5.8/queries

MThomas left a reply on Laravel 5.8 Does Not Use Sqlite For Testing

Did you install Laravel Telescope? If so, you need to be sure you have the line below in your phpunit.xml:

<env name="TELESCOPE_ENABLED" value="false" />

Somehow having telescope enabled while running tests causes an .env problem.

MThomas left a reply on Data Is Not Deleting In Laravel

Did you use the Vue component structure and compiled it down?

<template>
    <a href="#" @click="deleteUser(user.id)">
    <i class="fa fa-trash red"></i>
        </a>
</template>

<script>
   export default {
        data() {
            return {
                
            }
        },

        methods: {
            deleteUser(id){
            Swal.fire({
                    title: 'Are you sure?',
                    text: "You won't be able to revert this!",
                    type: 'warning',
                    showCancelButton: true,
                    confirmButtonColor: '#3085d6',
                    cancelButtonColor: '#d33',
                    confirmButtonText: 'Yes, delete it!'
                }).then((result) => {

                //send request to the server

                    this.form.delete('api/user/'+id).then(()=>{
                        Swal.fire(
                        'Deleted!',
                        'Your file has been deleted.',
                        'success'
                            )
                    }).catch(()=>{
                        swal("Failed!", "There was something worng.", "warning");
                    });
                    
                    })
            },
        }
        
        mounted() {
            console.log('Component mounted.')
        }
    }
</script>

MThomas left a reply on Logout In Laravel Not Working

What did you change? Did you do something with the authentication routes, did you change the logic in the auth scaffold? It must be there since your code seems very similar to the default code in app.blade.php

<div class="dropdown-menu dropdown-menu-right" aria-labelledby="navbarDropdown">
    <a class="dropdown-item" href="{{ route('logout') }}"
        onclick="event.preventDefault();
                        document.getElementById('logout-form').submit();">
        {{ __('Logout') }}
    </a>

    <form id="logout-form" action="{{ route('logout') }}" method="POST" style="display: none;">
        @csrf
    </form>
</div>

Or try reverting back to the code above, the one that is provided in the default layout/app.blade.php file :)

MThomas left a reply on Bulk Delete Of Records Where SoftDeletes Is True

@MIKE_SA - Glad I could be of help

would be great if you marked my reply as the answer :)

Makes it also clear to others that there is an answer :)

MThomas left a reply on Bulk Delete Of Records Where SoftDeletes Is True

You don't have to pas the delete in forceDelete, you are already in the context of the delete...

You could change the inside of your loop to chain the forceDelete method:

Post::where('id', $post)->forceDelete();

And assuming that $post is an single ID and $postsToDelete an array of ID's instead of the loop you could do:

Post::whereIn('id',$postsToDelete)->forceDelete();

MThomas left a reply on Getting Relation's Related Fields In Laravel Eloquent Model

use qty_prices() instead. You need the query builder for the with() method :)

$this->qty_prices will give you a collection of all the related prices. $this->qty_prices() will return a query builder object that you can build upon with Eloquent methods like with()

MThomas left a reply on Laravel API Image Upload

Thats where the videos on laracast can help you alot, there are several video's on file uploads, among them this one: https://laracasts.com/series/whats-new-in-laravel-5-3/episodes/12

Also take a look at this series: https://laracasts.com/series/laravel-from-scratch-2018 that will help you a lot I think.

MThomas left a reply on Issue With Eloquent: API Resources - Conditional Relationships

@ME@BAYES-SHELTON.CO.UK - The docs for Route Model Binding are here: https://laravel.com/docs/5.8/routing#route-model-binding

What you could do to backtrack your problem is dd() your user. Does it always load the company? If so, you might have specified an default eager loading property: https://laravel.com/docs/5.8/eloquent-relationships#eager-loading