MartinZeltin

MartinZeltin

Member Since 6 Months Ago

Experience Points 12,620
Experience Level 3

2,380 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 82
Lessons
Completed
Best Reply Awards 0
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.

23 Feb
1 month ago

MartinZeltin started a new conversation How To Hide All Popovers On Document Click - Except The One Clicked

I have a Calendar component with days. When you click on a day, it shows it's popover. I am trying to make it so that if you click anywhere in the document it hides all popovers. But it should not hide the one that I just opened.

I added an event listener for document click but it fires after the Day component's @click event. Which means it shows the current day's popover and then immediately hides all popovers. But it should first hide all popovers and only then show the Day's popover.

HTML

<div id="app">
    <calendar-month-view>
        <day></day>
        <day></day>
        <day></day>
    </calendar-month-view>
</div>

My Day component

export default {

    template: `
        <div @click="isVisiblePopover = !isVisiblePopover">
            <popover v-show="isVisiblePopover" />
        </div>
    `,

    components: {
        Popover
    },

    data() {
        return {
            isVisiblePopover: false
        }
    },

    mounted() {
        $(document).click(event => {
            EventBus.$emit('popover-opened')
        });

        EventBus.$on('popover-opened', () => {
            this.isVisiblePopover = false
        });
    }
};
21 Feb
1 month ago

MartinZeltin started a new conversation Vue.js - How To Name Components If I Have Many That Could Be Called A User Component?

I am at loss how to name my components so that it would look good on the page and not have super long names. For example, I have an app where I have a UsersSidebar component and inside there are User components. But I also have a UserList and inside there is also User components but different components. And then I may have another different User component on the page. So they are 3 different User components but they are all called User. How could I solve this problem?

Should I call it users-sidebar-user and user-list-user because that looks very long and clunky. What if I have 2 different user-sidebar components? Should I call it general-user-sidebar and forum-user-sidebar and then forum-user-sidebar-user?

// Here the <user> is a sidebar item <li>username</li>
<users-sidebar>
    <user>
    <user>
    <user>
</users-sidebar>

// Here the <user> is a different component <div><h1>username</h1></div
<user-list>
    <user>
    <user>
    <user>
</user-list>


// And here <user> is <div class="card">username</user>
<user>
20 Feb
1 month ago

MartinZeltin started a new conversation Argument 2 Passed To App\Models\Thread::scopeFilter() Must Be An Instance Of App\Models\ThreadFilters, Instance Of App\Filters\ThreadFilters Given

I am trying to implement the Filters from the "Let's build a Laravel forum" series here at Laracasts. But I keep getting this error.

Argument 2 passed to App\Models\Thread::scopeFilter() must be an instance of App\Models\ThreadFilters, instance of App\Filters\ThreadFilters given

The idea is that you can filter the results like so

  ../public/threads?by=Martin&popular=1&limit=10

Here is App\Filters\Filters.php

namespace App\Filters;
use Illuminate\Http\Request;

abstract class Filters
{
    protected $request;
    protected $builder;
    protected $filters = [];

    public function __construct(Request $request) {
        $this->request = $request;
    }

    public function apply($builder) {
        $this->builder = $builder;

        foreach ($this->getFilters() as $filter => $value) {
            if (method_exists($this, $filter)) {
                $this->$filter($value);
            }
        }

        return $this->builder;
    }

    public function getFilters() {
        return array_filter($this->request->only($this->filters));
    }
}

And here is the App\Filters\ThreadFilters.php

namespace App\Filters;

class ThreadFilters extends Filters
{
    protected $filters = ['by'];

    protected function by($username) {
        return $this->builder->where('username', $username);
    }
}

And then I call it from a controller like this

    use App\Models\Thread;
    use App\Filters\ThreadFilters;

    public function index(Request $request, ThreadFilters $filters)
    {
        return Thread::filter($filters)->get();
    }

Thread model looks like this

public function scopeFilter($query, ThreadFilters $filters)
{
    return $filters->apply($query);
}

My routes look like this

    Route::get('home', '[email protected]');

MartinZeltin left a reply on How To Call [email protected] From A Route Without A Controller?

