Mick79

Mick79

Member Since 1 Year Ago

Glasgow

Founder at SongBox

Experience Points 9,060
Experience
Level
Lessons Completed 32
Lessons
Completed
Best Reply Awards 1
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.

22 Jan
17 hours ago

Mick79 started a new conversation Installing Laravel On A Freelancers Machine

I've hired a UX specialist I know to tidy up my app. I am trying to install Laravel and Valet in his machine. I am getting a Whoops screen with this error

preg_replace_callback(): JIT compilation failed: no more memory

Can anyone advise?

13 Jan
1 week ago

Mick79 left a reply on Return User To Page They Logged In From

@CRONIX - Ugh.... no I'm just gonna go ahead and store the referring route in a session variable and play it back out the other side of the login process.

Mick79 left a reply on Return User To Page They Logged In From

@JLRDW - lol not a problem.

Mick79 left a reply on Return User To Page They Logged In From

@CRONIX - Yeah - maybe I'm tackling this problem badly.

I have a "follow this user" button which posts via Ajax to a controller that does the business behind the scenes... actually I'll just show you:

 @auth
                                    <form class='follow'>
                                        @if ($check)
                                            <button type='submit' class='btn bg-white mt-4 btn-block' id='follow_button'>Un-Follow Me</button>
                                        @else
                                            <button type='submit' class='btn bg-white mt-4 btn-block' id='follow_button'>Follow Me</button>
                                        @endif
                                        <input type="hidden" name='profile_id' id='profile_id' value='{{$profile->id}}'>
                                    </form>
                                @else
                                    <a href='/login' class='btn bg-white text-dark mt-4 btn-block' id='follow_button'>Follow Me</a>
                                @endif

Mick79 left a reply on Return User To Page They Logged In From

@ADAMPRICKETT - Hi Adam thanks for this but I don't think it will work in this use case.

They are not trying to access a url at this point, they are pushing a button.

If the user is logged in then the button performs an action, if they are not logged in it pushed them to the login screen.

Mick79 left a reply on Return User To Page They Logged In From

@jlrdw would that not push them back to the login page?

Mick79 started a new conversation Return User To Page They Logged In From

I'd like to push my users back to the page they logged in from. Is this possible in some clever Laravel way or will I need to catch the referring route and then pass it through the login process etc?

06 Jan
2 weeks ago

Mick79 left a reply on Return Collection Grouped By Date

It's cool I sorted it. I needed to do a foreach inside the foreach. Which I already knew I would need to do.... D'oh!

Mick79 left a reply on Return Collection Grouped By Date

@daniyum21 previously I would access the data with

$product->site_name

however now that isn't working for example I'm getting this error

Property [site_screengrab] does not exist on this collection instance.

however if I do this

$product[0]->site_name

it works. I can't replace that "0" with a variable and increment it either as that will obviously fail.

Please help :-)

05 Jan
2 weeks ago

Mick79 left a reply on Return Collection Grouped By Date

Thanks @daniyum21 - how would I output that in the blade to be structured as I need it?

Sorry for asking but I feel like I've tried everything possible with the query itself.

Mick79 started a new conversation Return Collection Grouped By Date

I've asked this question before and it didn't get resolved, but I'm pretty sure I asked the question terribly. Here's my second attempt.

I have a collection and I need to output that collection grouped by a given timeframe (by week initially then as the site gets busier by day).

Here is the code I'm using to get the collection:

$latest = Site::query()
                ->with('upvotes')
                ->where([
                    ['is_approved', '=', 2],
                    ['is_featured', '=', 1],
                ])->orderBy('created_at', 'DESC')
                ->get();

I have tried various different ways of doing a "group by" but I don't think that's the solution.

What I'm trying to achieve is to run an @foreach in the blade and have the results output like this

Today

- Item 1
- Item 2
- Item 3

Yesterday

- Item 1
- Item 2

2 days ago

Item 1
Item 2
Item 3

Etc Etc...

It's proving fairly challenging.

it seems to me like what I need to achieve is something along the lines of

