MartinZeltin

MartinZeltin

Member Since 1 Year Ago

Experience Points
20,200
Total
Experience

4,800 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
132
Lessons
Completed
Best Reply Awards
0
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.

Level 5
20,200 XP
Oct
16
3 days ago
Activity icon

Replied to How To Sort A Collection In Descending Order?

@sinnbeck If I put that in a service container and then Laravel releases with a build-in sortDesc won't I have a conflict?

Activity icon

Replied to How To Sort A Collection In Descending Order?

@jeffreyway but sortBy requires a key/field

Activity icon

Replied to How To Sort A Collection In Descending Order?

@sinnbeck thanks, that worked! I don't understand why there isn't a sortDesc() method, it should be added to the framework.

Activity icon

Started a new Conversation How To Sort A Collection In Descending Order?

Laravel collections has a sort() method to sort a collection (but only in ascending order). Unfortunately I can't find a way to sort in a descending order. There is no sortDesc() method and the sort method doesn't allow to pass a descending parameter.

Any help would be much appreciated.

I can only sort it in ascending order...

$sorted = $collection->sort();

Result:

Collection {#1884
  #items: array:10 [
    "GTA 5" => 1
    "CS" => 1
    "Trackmania" => 1
    "Doom" => 3
    "Quake Live" => 4
    "NHL" => 5
  ]
}
Oct
14
5 days ago
Activity icon

Replied to How To Get Posts With Comments AND Replies?

Thanks, yes. I needed to add comments() to my Posts model and replies() to my Comments model with a hasMany relationship.

Activity icon

Started a new Conversation How To Get Posts With Comments AND Replies?

So I have 3 tables - Posts, Comments, Replies. I would like to get All Posts with their comments and with the replies of comments. Like this

Posts: [
        id: 1,
        body: 'Post body'
        0 comment: {
             id: 1,
             body: 'Comment body for Post 1'
             0: reply: {
                id: 1,
                body: 'Reply for Comment 1'
             }
        }
]

$posts = Post::with('comment.reply')->get();

How do I need to set up relationships in my Models to make this work? I can't understand...

Oct
04
2 weeks ago
Activity icon

Replied to Excellence

@cbrewt yes I agree. Love the attention to detail on this site. And he is an excellent teacher. I love it how he is able to explain things in very simple terms.

I remember I was learning Vue.js and I couldn't understand it. Then I discovered a series on Laracasts and it all made sense. Just shut up and take my money, Jeff!

Activity icon

Replied to Node Js Api With Laravel

In this case you could use either Laravel or Node.js. Since you are using Laravel already, I would suggest you to have a Laravel app handle your API. Then hit those end points from any app you develop.

Sep
26
3 weeks ago
Activity icon

Started a new Conversation 2+2=4 Becomes 2 2=4 (where Did The + Go?)

This is very strange to me. I am trying to submit a POST request to my controller that saves to the database. But all the +'s have become empty spaces! I'm guessing it has something to do with encoding but I'm not sure how to preserve the +'s

With Postman I make a new POST request to my route

POST https://log.mywebsite.com/
key: log_message
value: 2+2=4

Here is the controller that handles the request:

$log_message                = new LogMessages;
$log_message->log_message   = $request->log_message;
$log_message->created_at    = date('Y-m-d H:i:s');
$log_message->save();

In the database this is what I end up with:

+----+-------------+---------------------+
| id | log_message | created_at          |
+----+-------------+---------------------+
| 1  | 2 2=4       | 2019-09-26 12:01:12 |
+----+-------------+---------------------+

How can I make sure the + is not lost in the process?

P.S. When I make the same request with axios, it preserves the +'s

Activity icon

Replied to Getting CSRF Token Mismatch With CURL POST Request

Ahh! I found the problem! I had to remove the trailing slash from my CSRF except

Instead of this

'https://log.mywebsite.com/*',

I replaced it with this and it worked!

'https://log.mywebsite.com*',
Activity icon

Replied to Getting CSRF Token Mismatch With CURL POST Request

Well, it looks like Postman is adding a X-CSRF token in headers for some reason...

Activity icon

Started a new Conversation Getting CSRF Token Mismatch With CURL POST Request