@SNAPEY - Thanks, I didn't know about those. I ended up using a controller.

MartinZeltin started a new conversation How To Call [email protected] From A Route Without A Controller?

I know that I can call a controller function like [email protected] but what if I don't want a controller but just a simple plain class with a method and to call that method, is that possible?

For example:

<?php 
    namespace App;

    use stdClass;

    class MyNewClass
    {
        public function doSomething()
        {
            echo "Hello world!";
        }
    }
?>

and call it like this from my routes

    Route::get('endpoint', '[email protected]');
19 Feb
1 month ago

MartinZeltin started a new conversation Newbie: Using The Same Variable Name For Foreach Loop?

This is a newbie question. But I wanted to ask if it is safe to use the same variable name for a foreach loop? Any potential pitfalls for doing it like this?

$news = News::all();

foreach($news as $news)
{
      echo $news->story;
}
06 Feb
1 month ago

MartinZeltin left a reply on How Could I Create This With Objects Instead Of Array?

@WILK_RANDALL - True but only inside the foreach loop. However, I would like to create it as an object to begin with.

MartinZeltin started a new conversation How Could I Create This With Objects Instead Of Array?

I am trying to create an array but I would like to be able to access it like an object (more Laravel-like) instead like array.

Here is an example, I would like to be able to do this.

  foreach ($data->total->stats as $stat) {
     echo $stat->sold;
     echo $stat->paid;
     echo $stat->in_stock;
  }

but with my current code I can only do it with $item[''] which doesn't look that nice.

  foreach ($data->total->stats as $stat) {
     echo $stat['sold'];
     echo $stat['paid'];
     echo $stat['in_stock'];
  }

How could I re-create my current code? $data->total->stats should be an array of items that I could access likt $item->property

$data = new stdClass;
$data->total = new stdClass;

$data->total->stats = [];

foreach ($statsistics as $stats)
{
    $data->total->stats[] = [
      'sold'      => $stats->sold,
      'paid'      => $stats->paid,
      'in_stock'  => $stats->in_stock
    ];
}

MartinZeltin left a reply on Return Count: 0 If Nothing Was Found

@MAC03733 - Same result as before

[2019-02-06 10:46:25] local.INFO: 100  

MartinZeltin left a reply on Return Count: 0 If Nothing Was Found

@MAC03733 - The result was 100. It did not group it by SenderID

[2019-02-06 10:46:25] local.INFO: 100  

MartinZeltin started a new conversation Return Count: 0 If Nothing Was Found

I am trying to group count items in my table but the thing is that if it does not find anything matching the criteria then it doesn't return 0 but instead skips it altogether. Is there a way for it to return 0 if it did not find anything?

$sms_count = SentItems::selectRaw('SenderID, count(*) as count')
                      ->whereIn('SenderID', $data->pluck('modem_id')->all())
                      ->whereBetween('SendingDateTime', [$date_from . ' 00:00:00', $date_to . ' 23:59:59'])
                      ->groupBy('SenderID')
                      ->get();

For example here it skipped modem1, modem3, modem4 instead of returning count => 0

  0 => 
  array (
    'SenderID' => 'modem2',
    'count' => 2,
  ),

  1 => 
  array (
    'SenderID' => 'modem5',
    'count' => 1,
  ),
05 Feb
1 month ago

MartinZeltin left a reply on Is There GetWhere() Like There Is FirstWhere()?

@SNAPEY - I understand what you mean. But 99% of the time I use get() without extra parametrs and if get() is put on a new line then I could save a whole line :)

MartinZeltin left a reply on Is There GetWhere() Like There Is FirstWhere()?

That would be very convenient if we had getWhere or somehow create a macro.

MartinZeltin left a reply on Is There GetWhere() Like There Is FirstWhere()?

How could we make getWhere()?

MartinZeltin left a reply on Is There GetWhere() Like There Is FirstWhere()?

How could we make getFirst()?

MartinZeltin started a new conversation Is There GetWhere() Like There Is FirstWhere()?

I just found out about the firstWhere() method which is very handy but I wonder if there is also a getWhere() method for Eloquent? So that I don't have to call where() and then get(). Or is it possible to add it via a macro somehow?

