3 Best Reply Awards

  • Member Since 3 Years Ago
  • 252 Lessons Completed
  • 2 Favorites

19th July, 2018

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

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.

18th July, 2018

ts left a reply on Get Month First Date Of Last Six Months • 3 days ago

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().

29th June, 2018

ts left a reply on Associating Models Through BelongsToMany Relationships • 3 weeks ago

@rumm.an I didn't know that, nice!

ts left a reply on Associating Models Through BelongsToMany Relationships • 3 weeks ago

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 • 3 weeks ago

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.

25th June, 2018

ts left a reply on Spatie Media Library Integration • 3 weeks ago

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

15th June, 2018

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

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

12th June, 2018

ts left a reply on Mail Queue Error • 1 month ago

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

24th May, 2018

ts left a reply on No Invoice/receipt Is Being Received On Card Charge • 1 month ago

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.

22nd May, 2018

ts left a reply on Validate Encrypted • 1 month ago

@tykus @Snapey

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

21st May, 2018

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

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


18th May, 2018

ts left a reply on Getting An Image To Save • 2 months ago

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? • 2 months ago

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

17th May, 2018

ts left a reply on Displaying Records If Both Structure Are True. • 2 months ago

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 • 2 months ago

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 • 2 months ago

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.

18th April, 2018

ts left a reply on Injecting A Relationship • 3 months ago

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

17th April, 2018

ts left a reply on Injecting A Relationship • 3 months ago

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

16th April, 2018

ts started a new conversation Injecting A Relationship • 3 months ago

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

15th April, 2018

ts started a new conversation Repository Pattern • 3 months ago

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!

15th October, 2015

ts left a reply on Best Place To Store User Attributes • 2 years ago

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.

14th October, 2015

ts started a new conversation Best Place To Store User Attributes • 2 years ago

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?


Edit Your Profile

Want to change your profile photo? We pull from gravatar.com.