@foreach($dates as $date)

    {{$date->diffForHumans()}}
    
    @foreach($date as $items)
        $item->name
        $item->description
    @endforeach

@endforeach

But I don't know, or can't figure out how to get there.

All help appreciated.

04 Jan
2 weeks ago

Mick79 left a reply on Return Items Separated Out By Date

Hi Richard that didn't change anything. It didn't break anything, but it didn't change anything either. I'm just getting all the products output as they were.

I feel like I'm missing something. This shouldn't be hard.

Mick79 left a reply on Return Items Separated Out By Date

@NOLROS - Hi thanks for replying, when I use this code I get the same output as I'm getting at the moment. I fear I'm missing something. Do I need to change the foreach in the blade to start the loop with the date?

Thanks

Mick79 left a reply on Return Items Separated Out By Date

@TYKUS - Hi thanks for this. My code now looks like this:

Controller

$latest = Site::query()
                ->with('upvotes')
                ->where([
                    ['is_approved', '=', 2],
                    ['is_featured', '=', 1],
                ])->orderBy('created_at', 'DESC')
                ->groupBy(DB::raw("DAY(created_at)"), 'ID')
                ->get();

            // New section
            $latest->groupBy(function ($item) {
                return $item->created_at->toDateString();
            });


            return view('home', compact( 'user', 'featured', 'latest', 'voted', 'y'));

Blade

@foreach ($latest as $product)

//output the product details

@endforeach

But how do I get each loop to start with the date? Bear in mind I just want each loop to start with the date and not each product/item.

Thanks so much for taking the time to reply.

03 Jan
2 weeks ago

Mick79 started a new conversation Return Items Separated Out By Date

I am returning a bunch of items and would like them listed by date. I'm using this query

$latest = Site::query()
                ->with('upvotes')
                ->where([
                    ['is_approved', '=', 2],
                    ['is_featured', '=', 1],
                ])->orderBy('created_at', 'DESC')
                ->groupBy(DB::raw("DAY(created_at)"), 'ID')
                ->get();

I'd like to output the items on the page like this:

TODAY item 1 item 2 item 3

YESTERDAY Item 1 Item 2

2nd January Item 1 Item 2 Item 3

1st January Item 1 Item 2

etc etc

Kinda stuck.

Mick79 left a reply on How To Tell If A User Has Voted On / Liked An Item

Ah yes of course. This is actually my exact use case. I just thought it was quite ugly to do that as I have a bunch of other class names in there also. This is how it looks as I have it:

<button type='submit' id='btn{{$l->id}}' class='d-flex flex-column {{$voted}} justify-content-center align-items-center btn btn_upvote'>

It's already quite busy. I know I probably should do it the way you're suggesting though.

Mick79 left a reply on How To Tell If A User Has Voted On / Liked An Item

What would be the alternative to running @php ?

How else could I set that variable?

Mick79 left a reply on How To Tell If A User Has Voted On / Liked An Item

@snapey that works! oh my god I didn't know that "contains" method was a thing.

I'm glad I figured this out on my own but I'm much more glad that you showed me a much better way to do it. I knew the way I was doing it was bullshit.

My code now looks like this

@if($l->upvotes->contains('user_id', Auth::id()))
        @php $voted = "brand_bg" @endphp
    @else
        @php $voted = "" @endphp
@endif

Interestingly, if I don't add in the "else" rule then everything gets returned as true.

Mick79 left a reply on How To Tell If A User Has Voted On / Liked An Item