// this would be shorter
$user = getWhere('fullname', 'John');

// ... than doing this
$user = where('fullname', 'John')->get();

MartinZeltin left a reply on How Could I Join 2 Collections From 2 Different Databases?

As far as I know joins will only work if it is in the same database, right?

MartinZeltin started a new conversation How Could I Join 2 Collections From 2 Different Databases?

I have 2 tables in 2 different databases - users and posts. I want to retrieve all users AND all user's posts (count) in ONE collection. So that the end result would look like this.

$model->username     // john
$model->fullname     // John Smith
$model->user_avatar  // jsm2m.jpg
$model->user_posts_count // 3  <-- from different database

Of course I could first retrieve all users and then in another collection get all his posts count like this...

// I don't want 2 different collection like this....
$users = Users::all();
$user_posts_count = Posts::where('user_id', 1)->count();

But I want it all to be in one collection (variable) for convenience.

**Users table**
id | username |   fullname   |  user_avatar
1      john      John Smith      jsm2m.jpg
2     martin     Bob Martin     jk3i302.jpg

**Posts table (different database)**
id | user_id |    post_body
1       1        hello world
2       1        howdy yall
3       1        what is up?
29 Jan
1 month ago

MartinZeltin started a new conversation Hide Popup Box When Clicked Anywhere On The Document

I am trying to make a component with a list of items and when I click on each of the items, it shows me an edit popup. When I click on it again, it hides the edit popup. But I would like to also be able to click anywhere on the document and hide all edit popups (by setting edit_item_visible = false).

I tried v-on-clickaway but since I have a list of items then it would trigger multiple times. And the @click event would trigger first and then the clickaway event would trigger multiple times and hide it right after showing it. I also tried to change the component's data from outside but with no luck.

Vue.component('item-list', {
    template: `
        <div>
            <div v-for="(item, index) in items" @click="showEdit(index)">
                <div>{{ item.id }}</div>
                <div>{{ item.description }}</div>

                <div v-if="edit_item_visible" class="edit-item">
                    Edit this item here...
                </div>
            </div>
        </div>
    `,

    data()
    {
        return {
            items: [],
            edit_item_visible: false,
            selected: null,
        };
    },

    methods:
    {
        showEdit(index)
        {
            this.selected = index;
            this.edit_item_visible = !this.edit_item_visible;
        }
    },
});

const App = new Vue ({
    el: '#app',
})
21 Jan
2 months ago

MartinZeltin left a reply on Losing Intended URL After Using It Once. Really Strange Behavior.

Undefined variable: request (View: /var/www/php7/newlaravel/resources/Views/auth/login.blade.php)

I get this error when I try to access the intended url via sessian

<input type="text" id="target_url" value="{{ $request->session()->get('url.intended') }}">

MartinZeltin left a reply on Losing Intended URL After Using It Once. Really Strange Behavior.

@SNAPEY - Could you provide an example? I can't understand why it disappears...

MartinZeltin left a reply on Losing Intended URL After Using It Once. Really Strange Behavior.

@WILK_RANDALL - I put this in my blade but it shows empty

<input type="hidden" id="target_url" value="{{ $request->session()->get('url.intended') }}">

the result is this

<input type="hidden" id="target_url" value="">

MartinZeltin left a reply on Losing Intended URL After Using It Once. Really Strange Behavior.

@WILK_RANDALL - I put this in my blade but it shows empty

<input type="hidden" id="target_url" value="{{ $request->session()->get('url.intended') }}">

the result is this

<input type="hidden" id="target_url" value="">

MartinZeltin left a reply on Losing Intended URL After Using It Once. Really Strange Behavior.

@WILK_RANDALL - I put this in my blade but it shows empty

<input type="hidden" id="target_url" value="{{ $request->session()->get('url.intended') }}">

the result is this

MartinZeltin left a reply on Losing Intended URL After Using It Once. Really Strange Behavior.

I don't understand, how could I retrieve the intended url without redirecting and losing it.

if I go to http://localhost/project/public/admin/ then I get redirected after login to admin