I can't understand what is happening here. When I make a POST request using Postman it works! But when I try to do a cURL POST request from a route then it gives me this error:

CSRF token mismatch /Middleware/VerifyCsrfToken.php#82

Here is my VerifyCsrfToken:

    protected $except = [
        'https://log.mywebsite.com/*',
    ];

Here is my cURL request

    Route::get('test', function (Illuminate\Http\Request $request)
    {
        $endpoint_url = 'https://log.mywebsite.com/';

        $data_to_post = ['log_message' => 'foo'];

        $options = [
            CURLOPT_URL        => $endpoint_url,
            CURLOPT_POST       => true,
            CURLOPT_POSTFIELDS => $data_to_post,
        ];

        $curl = curl_init();
        curl_setopt_array($curl, $options);
        $results = curl_exec($curl);
        curl_close($curl);

        return response()->json($results);
    });

What is happening? I'm so confused.. Why does it work with Postman but not from my route?

Sep
23
3 weeks ago
Activity icon

Replied to I Don't Understand Docker - What Am I Missing?

Thanks for pointing me in the right direction @ftiersch I will keep learning about these things. At first it is kind of difficult to wrap my head around it. But containers seem to be getting very popular.

Activity icon

Replied to I Don't Understand Docker - What Am I Missing?

@ftiersch thanks for the explanation, just a few more questions I'm wondering about...

you would create 10 application containers that you link up to a PHP container

I didn't know about linking up containers, I will have to look that up.

So your host persists the data and that data is passed into the container

How does that work? How would I get my app (which is running inside the container) to get my host to save data to the database?

Activity icon

Replied to I Don't Understand Docker - What Am I Missing?

I guess if I have 10 containers I would end up with 10 OSs?

Activity icon

Started a new Conversation I Don't Understand Docker - What Am I Missing?

So I started learning about Docker. And as far as I understand you bundle everything into one image for your app. But it doesn't make sense to me.

  1. If you bundle everything for every app into an image then that is a huge overhead. If you need 10 PHP applications then you would end up with 10 PHP installations (one for each docker image)? Makes no sense to me...

  2. If containers don't persist data, then how can you use a database?

Sep
19
1 month ago
Activity icon

Replied to How To Update Model Using Scope?

I wasn't aware of soft deleting, I will have to look into it. I'm fairly new to Laravel, still learning. Thank you for pointing me in the right direction!

Activity icon

Replied to How To Update Model Using Scope?

Thank you, yes you are right. It looks like it is working!

Activity icon

Started a new Conversation How To Update Model Using Scope?

I am trying to create a softDelete() method for my Model but I can't understand how to do this.

I would like to be able from my Controller to do this, and it would update is_deleted to 1:

User::where('id', 2)->softDelete();

Here is my Users table

+----+----------+------------+
| id | username | is_deleted |
+----+----------+------------+
| 1  | john     | 1          |
| 2  | jack     | 0          |
| 3  | joel     | 0          |
+----+----------+------------+

Here is my Model

class User extends Model
{
    public function scopeSoftDelete($query)
    {
        return $query->update(['is_deleted' => 1]);
    }
}

What am I doing wrong? Am I using scope in the wrong way?

Sep
05
1 month ago
Activity icon

Replied to Toggles

@sarahs74 Don't press the "Best answer" until you solve the issue, otherwise everyone will think that you already solved it.

Sep
04
1 month ago
Activity icon

Started a new Conversation ErrorException: Trying To Get Property Talk_time Of Non-object

I have a collection that I am trying to filter but it is giving me an error. I can't understand why because I know that this property does exist on this collection as can be seen from the dump.

What is happening here?

  $collection = $collection->filter(function ($item, $key) use ($limit) {
      return $item->talk_time > $limit;
  });
  ErrorException: Trying to get property talk_time of non-object

dump

object(Illuminate\Support\Collection)#1008 (1) {
  ["items":protected]=>
  array(30) {
    [0]=>
    array(3) {
      ["user_id"]=>
      int(30)
      ["day"]=>
      string(10) "2019-09-02"
      ["talk_time"]=>
      int(1713)
    }
    [1]=>
    array(3) {
      ["user_id"]=>
      int(30)
      ["day"]=>
      string(10) "2019-09-03"
      ["talk_time"]=>
      int(2154)
    }
    [2]=>
    array(3) {
      ["user_id"]=>
      int(30)
      ["day"]=>
      string(10) "2019-09-04"
      ["talk_time"]=>
      int(1488)
    }
}