I figured this out but it's horrible and I'm not happy with it

  1. Inside each loop where I am reading out the products, I run another loop that pulls out all the user_ids that have upvoted.
  2. I run all of these into an array
  3. I then have to check the user is logged in
  4. Inside that check I check that the product has any votes at all
  5. inside that I attribute a "voted" class to a variable
  6. I then output that variable inside the vote button (so that if you've already voted on this product the button is blue, if not its white.

it looks like this INSIDE the blade template

 @foreach ($l->upvotes as $x)
                        @php
                            ${"array" . $l->id}[] =  $x->user_id
                        @endphp
                    @endforeach
                    @auth
                        @if (count($l->upvotes) > 0)
                            @if (in_array($user->id,${"array" . $l->id}))
                                @php
                                    $voted = "brand_bg"
                                @endphp
                            @endif
                        @endif
                    @endauth

Mick79 started a new conversation How To Tell If A User Has Voted On / Liked An Item

I'm having a bit of a confusing time right now trying to make something work that in my head should be easy.

I am building a site where people list products and other folks can upvote them - kinda like Product Hunt.

I have an Upvote model that contains ID, user_id, item_id

When reading out the products to display on the page, I get the number of upvotes by counting the number of upvotes for that item_id. That same model also tells me all the users who have voted.

But I can't seem to figure out how to display if a given user has upvoted a given product.

So for example if I'm logged in as user id 27 and I have upvoted item 76, then for me, when I am logged in I want to display a tick or something on that item.

christ... I'm aware of how bad this question is.

17 Dec
1 month ago

Mick79 started a new conversation Plot Line Graph

I have an array that looks like:

 0 => array:2 [▼
    "date" => "2018-06-08"
    "number" => 24
  ]
  1 => array:2 [▼
    "date" => "2018-06-15"
    "number" => 26
  ]
  2 => array:2 [▼
    "date" => "2018-06-22"
    "number" => 26
  ]
  3 => array:2 [▼
    "date" => "2018-06-29"
    "number" => 40
  ]

what's the best way to plot a line graph (to shoe growth) with date on the X axis and number on the Y axis?

I looked at Lavcharts but it seems difficult to get my head around.

Mick79 left a reply on Get Cumulative Users By Week

Hey thanks but I solved this with my own solution:

$date = Carbon::parse("2018-06-01");

            while ($date < NOW())
            {
                $cumulative_users = User::query()->select('id')->where('created_at', '<=', $date)->count();
                $date = $date->addWeek(1);
                $array[] = array("date"=>$date->toDateString(), 'number' => $cumulative_users);
            }

            dd($array);
16 Dec
1 month ago

Mick79 started a new conversation Get Cumulative Users By Week

Hi, I'm having trouble getting my head around writing something in Laravel to produce cumulative user numbers.

like...

Week 1 : 10 users
Week 2 : 8 users
Week 3: 22 users

I'd like to return an array that had

Week 1 : 10 users
Week 2 : 18 users
Week 3 : 40 users
06 Dec
1 month ago

Mick79 left a reply on Laravel And Gzip... How To?

@snapey - any idea how to do this on Heroku?

05 Dec
1 month ago

Mick79 left a reply on Laravel And Gzip... How To?

@WILK_RANDALL - hi thanks. Where did you add this exactly?

Mick79 started a new conversation Laravel And Gzip... How To?

hi ive googled around and can't seem to find anything on how to gzip all my css, js etc (basically everything in /public).

is this possible?

03 Dec
1 month ago

Mick79 left a reply on Do "something" Once A Day In Laravel

@SNAPEY - YES. Uptime robot! This is the kind of hack I was after.

I'll have that ping a route and utilise that to run the controller I need to have ran.

Love it.

Mick79 started a new conversation Envoyer / Forge / Heroku... Help

I currently run on heroku and by enlarge, it's awesome.

However.... given recent cron troubles, I was looking at Envoyer, which pointed me to Forge... and now I am lost.

How are Envoyer and Forge different? and do either of them let me add environment variables the way heroku does?

Thanks in advance. I did a search and didn't find any relevant threads on here,

Mick79 left a reply on Do "something" Once A Day In Laravel

@CRONIX - Hmmm... I'm running on Heroku. Not sure I can use Cron there. Let's see.

Mick79 left a reply on SQL Error Only In Production

I had to add every column in my "select" to my "group by". This solved it.

Mick79 started a new conversation Do "something" Once A Day In Laravel

My app sends out instant notifications via text message when something happens. However my app is starting to gain traction and get busy.... which is nice, obviously, but my Twilio bills are getting high.

I've spoke to some users and they have said a text message or an email once a day that collates all of their activity would be better.

I have never ever done any sort of scheduled stuff before, despite building large complex apps.... I've just always managed to avoid it.

Where would I start if I wanted to run something every night at like 8pm that went through all my users and sent them a text (if they have anything to report of course)?

Mick79 left a reply on Upload Multiple Files To AWS S3 From Laravel?

I struggled with this for a long time. I finally caved in and now use a service - filestack.

Honestly... it costs me $19 a month but I would pay more. They make uploading and asset storage a dream.

PS. I absolutely do not work or am affiliated in anyway with that company. I just struggled for so long with trying to create a nice file upload experience and they have changed my life (and my app) hugely for the better.

02 Dec
1 month ago

Mick79 left a reply on Can't Make Simple Query Work In Eloquent

@BIRROGER - Hi @birroger and thanks, but that's what I posted in my original question and as I already said, it doesn't work.

Mick79 left a reply on Can't Make Simple Query Work In Eloquent

OK thanks for that. I knew I could do it that way but hoped there would be an eloquent way to do it.

Thanks

Mick79 started a new conversation Can't Make Simple Query Work In Eloquent

I would like to get the total amount of sales per agent on my system. In normal SQL this works absolutely fine:

SELECT sum(food_total), cook_id FROM orders GROUP BY cook_id;

However my attempt at this using Eloquent seems to go very wrong:

 $users = order::query()->select('cook_id as id', 'food_total')
                ->groupBy('cook_id')
                ->sum('food_total');

this simply returns the total for the first agent in the database. I want them all returned as an array, but if I add a get() then everything goes to pot and I get the error

Call to a member function get() on string

What am I doing wrong?

24 Nov
1 month ago

Mick79 started a new conversation SQL Error Only In Production

I have the following query which works perfectly in my local environment. However when I deploy to production (Heroku) I get the error detailed below. Would love some insight.

$tracks = DB::table('tracks as t')
                ->select(DB::raw('AVG(tt.time_listened) as avg, tt.track_id, t.id, t.track, t.count, t.id'))
                ->where([
                    ['t.user_id', $user_id],
                    ['tt.user_id', $user_id],
                ])
                ->Join('track_times as tt', 'tt.track_id', '=', 't.id')
                ->groupBy('tt.track_id')
                ->paginate(15);
Syntax error or access violation: 1055 'pfoe42ui3fzinf1p.t.id' isn't in GROUP BY (SQL: select AVG(tt.time_listened) as avg, tt.track_id, t.id, t.track, t.count, t.id from `tracks` as `t` inner join `track_times` as `tt` on `tt`.`track_id` = `t`.`id` where (`t`.`user_id` = 75 and `tt`.`user_id` = 75) group by `tt`.`track_id` limit 15 offset 0)
16 Nov
2 months ago

Mick79 started a new conversation Upload Multiple Files With FileStack

I am using Filestack to upload multiple audio files.

I need to get the Filestack token AND the original filename and pass them to my controller so I can save them to db.

after the uploads complete I get a JS array that has this info.

I don't know how to get this JS array into my form so that I can pass it. help.

console.log(result.filesUploaded)
Array (2)
0 {filename: "Haydn_Cello_Concerto_D-1.mp3", handle: "psakApfXTYeDZrGG0dFO", mimetype: "audio/mpeg", originalPath: "Haydn_Cello_Concerto_D-1.mp3", size: 2597564, …}
1 {filename: "SampleAudio_0.7mb.mp3", handle: "Lp3opNxTQny7KkPfmk97", mimetype: "audio/mpeg", originalPath: "SampleAudio_0.7mb.mp3", size: 725240, …}
13 Nov
2 months ago

Mick79 left a reply on Nova Support

@ejdelmonico handling it in the model is an interesting angle.

I wouldn’t even know where to start on that though... but it’s definitely something i’ll go and play with.

Any ideas yourself on how that might work?

Mick79 left a reply on Nova Support

@ejdelmonico hi, i did not buy the pro licence. I didn’t know this was required for support.

However upon sending my first email, I got a reply after about ten days from David Hemphill saying along the lines of “hi you don’t have the pro account, however, how can I help?” - which I thought was really nice.

However when I replied detailing my problem I got no reply. I waited another ten days or so then emailed again asking “hi, if I upgrade to the pro account, is this the kind of problem that I could receive help with?”

And again no reply. I’m not looking for someone to write my code for me here, i am just looking for someone to acknowledge my existence. I would / will happily upgrade but I won’t do so until someone at least replies to my basic queries about a non technical and very general product enquiry.

Mick79 left a reply on Nova Support

Hi @richard - I’ve posted in a few places already to no avail.

It’s to do with the “trend” metrics. I need to see a trend of “active users”. So for example I have an orders table and someone may appear in that table multiple times, but my business definition of “active” is someone who has ordered at least once in a given time period.

So if Mr X has ordered 4 times in a week Andy Mrs Y has ordered 3 times in a week then my “active user” count is 2.

The countByDays method which powers the “trend” metric in nova can’t return me a distinct count, which is (I believe) what I need.

I would just like to know if it’s possible. As if it is not then nova isn’t of much use to me.

12 Nov
2 months ago

Mick79 started a new conversation Nova Support

The email support for Nova is extremely poor. Is anyone else having trouble getting a reply?

03 Nov
2 months ago

Mick79 left a reply on Graham Campbell Markdown Issue

@Snapey FYI that simpleMDE thing works like a dream.

Mick79 left a reply on Graham Campbell Markdown Issue

@Snapey Yeah it was watching the Nova release that set me down this path. It gave me the impression a MD editor was baked into Laravel.

Thanks for that link, I'm checking it out now.

Mick79 left a reply on Graham Campbell Markdown Issue

Thanks a lot @Snapey I'll mark your answer as correct but I already switched to this package (seems equally reputable) https://github.com/andreasindal/laravel-markdown and it all works as intended right out of the box.

As an aside, is there any such thing that adds a markdown editor to a textarea input?

Thanks

Mick79 started a new conversation Graham Campbell Markdown Issue

I'm using this package which comes highly recommended: https://github.com/GrahamCampbell/Laravel-Markdown

In my view I am rendering it out as

@markdown
    {{$post->markdown}}
@endmarkdown

However not all if it is rendering. The italics are rendering correctly, my list is rendering correctly, however my H1 and my quotes are not. They are just showing up in the blade like

# Hello, This is the blog title

Any help more than welcome. Thanks.

02 Nov
2 months ago

Mick79 left a reply on Why No Good Blog / Cms Options

I think I'm going to roll my own. The real problem is image upload and storage. That's a PITA for me to do.

Other than that just a form that accepts title, subtitle and a textarea to paste in a markdown dump.

is @markdown and @endmarkdown valid blade syntax for dumping laravel out onto the screen.

01 Nov
2 months ago

Mick79 started a new conversation Why No Good Blog / Cams Options

I’ve been googling away for a few days and have been unable to find any really good blog \ cams options that I can bolt onto my existing laravel web app.

I was wondering if there was a reason for this. And by the way when I say “good” what I mean is like.... there are no clear winners. There is no “go to” solution the way there are for so many other laravel needs like permissions for example. All available solutions that I can find seem half baked.

Mick79 left a reply on Add Markdown Editor To Textarea

Thanks - is there not a safety concern in saving html to the database? That's why I was looking for a markdown editor.

31 Oct
2 months ago

Mick79 started a new conversation Add Markdown Editor To Textarea

Hello everyone,

I thought finding a package that turned textareas into a markdown editor would be easy... but it actually isn't.

Is there such a thing as a way to turn a bog standard textarea into a markdown editor?

Thanks

30 Oct
2 months ago

Mick79 left a reply on Can't Install Nova In Production (Heroku)

Thanks a lot @martinbean i’ll look into this for sure.

@okanlawonema please see the answer that I marked as correct. That is how I solved the problem.