public function login(Request $request)
{
    ...
    Auth::login($user);
    return redirect()->intended('/');
}

But when I do this then I get redirected back to /public/

public function login(Request $request)
{
    ...
    Auth::login($user);
        $intended_url = redirect()->intended()->getTargetUrl();

    return redirect()->intended('/');
}

Is there a way for me to retrieve the intended target url without redirecting so I can do something with that url?

MartinZeltin left a reply on Losing Intended URL After Using It Once. Really Strange Behavior.

I don't understand, how could I retrieve the intended url without redirecting and losing it.

if I go to http://localhost/project/public/admin/ then I get redirected after login to admin

public function login(Request $request)
{
    ...
    Auth::login($user);
    return redirect()->intended('/');
}

But when I do this then I get redirected back to /public/

public function login(Request $request)
{
    ...
    Auth::login($user);
        $intended_url = redirect()->intended()->getTargetUrl();

    return redirect()->intended('/');
}

Is there a way for me to retrieve the intended target url without redirecting so I can do something with that url?

MartinZeltin left a reply on Losing Intended URL After Using It Once. Really Strange Behavior.

@MARTENVANURK - The redirect works fine it just becomes unavailable once I call it. I lose it.

MartinZeltin started a new conversation Losing Intended URL After Using It Once. Really Strange Behavior.

I am seeing some really strange behavior. I have my login() function redirect to intended() url and it is working fine until I put this line in my login.blade.php just to see what the intended URL was. Then my login() function doesn't know what the intended url was anymore. This is super strange.

My Login Controller

public function login(Request $request)
{
    .....
    // works great!
    Auth::login($user);
    return redirect()->intended('/');
}

But then I added this line in my login.blade.php and I lost my intended URL

<input type="hidden" id="target_url" value="{{ redirect()->intended()->getTargetUrl() }}">

And now when I log in I get redirected back to the home page ('/') instead of my intended target url. What is going on here?

echo redirect()->intended()->getTargetUrl();

// now it is simply http://localhost/project/public
// before it was http://localhost/project/public/intended-page/
15 Jan
2 months ago

MartinZeltin left a reply on Is There A Way To Sort A Collectin Using SortBy($key, 'asc/desc')?

@REALRANDYALLEN - But I still need to check if the $order is == 'asc' or 'desc' and do sortBy or sortByDesc instead of passing it as second argument?

MartinZeltin started a new conversation Is There A Way To Sort A Collectin Using SortBy($key, 'asc/desc')?

I noticed that the sortBy methods are a little bit different on Collection than on Query Builder, I'm not sure why that is. It seems more difficult to sort a collection by a key since it does not accept a second argument for asc/desc.

I would love to be able to sort by collection like this but I can't.

    $order = 'desc';
    $sorted = $collection->sortBy($company->user->id, $order)

But instead I have to do it this way. (As far as I know).

    $sorted = $collection ->sortBy(function ($item) {
        return $item->company->user->id;
    })

So... is it possible to sort like with the first (much shorter) method?

And is it possible to specify the order of 'asc/desc' without doing a if/else like this...

    if ($order == 'asc') {
        $sorted = $collection ->sortBy(function ($item) {
            return $item->company->user->id;
        })
    } else if ($order == 'desc') {
        $sorted = $collection ->sortByDesc(function ($item) {
            return $item->company->user->id;
        })
    }

MartinZeltin left a reply on How Could I Extend Collection With Macros To Sum Times?

Is it also possible not to hard-code $item->work_time but be able to use sumTimes('key_here')?

MartinZeltin left a reply on How Could I Extend Collection With Macros To Sum Times?

@ADAMPRICKETT - Oh, I see, thanks for the explanation.

MartinZeltin left a reply on How Could I Extend Collection With Macros To Sum Times?

@S4MUEL - works like a charm! :) Thanks!

Out of curiosity, what does this line mean? Why is it at the very end?

    }, ['h' => 0, 'm' => 0, 's' => 0]); 

MartinZeltin left a reply on How Could I Extend Collection With Macros To Sum Times?

Now I'm getting Illegal offset error

ErrorException (E_WARNING)
Illegal string offset 'h'

