MThomas

MThomas

Member Since 4 Years Ago

Eindhoven, The Netherlands

Experience Points 110,010
Experience Level 23

4,990 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 807
Lessons
Completed
Best Reply Awards 60
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.

21 Jun
4 weeks 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
public function product_types() // Or types is even better but then you need to update the eloquent query accordingly
{
    return $this->hasMany(ProductType::class);
}

20 Jun
4 weeks 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
1 month 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
1 month 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
1 month 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
1 month 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
1 month 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
1 month 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
1 month 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
1 month 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
2 months ago
17 May
2 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" />

MThomas left a reply on Data Is Not Deleting In Laravel

Did you follow the component structure of:

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

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

@MIKE_SA - 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 :)

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://laravelfromscratch.com 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

MThomas left a reply on Auth::logout() Not Working As Expected

Why not add Auth::logout() to your /dev route and redirect to the guest route afterwards?

MThomas left a reply on Laravel API Image Upload

Have you checked this part of the documentation: https://laravel.com/docs/5.8/filesystem#file-uploads

MThomas left a reply on Laravel Rtl

you can set the locale in /config/app/php.

And find (and copy) other translations for the default translated strings https://github.com/spatie/laravel-translatable

In /resources/lang/ you can add other translations according to laravels localization: https://laravel.com/docs/5.8/localization

MThomas left a reply on Laravel Rtl

I think you have to do this using your css and your layout file.

https://www.w3schools.com/cssref/pr_text_direction.asp

MThomas left a reply on Undefined Variable: _ENV Error

@deekshith can you backtrack when this error occurred? What did you change before?

I think I have seen a similar question on Laracast, in that case the error occurred after a composer pull http://git.... and he/she forgot to run a composer install :)

MThomas left a reply on I Can't Access Header In Controller Construct

@munazzil sorry your answer does not make sense, there is nothing wrong with $this->user = User::where('id', Auth::id())->first(); the only viable comment about that part would have been that $this->user = Auth::user(); would have had the same result and event more effective.

->first() will get you the first result if there will be more, as ID is a primary key there can only be one result, so using ->get() will let you endup with a collection with one item and you need to add a loop or pull the first.

So yeah, your answer does not make sense at all.

MThomas left a reply on HOW CAN I SAVE THE PREVIOUS/YESTERDAY BALANCE

That is just basic laravel. add an if statement that checks if data has been saved for that day :)

MThomas left a reply on How Do You Install A Vue.js Package Into Laravel?

You should start watching the first episodes of the series, that will help you understand how Vue works. You need more understanding in order to get this not just to work, but not fall in any more pits.

Your creating two Vue instances (the ones with the 'el' property in it). keep the one that is default in your laravel app.js, and expand it with the things you need to add for vodal.

Copy the css files from your node modules directory to your own resource/css (if you use laravel mix) or public/css directory (you are currently trying to import them from outside the public realm). And add the import statements to your css/app file.

MThomas left a reply on 404 Page Instead Of {METHOD} Not Supported For This Route

If you really want to change the error, you could change the error rendering method for the exception being thrown:

https://laravel.com/docs/5.8/errors#render-method

16 May
2 months ago

MThomas left a reply on 404 Page Instead Of {METHOD} Not Supported For This Route

ah I see what you don't like. A solution can be that you change the default error handling (and you should realize that the error pages shown in your local development environment are differently styled that those on production). That way you can change the appearance of your error pages on production.

MThomas left a reply on Switching Team Subscription

I think it would be best to contact Jeffrey directly (click the contact link a the bottom of the page).

MThomas left a reply on Displaying Errors With Login And Register On Same Page

If you really can't change the markup of the page. The only option is adding a general error message, iterating over the fields errors. I don't think there will be an easy other option.

MThomas left a reply on How Do You Install A Vue.js Package Into Laravel?

@connecteev I think it best that you watch this series: https://laracasts.com/series/learn-vue-2-step-by-step

This is basic stuff regarding vue.

Add the 'component' to your blade template file where you will use the modal:

<vodal :show="show" animation="rotate" @hide="show = false">
    <div>A vue modal with animations.</div>
</vodal>

Add this to your public.js file resources directory

import Vue from 'vue';
import Vodal from 'vodal';

Vue.component(Vodal.name, Vodal);

export default {
  name: 'app',
    
  data() {
    return {
      show: false
    }
  }
}

Add this to your template layout file (near the spot where you include your own css)

// include animation styles
@import "vodal/common.css";
@import "vodal/rotate.css";

MThomas left a reply on 404 Page Instead Of {METHOD} Not Supported For This Route

You won't be able to access a POST Route as a GET. If you want to be able to visit the page in a browser or make a GET request, you need to register a get route:

Route::get('/admin/user/list/ajax', '[email protected]');

That is also the reason you will get the Method not supported error, you don't have a matching rout in your routes file that supports that method.

If you want to be sure that you will get a 404 for the get route, register a route (can be a closure) that will handle the get request and present the visitor with a 404:

Route::get('/admin/user/list/ajax', function() {
    return abort(404);
});
15 May
2 months ago

MThomas left a reply on 404 Page Instead Of {METHOD} Not Supported For This Route

Can you show your routes file?

It sounds like the order of your routes might cause this. If you have for example first a route ‘products/{product}’ followed by a route ‘products/sale’ the router will try to resolve ‘sale’ as a product. If you first declare the specific sale route, this will not happen.

MThomas left a reply on Displaying Errors With Login And Register On Same Page

An other suggestion is hiding (with jQuery or Vue) the login form when clients are registring and vice versa. Show the login form by default, add a button "Or create an account" that hides the login form and shows the registration form.

Think this will even be more user friendly.

MThomas left a reply on 404 Page Instead Of {METHOD} Not Supported For This Route

you might want to check this part of the Laravel Docs: https://laravel.com/docs/5.8/errors#custom-http-error-pages

You can change/add error handling pages :)