$collection->all() outputs the following...

Array
(
    [0] => Array
        (
            [user_id] => 30
            [day] => 2019-09-02
            [talk_time] => 1713
        )

    [1] => Array
        (
            [user_id] => 30
            [day] => 2019-09-03
            [talk_time] => 2154
        )

    [2] => Array
        (
            [user_id] => 30
            [day] => 2019-09-04
            [talk_time] => 1488
        )
)
Activity icon

Replied to How To Merge 2 Collections Together?

awesome, that worked!

Activity icon

Replied to How To Merge 2 Collections Together?

@geraintp yes, it looks like this is what I was looking for (merging on user_id).

$merged = $col_one->map(function ($item) use ($col_two) {
      return  array_merge($item, $col_two->firstWhere('user_id', $item['user_id']));
 });

I guess it would be nice if there was a collection method that allowed to merge on key like this...

   $merged = $collection_one->merge($collection_two)->on('user_id');

isn't that elegant?

Activity icon

Replied to How To Merge 2 Collections Together?

@resin try this, it isn't working....

        $array1[] = [
            'user_id' => 1,
            'username' => 'johnive3',
            'posts' => 569,
        ];

        $array1[] = [
            'user_id' => 2,
            'username' => 'elliot',
            'posts' => 9,
        ];

        $array2[] = [
            'user_id' => 1,
            'username' => 'johnive3',
            'comments' => 1569,
        ];

        $array2[] = [
            'user_id' => 2,
            'username' => 'elliot',
            'comments' => 19,
        ];

        $collection_one = collect($array1);
        $collection_two = collect($array2);

        $merged = $collection_one->merge($collection_two);

        dump($merged->all());

result

array:4 [
  0 => array:3 [
    "user_id" => 1
    "username" => "johnive3"
    "posts" => 569
  ]
  1 => array:3 [
    "user_id" => 2
    "username" => "elliot"
    "posts" => 9
  ]
  2 => array:3 [
    "user_id" => 1
    "username" => "johnive3"
    "comments" => 1569
  ]
  3 => array:3 [
    "user_id" => 2
    "username" => "elliot"
    "comments" => 19
  ]
]

Activity icon

Replied to How To Merge 2 Collections Together?

I couldn't find any collection method that could do this

Activity icon

Started a new Conversation How To Merge 2 Collections Together?

I have 2 collections that I would like to merge but the merge() method doesn't seem to do what I expect.

Collection one

$collection_one = collect([
    'user_id' => 1,
    'username' => johnive3,
    'posts' => 569,
]);

  // 0 => array:3 [
  //   "user_id" => 1
  //   "username" => "johnive3"
  //   "posts" => 569
  // ],

  // 1 => array:3 [
  //   "user_id" => 105
  //   "username" => "larry_one"
  //   "posts" => 81
  // ],

  // 2 => array:3 [
  //   "user_id" => 7
  //   "username" => "sally25"
  //   "posts" => 1
  // ]

Collection two (added comments for each user)

$collection_two = collect([
    'user_id' => 1,
    'username' => johnive3,
    'comments' => 12,
]);

// 0 => array:3 [
//   "user_id" => 1
//   "username" => "johnive3"
//   "comments" => 12
// ],

// 1 => array:3 [
//   "user_id" => 105
//   "username" => "larry_one"
//   "comments" => 84
// ],

// 2 => array:3 [
//   "user_id" => 7
//   "username" => "sally25"
//   "comments" => 984
// ]

Expected result

[
    'user_id' => 1,
    'username' => johnive3,
    'posts' => 569
    'comments' => 12,
]

// 0 => array:3 [
//   "user_id" => 1
//   "username" => "johnive3"
//   "posts" => 569
//   "comments" => 12
// ],

// 1 => array:3 [
//   "user_id" => 105
//   "username" => "larry_one"
//   "posts" => 81
//   "comments" => 84
// ],

