PHP Developer at tomm.us


Member Since 3 Years Ago

Experience Points 27,675
Lessons Completed 332
Best Reply Awards 4
Best Answer
  • 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


    Earned if you are a paying Laracasts subscriber.

  • Lifer Achievement


    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.

05 Nov
2 months ago

ts left a reply on How To Generate A Unique But Simple Id For Ticket?

I use random_bytes and bin2hex:


The amount you give to random bytes is doubled when you pass it to bin2hex. So in this instance you'll get a ten character string.

Or, just generate a UUID and trim it to eight characters or something?

10 Oct
3 months ago

ts left a reply on Organize Polymorphic BelongsTo Save

You don't necessarily need a controller. I did something very similar last week with a Polymorphic belongsTo relationship for Notifications.

I ended up using a trait, it works perfectly for this kind of thing because the classes (should) all have the same logic for creating the relation.

19 Jul
5 months ago

ts left a reply on Facebook Share Giving Me An Error On "og:title"

As a separate issue, you've got debug mode turned on on production, so your app key and database password are compromised. You should change these.

18 Jul
5 months ago

ts left a reply on Get Month First Date Of Last Six Months

If I understand correctly, you could get "now" Carbon::now(), subtract a month (or six) ->subMonths(6) and then get the start of the month ->startOfMonth().

So Carbon::now()->subMonths(6)->startOfMonth().

29 Jun
6 months ago

ts left a reply on Associating Models Through BelongsToMany Relationships

I think I understand what you're needing. If you just want to access $job->operations in a blade view (and then $operation->risks and then $risk->measures), you only need to pass $job to the view. Like:

$job = Job::find($id); // or Job::findOrFail($id);
return view('jobs.show', compact('job'));

ts left a reply on Associating Models Through BelongsToMany Relationships

Consider using the hasManyThrough() method. https://laravel.com/docs/5.6/eloquent-relationships#has-many-through

I've not seen your codebase, but I'd guess you probably are wanting to enumerate through the 'risks' of a 'job'? If so, you could add a risks() method to your Job model utilising hasManyThrough().

Job::find($id)->risks or Job::find($id)->measures are much more readable and reusable.

25 Jun
6 months ago

ts left a reply on Spatie Media Library Integration

You can just use Auth::user() to get the logged in user, so $user = Auth::user().

Have you added the appropriate trait and interface to your user Model? https://docs.spatie.be/laravel-medialibrary/v7/basic-usage/preparing-your-model

15 Jun
7 months ago

ts left a reply on Pagination For The View Is Not Working In Laravel5.3

Yeah, as above. The paginate method doesn't return an array, but an instance of Illuminate\Pagination\LengthAwarePaginator. By iterating through this and adding the values to an array, you're losing all the methods that the LengthAwarePaginator provides. You should write it like so:

