DerManoMann

DerManoMann

Member Since 5 Months Ago

Experience Points
320
Total
Experience

4,680 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
1
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 1
320 XP
Jun
25
4 months ago
Activity icon

Replied to HasManyThrough With MorphMany

Hmm, looks like I could use just a regular hasManyThrough using the morph id and then tack on a where clause to fix the morph type too...

Activity icon

Replied to Relationship From Query?

In the end I stuck with what I had - it works and is simple. Only thing that is annoying is to call ->get()->first(); when accessing it; ie: ->bestOffer()->get()->first() which doesn't look very nice.

Activity icon

Started a new Conversation HasManyThrough With MorphMany

Relationship:

[A] -> hasMany() -> [B] -> morphMany() -> [C]

So I would like to access all [C] on [A] via hasManyThrough, but that seems not possible?

Jun
19
4 months ago
Activity icon

Replied to Relationship From Query?

Yeah, that works. Cheers.

Activity icon

Started a new Conversation Relationship From Query?

Hi there,

I've got this model method that I would like to convert into a proper relationship. Is that possible? Basically I want to convert the query into a HasOne...

    public function bestOffer()
    {
        return $this->hasMany(Offer::class)->orderBy('amount, 'desc')->limit(1);
    }

Jun
03
5 months ago
Activity icon

Replied to Conditional INSERT

Perfect! Thanks a lot!

Activity icon

Replied to Conditional INSERT

Yeah, selectRaw()... I've tried so many things, loosing track :)

I managed to track down the actual SQL executed which looks like this:

insert into `bids` (`id`, `bid_id`, `bid`) 
select 1, 1, 12 from `auction_bids` 
where
 not exists (select 1 from `auction_bids` where (`bid_id` = 1)) 
 or 
 not exists (select 1 from `auction_bids` where (`bid_id` = 1) having max(bid) >= 12)

The issue is the from `auction_bids` in select 1, 1, 12 from `auction_bids`. When I remove that and execute the SQL manually it works. Kinda makes sense as I am not really trying to select from the table directly....

So, the question now is how to supress the from `auction_bids` on the select

Activity icon

Replied to Conditional INSERT

Also, I am curious if there is a way around using the DB::raw (sprintf(..)) construct and use proper bindings instead. I seem to have issues using named bindings for some reason. (OTOH, I do not want to mix different issues...)

Activity icon

Replied to Conditional INSERT

As it is it does not insert anything at all.

Activity icon

Started a new Conversation Conditional INSERT

Hi there,

I am struggling to convert this conditional SQL into Builder code. Any help is much appreciated....

Given these inputs ['id' => 1, 'bid_id' => 2, 'bid' => 3] i want to insert if either there is not bid yet or the given bid is higher than any previous. I've tried the SQL as-is, but cannot get it into Eloquent (at least not without making it just one big string which I'd like to avoid).

SQL:

INSERT INTO bids (id, bid_id, bid)
// given id, bid_id and bid
SELECT 1, 2, 3
WHERE
    NOT EXISTS (SELECT 1 from bids where bid_id = 2)
OR
    NOT EXISTS (SELECT 1 from bids where bid_id = 2 HAVING max(bid) >= 3)
$id = 1;
$bidId = 2;
$bid = 3;

$select = static::query()
->whereNotExists(function (Builder $query) use ($bidId) {
$query
->from('bids')
->selectRaw(DB::raw(1))
->where(['bid_id' => $bidId]);
})
->orWhereNotExists(function(Builder $query) use ($bidId, $bid) {
$query
->from('bids')
->selectRaw(DB::raw(1))
->where(['bid_id' => $bidId])
->havingRaw('max(bid) >= ?', [$bid]);
})
->select(DB::raw(sprintf('%d, %d, %d', $id, $bidId, $bid)));

$model = DB::table('auction_bids')->insertUsing(['user_id', 'auction_id', 'bid'], $select);