// 2 => array:3 [
//   "user_id" => 7
//   "username" => "sally25"
//   "posts" => 8
//   "comments" => 984
// ]
Sep
03
1 month ago
Activity icon

Replied to How To Transform A Collection Where Each Property Becomes A New Item?

This gave me an error:

message: "array_diff_key(): Argument #1 is not an array"
Activity icon

Started a new Conversation How To Transform A Collection Where Each Property Becomes A New Item?

Hello, I have a collection where I have data for users (their posts, comments and reputation). I would like to transform this collection where each item becomes one of the three properties (posts, comments and reputation).

So the result would be like - for field: 'posts' and user_id: 46 we have 1542 posts. And for field: 'comments' the same user has 2. etc.

I tried to create multiple loops over the collection to get to this result but it is not working as I don't know how may loops I need. Is there a better and more clean way to do this?

Here is my original collection

"data": [
    {
        "user_id": 46,
        "username": "johnive",
        "posts": 1542,
        "comments": 2,
        "reputation": 48.5,
    },

    {
        "user_id": 30,
        "username": "zacky13",
        "posts": 54,
        "comments": 16,
        "reputation": 14.3,
    },

    {
        "user_id": 107,
        "username": "lil_elf4",
        "posts": 564,
        "comments": 60,
        "reputation": 67.5,
    },
],

Here is the result I would like to achieve

"data": [
    {
        "user_id": 46,
        "username": "johnive",
        "field": "posts",
        "value": 1542
    },

    {
        "user_id": 46,
        "username": "johnive",
        "field": "comments",
        "value": 2
    },

    {
        "user_id": 46,
        "username": "johnive",
        "field": "reputation",
        "value": 48.5
    },

    {
        "user_id": 30,
        "username": "zacky13",
        "field": "posts",
        "value": 54
    },

    {
        "user_id": 30,
        "username": "zacky13",
        "field": "comments",
        "value": 16
    },

    ...
],

I tried using multiple loops seems like a dirty way to do it and I don't know how many loops I would need.

foreach ($collection as $item)
{
  $new_item = new stdClass;

  $new_item->user_id = $item->user_id;
  $new_item->username = $item->username;
  $new_item->field = 'posts';
  $new_item->value = $item->posts;
}

foreach ($collection as $item)
{
  $new_item = new stdClass;

  $new_item->user_id = $item->user_id;
  $new_item->username = $item->username;
  $new_item->field = 'comments';
  $new_item->value = $item->comments;
}

foreach ($collection as $item)
{
  $new_item = new stdClass;

  $new_item->user_id = $item->user_id;
  $new_item->username = $item->username;
  $new_item->field = 'reputation';
  $new_item->value = $item->reputation;
}
Aug
19
2 months ago
Activity icon

Replied to Is It Possible To DRY This Code (only 2 Lines Change)

Thanks, that does seem cleaner than what I had before.

Activity icon

Started a new Conversation Is It Possible To DRY This Code (only 2 Lines Change)

Hello, I am trying to get data with applied filters. And then with almost identical code to get sums and averages.

But 90% of it is repeated code (only the first and the last lines are different). Is there a way to avoid repeating myself like this? I know that this is probably not going to scale either.

/** NEEDS TO DRY **/
    $payments       = Payments::select('clients.id', 'employees.full_name', 'payments.employee_id', 'payments.id', 'payments.receive_date');
    $payments       = $payments->join('clients', 'clients.id', '=', 'payments.id');
    $payments       = $payments->join('employees', 'employees.id', '=', 'payments.employee_id');
    $payments       = $this->applyFilters($payments);
    $payments       = $payments->whereBetween('payments.receive_date', [$this->date_from, $this->date_to]);
    $payments       = $this->paginate($payments);


    $total_sums     = Payments::selectRaw("sum(price) as _sum_price, avg(price) as _avg_price, sum(remaining) as _sum_remaining");
    $total_sums     = $total_sums->join('clients', 'clients.id', '=', 'payments.id');
    $total_sums     = $total_sums->join('employees', 'employees.id', '=', 'payments.employee_id');
    $total_sums     = $this->applyFilters($total_sums);
    $total_sums     = $total_sums->whereBetween('payments.receive_date', [$this->date_from, $this->date_to]);
    $total_sums     = $total_sums->first();