at: $sum['h'] += intval($h);

MartinZeltin left a reply on How Could I Extend Collection With Macros To Sum Times?

@ADAMPRICKETT - I'm getting an error

$total = $this->database->work_time_stats->sumTimes('work_time');
ErrorException (E_WARNING)
A non-numeric value encountered

at: $sum['h'] += $h;

My macro looks like this:

Collection::macro('sumTimes', function () {
    return $this->reduce(function ($sum, $value) {
        list($h, $m, $s) = explode(':', $value);

        $sum['h'] += $h;
        $sum['m'] += $m;
        $sum['s'] += $s;
        
        $sum['m'] += floor($sum['s'] / 60);
        $sum['h'] += floor($sum['m'] / 60);
        $sum['s'] = $sum['s'] % 60;
        $sum['m'] = $sum['m'] % 60;
        
        $sum = implode(':', $sum);

        return $sum;
    }, ['h'=>0, 'm'=>0, 's'=>0]);
});

The collection looks like this:

[
    {
        "id": 5071,
        "user_id": 30,
        "work_date": "2018-12-03",
        "work_time": "20:43:59"
    },
    {
        "id": 5072,
        "user_id": 30,
        "work_date": "2018-12-03",
        "work_time": "07:43:59"
    },
    {
        "id": 5073,
        "user_id": 30,
        "work_date": "2018-12-03",
        "work_time": "18:43:59"
    },
]

MartinZeltin left a reply on How Could I Extend Collection With Macros To Sum Times?

namespace App\Providers;

use Auth;
use stdClass;
use Illuminate\Support\Facades\Blade;
use Illuminate\Support\ServiceProvider;
use Illuminate\Support\Facades\Collection;

I'm also getting this error

Symfony \ Component \ Debug \ Exception \ FatalThrowableError (E_ERROR)
Class 'Illuminate\Support\Facades\Collection' not found

MartinZeltin started a new conversation How Could I Extend Collection With Macros To Sum Times?

I looked into the sum() function of Collection class and it looks like it only does array_sum($this->items). But if my items contain times in the format of '127:55:12' then it throws an error that it is not an integer. So I wrote a function to sum times and I would like to be able to extend Collection and add sumTimes() function to it. The problem is that I'm not sure exactly how to do it. I suppose I need to map over the collection somehow?

In the end I would love to be able to simply do this to get the sum:

    $total->work_time = $this->collection->work_time_stats->sumTimes('work_time');
    // result: 234:37:12

I have placed this macro in my AppServiceProvider's boot method.

Collection::macro('sumTimes', function () {
    return $this->map(function ($value) {
        //
    });
});

and my function for getting the sum of times looks like this:

$times = [ '217:43:59', '07:50:54', '07:51:43' ];
$sum = [ 'h'=>0,'m'=>0,'s'=>0 ];
    
foreach( $times as $time ) {
    list($h, $m, $s) = explode(':', $time);
    $sum['h'] += $h;
    $sum['m'] += $m;
    $sum['s'] += $s;
}

$sum['m'] += floor($sum['s'] / 60);
$sum['h'] += floor($sum['m'] / 60);
$sum['s'] = $sum['s'] % 60;
$sum['m'] = $sum['m'] % 60;

echo implode(':', $sum); // prints 234:37:12
14 Jan
2 months ago

MartinZeltin left a reply on Can't Use WhereBetween On A Collection (method Not Found)

@PATRICKSJ - I'm on 5.6 I think that was the problem.

MartinZeltin left a reply on Can't Use WhereBetween On A Collection (method Not Found)

@SHEZ1983 - I am trying to gather all the data at first and then work with the collection.