$referredProcedureBookings = Gateway::procedurebooking()->getReferredProcedureBooking()->paginate(5);
return view('procedurebookings', compact('referredProcedureBookings ');

There's more info in the documentation: https://laravel.com/api/5.3/Illuminate/Contracts/Pagination/LengthAwarePaginator.html

12 Jun
7 months ago

ts left a reply on Mail Queue Error

Strange. All looks fine to me. Try running composer dump-autoload in the terminal.

24 May
7 months ago

ts left a reply on No Invoice/receipt Is Being Received On Card Charge

There are a couple of ways to do this:

The easiest is setting the receipt in Stripe. If you go to Business Settings -> Customer Emails (or https://dashboard.stripe.com/account/emails), you can turn on "Email Customers for Successful Payments". I believe Laracasts does this.

Or, you could set up a job that is dispatched after successful payment. This would be more flexible in terms of presentation.

22 May
7 months ago

ts left a reply on Validate Encrypted

@tykus @Snapey

Stumbled on this today, thanks a lot guys, helped me at least!

21 May
7 months ago

ts left a reply on Assign The Value Of Id In User Table To The User_id In Posts Table Automatically ??

Using the create method on a Model relationship will automatically insert the correct id into the database.


18 May
7 months ago

ts left a reply on Getting An Image To Save

I've not used Dropzone.js before, but after a quick look at the documentation I'd imagine that the issue is in the instantiation of the Dropzone class in main.js. The documentation shows that the first argument should be the query selector for the form. Add an id to the form element and reference this.


ts left a reply on How To Use A Dynamic Page Title In A Laravel Application?

I like to add a @yield('title') to my base view, and then use @section('title', 'My title') in any views that extend this base view. You can see this in use in the documentation: https://laravel.com/docs/5.6/blade#defining-a-layout

Of course, if this is dependent on a language file, you can use the __ method to retrieve it, like so: `@section('title', __('titles.example'). https://laravel.com/docs/5.6/localization#retrieving-translation-strings

17 May
7 months ago

ts left a reply on Displaying Records If Both Structure Are True.

Check out query scopes: https://laravel.com/docs/5.6/eloquent#local-scopes

You could create a scope for "boosted" properties that contains the logic you currently have in your controller. You can then retrieve the properties like so: $boostedProperties = Property::boosted();

In your view, you should use a @foreach loop to iterate through each property.

Hope this helps some.

ts left a reply on Page Not Found On Route Invocation

Have you checked the laravel.log file for a specific error?

In the CommunityController, change the Community::find($id)->get(); to Community::find($id); You don't need to chain the get() command onto find().

ts left a reply on Gulp On Production

That depends. If you're committing the compiled assets (in public/) to version control, then no. Otherwise, you'll have to create some kind of post deploy hook to call gulp on the assets to compile them down on the server.

18 Apr
8 months ago

ts left a reply on Injecting A Relationship

@bobbybouwmann yeah, I've got my User model to use route model binding. I didn't think establishments would be necessary because a user belongsTo an establishment, so retrieving the user's establishment would be predictable. However, to futureproof (haha) the app, I'm going to change the relationship to belongsToMany - in future a user may be responsible for more than one establishment.

17 Apr
8 months ago

ts left a reply on Injecting A Relationship

@bobbybouwmann that's excellent, thanks so much.

I think the "best" way in this instance would be to use route model binding. The routes don't currently include the establishment, so I'll rewrite them to do so.

Thanks again!

16 Apr
9 months ago

ts started a new conversation Injecting A Relationship

Hi all,

So in a controller I'm accessing the establishment property of the authenticated user, which returns an Eloquent belongsTo relationship.

I'm accessing it in several places, currently like so:


Which I feel is bad. I'd really like to inject the establishment into the controller __construct method so I can access it as $this->establishment, but when I do, it returns a new instance of the establishment, not the user's establishment.

I've tried declaring a singleton in a service container and setting it to Auth::user()->establishment, but Auth::check() is returning false because (I'm guessing) the user hasn't been resolved?

I feel like I'm close to a solution. If there are any Laracasts or articles that might shed some light, that'd be ace.

Cheers, Tom

15 Apr
9 months ago

ts started a new conversation Repository Pattern

Hi all,

I just wanted to check I was on the right lines with this. It feels neat to me, but I've not used Laravel for a while and am just getting back into the swing of things.

I have an establishment that has visitors, that will be deleted after a certain time by a scheduled console command.

The console command is as so:

    public function handle()
        Establishment::all()->each(function ($establishment) {

The deleteExpiredVisitors() method on the Establishment class is as so:

    public function deleteExpiredVisitors()
        $visitors = (new VisitorRepository)->getExpiredVisitorsForEstablishment($this);

        $visitors->each(function ($visitor) {

And the VisitorRepository is as so:

    public function getExpiredVisitorsForEstablishment(Establishment $establishment)
        return $this->model->where([
            ['created_at', '>=', now()->subDays($establishment->days_retention)],
            ['establishment_id', '=', $establishment->id],

I suppose what I am asking is:

  • Is a repository necessary? From browsing the forum it seems they were popular a few years ago but I can't find much up-to-date reading on them.
  • How's my code.

Good to be back!

15 Oct
3 years ago

ts left a reply on Best Place To Store User Attributes

Thanks for the input all. It seems obvious now I've slept! I think if I add a role column as an integer to the Users table, make a Roles table, and then use ACL to control how users can access content.

14 Oct
3 years ago

ts started a new conversation Best Place To Store User Attributes

Hi all

We are in the process of creating a content management system for a school.

All faculty will have a log in, which is obviously stored in the users table.

My question is, where is the best place to put attributes that pertain to these staff members. For example, we have senior management, which might have access to actions or areas that other staff might not.

Obviously I could create an is_management column in the schema, but I'd imagine this to get unwieldy down the line as more attributes are added.

Advice is appreciated – are there any posts (or laracasts!) that might illuminate?