/** NEEDS TO DRY **/
Aug
14
2 months ago
Activity icon

Replied to TokenMismatch - With Multiple Laravel Projects On One Server

The reason I specified the domain was because I have one Laravel project that is spread across multiple subcomains that should share the same authentification across all subdomains.

Laravel1 project routes:

forum.ultimategaming.com
blog.ultimategaming.com

Laravel2 project routes:

laravel2.ultimategaming.com

I only specified session domain for Laravel1 project.

Activity icon

Replied to TokenMismatch - With Multiple Laravel Projects On One Server

I changed the APP_NAME for each project but that didn't help.

I have an Apache server. The SESSION_DRIVER is set to file. Also these Laravel projects share the same domain with one.domain.com two.domain.com three.domain.com etc.

Aug
13
2 months ago
Activity icon

Started a new Conversation TokenMismatch - With Multiple Laravel Projects On One Server

I noticed a strange behavior. I have multiple Laravel projects on one server. When I log into one project and then try to log into another project (different sub domains) I get a TokenMismatchException.

But when I have not logged in to any project and I try to log in then it works. What could be causing this? Any ideas?

in config/session.php I have this

'domain' => '.mydomain.com',
Aug
12
2 months ago
Activity icon

Replied to How To Make Any Route Except For '/login/'

Thank you, that worked!

Activity icon

Started a new Conversation How To Make Any Route Except For '/login/'

I have a Route to any for a SPA. But I don't want to include '/login/' in the any rule. I can't figure out how to achieve this.. Any help would be much appreciated.

Here is my Route. Instead of "any", I would really like to say this - any route (except /login)

Because with the current route I end up in an infinite redirect loop.

Route::domain('forum.ultimategamerz.com')->group(function ()
{
    Route::get('{any?}',    '[email protected]')->where('any', '.*');
});
Jul
30
2 months ago
Activity icon

Replied to Call To A Member Function ToSql() On Array

True, but the bindings are separated from the query. I was thinking if it is possible to have bindings in the query.

like this

SELECT id, reply_text, sending_time
   FROM inbox_replies
   WHERE number IN ('123', '456', '789')
Activity icon

Replied to What Should I Learn, Vue Native Or React Native?

I would say if you already have experience with Vue and you like Vue then it would make sense to choose it. Build on our existing knowledge. Vue is also much simpler than React but just as powerful imho.

Activity icon

Replied to Not Getting Any Results Back From A Raw Query

I finally found a solution. It looks like the way I was doing it, I was passing in a single value to WHERE IN. So I remade it like so

$replies = DB::connection('second')
       ->table('sms_sender_inbox_replies')
       ->select('id', 'reply_text', 'sending_time')
       ->whereIn('phone_number', $phone_numbers)
       ->whereIn('id', DB::connection('second')
                         ->table('sms_sender_inbox_replies')
                         ->selectRaw('MAX(id)')
                         ->groupBy('phone_number'))
       ->get();
Activity icon

Replied to Not Getting Any Results Back From A Raw Query

P.S. Here is the output of the Query Log

I can't understand why it is returning an empty array.

Array
(
  [0] => Array
    (
      [query] => 
          SELECT id, reply_text, sending_time
          FROM sms_sender_inbox_replies
          WHERE phone_number IN (':phone_numbers')
          AND id IN (
              SELECT MAX(id)
              FROM sms_sender_inbox_replies
              GROUP BY phone_number
          )
                   
      [bindings] => Array
          (
              [phone_numbers] => +1234567819','+19873216154','+15984989898
          )

        [time] => 0.7
    )
)
Activity icon

Started a new Conversation Not Getting Any Results Back From A Raw Query

Hello, I have a raw query and when I run this query in phpMyAdmin it returns 3 results but when I try to use Laravel Query Builder I get an empty array.

My query

SELECT id, reply_text, sending_time
FROM sms_sender_inbox_replies
WHERE phone_number
IN ('+1234567819',  '+19873216154',  '+15984989898')
AND id IN (
    SELECT MAX( id ) 
    FROM sms_sender_inbox_replies
    GROUP BY phone_number
)

Result:

+----+-----------------+---------------------+
| id |   reply_text    |    sending_time     |
+----+-----------------+---------------------+
| 87 | This is a test  | 2019-07-30 08:25:26 |
| 54 | And another one | 2019-07-29 06:35:11 |
| 12 | Last test       | 2019-06-16 09:44:26 |
+----+-----------------+---------------------+

But when I try to do this query with Laravel I get back an empty array []

dump($phone_numbers);

// 0 => "+1234567819"
// 1 => "+19873216154"
// 2 => "+15984989898"

$phone_numbers = implode("','", $phone_numbers);
dump($phone_numbers);


// +1234567819','+19873216154','+15984989898


dump("SELECT id, reply_text, sending_time
                  FROM sms_sender_inbox_replies
                  WHERE phone_number IN ('$phone_numbers')
                  AND id IN (
                      SELECT MAX(id)
                      FROM sms_sender_inbox_replies
                      GROUP BY phone_number
                  )");


// SELECT id, reply_text, sending_time
// FROM sms_sender_inbox_replies
// WHERE phone_number
// IN ('+1234567819',  '+19873216154',  '+15984989898')
// AND id IN (
//  SELECT MAX( id ) 
//  FROM sms_sender_inbox_replies
//  GROUP BY phone_number
// )



$replies = DB::connection('second_connection')
             ->select("
                  SELECT id, reply_text, sending_time
                  FROM sms_sender_inbox_replies
                  WHERE phone_number IN (':phone_numbers')
                  AND id IN (
                      SELECT MAX(id)
                      FROM sms_sender_inbox_replies
                      GROUP BY phone_number
                  )
             ", ['phone_numbers' => $phone_numbers]);

dump($replies);

// []
Activity icon

Replied to Question About Vuejs

Why can't you accomplish them with Vue?

Can you paste your routes and controller method that renders the view so we can take a look at it?

Activity icon

Replied to Call To A Member Function ToSql() On Array

It gave me this kind of query

 [query] => 
   SELECT id, reply_text, sending_time
   FROM inbox_replies
   WHERE number IN (':numbers')

but I was hoping to get a raw sql like this

   SELECT id, reply_text, sending_time
   FROM inbox_replies
   WHERE number IN ('123', '456', '789')
Activity icon

Replied to Getting Data From Another Website Using Axios

I have used JSONP before but it is only for GET requests.

$.getJSON("https://www.website.com?callback=?", function(json) {
    console.log(json);
});
Activity icon

Replied to Question About Vuejs

Hi, could you give more explanation as to what exactly you are trying to achieve?

Activity icon

Replied to Call To A Member Function ToSql() On Array

I get this error

Method Illuminate\Support\Collection::toSql does not exist
Activity icon

Replied to Call To A Member Function ToSql() On Array

When I have bindings for my SQL query, I would like to see the query that was executed with bindings

Activity icon

Started a new Conversation Call To A Member Function ToSql() On Array

Hello, I am trying to use the toSql() function for Query Builder but it is not working. I get an error

Call to a member function toSql() on array

Here is my query

$replies = DB::connection('second_connection')
            ->select("
                 SELECT id, reply_text, sending_time
                 FROM inbox_replies
            ");

dump($replies->toSql());

It works on Eloquent but not for raw DB query like this. What am I doing wrong here?

May
21
4 months ago
Activity icon

Started a new Conversation LeftJoinSub() Inside Another Left Join Subquery?

Is it possible to put a left join subquery inside another left join subquery using Eloquent?

For example, I have this query that I would like to re-write using Eloquent and without using Raw.

I know only how to do one level leftJoinSub().

select
    contracts.id,
    payments.ink_id,
from contracts
    left join (
        select
            contracts.id,
            payments.ink_id,
        from
            contracts
        left join (
            select
                ink_id,
            from
                payments
            group by
                ink_id
        ) payments on payments.ink_id = contracts.id
    ) as payments on contracts.id = payments.ink_id
May
20
4 months ago
Activity icon

Replied to How To Pass A Variable To A Function With Callback?

@KUNDEFINE - Yes!!! Thank you! That's what I was looking for! Like Snapey said, it's hard to find something when you don't know what to search for.

function doIt($data, $callback) {
    $callback($data);
}


doIt('my data', function($data) {
    echo 'Anonymous function: ' . $data;
});