For example I got $this->database->comments->all(); and then worked with that collection. But whereBetween is not working... :(

MartinZeltin started a new conversation Can't Use WhereBetween On A Collection (method Not Found)

I can't seem to be able to use whereBetween method on a collection. It works on an Eloquent model but if it is a local collection then it says not found. Is there a way to perform a whereBetween search on a collection?

Method Illuminate\Database\Eloquent\Collection::whereBetween does not exist.
$comments = $this->database->comments->where('user_id', $user_id)
                                     ->whereBetween('date_from', [$date_from, $date_to])
                                     ->whereBetween('date_to', [$date_from, $date_to])
                                     ->first();

MartinZeltin left a reply on Is It Possible To Join Another Table Based On 2 Columns Using With()?

@ZION - oh, that's a good point. They are all related by user_id so I could do a where on the date to filter them. I will give it a try.

MartinZeltin left a reply on Is It Possible To Join Another Table Based On 2 Columns Using With()?

@VILFAGO - Because in one table are comments for that user and time period, then activities, logs, achievements etc. they can't all be in one table. So they are split between multiple tables.

MartinZeltin left a reply on Is It Possible To Join Another Table Based On 2 Columns Using With()?

@ZION - Simply so that I could avoid making a lot of collections and have just one collection to work with later...

So instead of doing this...

$data->table_one = TableOne::whereIn('user_id', $user_id)
                    ->whereBetween('date_from', [$date_from, $date_to])
                    ->whereBetween('date_to', [$date_from, $date_to])
                    ->get();

$data->table_two = TableTwo::whereIn('user_id', $user_id)
                           ->whereBetween('date_from', [$date_from, $date_to])
                           ->whereBetween('date_to', [$date_from, $date_to])
                           ->get();

$data->table_three = TableThree::whereIn('user_id', $user_id)
                                ->whereBetween('date_from', [$date_from, $date_to])
                                ->whereBetween('date_to', [$date_from, $date_to])
                                ->get();

$data->table_four = TableFour::whereIn('user_id', $user_id)
                              ->whereBetween('date_from', [$date_from, $date_to])
                              ->whereBetween('date_to', [$date_from, $date_to])
                              ->get();

$data->table_five = TableFive::whereIn('user_id', $user_id)
                            ->whereBetween('date_from', [$date_from, $date_to])
                            ->whereBetween('date_to', [$date_from, $date_to])
                            ->get();

I could do simply this...

$data = TableOne::whereIn('user_id', $user_id)
                ->whereBetween('date_from', [$date_from, $date_to])
                ->whereBetween('date_to', [$date_from, $date_to])
                ->with('table_two')
                ->with('table_three')
                ->with('table_four')
                ->with('table_five')
                ->get();

And I would end up with this

[  
   {  
      "id":1,
      "user_id":75,
      "date_from":"2019-01-01",
      "date_to":"2019-01-31",
      "table_two": [
        {
            "id":1,
            "user_id":75,
            "date_from":"2019-01-01",
            "date_to":"2019-01-31",
            "reward":"candy",
        },
      ]
      "table_three": [
        {
            "id":1,
            "user_id":75,
            "date_from":"2019-01-01",
            "date_to":"2019-01-31",
            "reward":"candy",
        },
      ]
   },
   
   {  
      "id":1,
      "user_id":75,
      "date_from":"2019-01-01",
      "date_to":"2019-01-31",
      "table_two": [
        {
            "id":1,
            "user_id":75,
            "date_from":"2019-01-01",
            "date_to":"2019-01-31",
            "reward":"candy",
        },
      ]
      "table_three": [
        {
            "id":1,
            "user_id":75,
            "date_from":"2019-01-01",
            "date_to":"2019-01-31",
            "reward":"candy",
        },
      ]
   },
]

MartinZeltin left a reply on Is It Possible To Join Another Table Based On 2 Columns Using With()?

@VILFAGO - Yea, that's the thing, it is an array of users, so for each user there should be a key for 'table_two' with an array of that table's data. I may end up just using a bunch of collections (one for each table) instead of trying to join them all together in one collection... meh...

MartinZeltin left a reply on Is It Possible To Join Another Table Based On 2 Columns Using With()?

Maybe there is a way to use with() without a relationship? Like passing a variable

$table_two = TableTwo::all();

$table_one = TableOne::with('table_two', $table_two);

I tried this but it was asking for a relationship instead of a collection :(

MartinZeltin left a reply on Is It Possible To Join Another Table Based On 2 Columns Using With()?

Joins also require a foreign key. I thought I could get table_two later and push it into the original collection but it did not work like with(), it just added it at the end.