Mick79

Mick79

Founder at SongBox

Member Since 2 Years Ago

Glasgow

Experience Points
13,530
Total
Experience

1,470 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
40
Lessons
Completed
Best Reply Awards
1
Best Reply
Awards
  • start your 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-in-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 Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • evangelist 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 3
13,530 XP
Oct
24
6 days ago
Activity icon

Replied to Download Audio File Directly From Link

Thanks but that was one of the first things I tried. That "download" attribute only works for files stored locally, sadly.

Activity icon

Replied to Download Audio File Directly From Link

Thanks for that, here is the new code:

class DownloadController extends Controller
{

    public function downloadTrack($token) {

        return response()->streamDownload(function () use ($token) {
            $track = Track::where('token',$token)->first(); // You should pass $token not $this->token
            $source = $track->tracksource;
            echo file_get_contents($source);
        }, 'nice-name.jpg');

    }
}

But I get the following error:

LogicException
The content cannot be set on a StreamedResponse instance.
Activity icon

Replied to Download Audio File Directly From Link

I’m super grateful for your response but I don’t know what you mean.

Activity icon

Started a new Conversation Download Audio File Directly From Link

I'm trying to add a download button that just downloads the file as opposed to opening it in another tab.

This is where I'm at

class DownloadController extends Controller
{

    public $token;

    public function downloadTrack($token) {

        return response()->streamDownload(function () {
            $track = Track::where('token',$this->token)->first();
            $source = $track->tracksource;
            echo file_get_contents($source);
        }, 'nice-name.jpg');

    }
}

and it's giving me this response

The content cannot be set on a StreamedResponse instance.

For info the file is on a CDN, so it's not local.

I've also tried this which also didn't work

class DownloadController extends Controller
{
    public function downloadTrack($token) {

        $track = Track::where('token',$token)->first();
        
        return Response::download($track->tracksource, 'download', ['location' => $track->tracksource]);
        
    }
}

Any help appreciated

Update

I've now tried this which is TRYING to work, but getting this

WHAT I TRIED (Disregard the client / policy stuff this is just security to get my file from the CDN)

class DownloadController extends Controller
{
    public function downloadTrack($token) {


        $client = SecurityPolicy::createPolicy();

        $policy = $client->policy;
        $signature = $client->signature;

        $track = Track::where('token',$token)->first();

        $filename = 'temp-image.jpg';
        $tempImage = tempnam(sys_get_temp_dir(), $filename);
        copy($track->tracksource."?policy=".$policy."&signature=".$signature, $tempImage);

        return response()->download($tempImage, $filename);
    }
}

WHAT I GOT

The content cannot be set on a BinaryFileResponse instance.

Update 2

Also now tried this

        $response = new BinaryFileResponse($track->tracksource."?policy=".$policy."&signature=".$signature);
        $response->setContentDisposition(ResponseHeaderBag::DISPOSITION_ATTACHMENT);

        return $response;

And I get

File does not exist
Oct
22
1 week ago
Activity icon

Replied to Manually Change Password - Am I Missing Something?

Uurgh...

I was using this package: https://github.com/renoki-co/laravel-eloquent-query-cache

and I was Caching the User model. I added it weeks ago as an experiment to help speed up my app and forgot about it. If I purge the cache at the top of that controller then it's all good, however what I did was just remove it from the User model altogether as I found the source of my app's slowness and it wasn't an issue that required a cache.

Hangs head in shame....

Activity icon

Replied to Manually Change Password - Am I Missing Something?

@snapey @jlrdw

I got there in the end and I'm too embarrassed to tell you what the actual problem was, but it was related to the session.

Can I just say that the two of you are my fucking heroes. Every time I have a problem... EVERY time, it's one of you who help me.

So just want to say thank you for that!

Moving on.....

Activity icon

Replied to Manually Change Password - Am I Missing Something?

@snapey @jlrdw

Ahhhh shit it is a session thing! Christ!

The password returned from

Auth::User()->password;

Or

Auth::User()->getAuthPassword();

is the password from the session and not from the database. This is why it works one time only as every time after that

Auth::User()->password;

is pulling the hash of the original password.

I want to punch myself hard in the face.

So here's the thing though, why isn't laravel killing the session when it logs me out?

Activity icon

Replied to Manually Change Password - Am I Missing Something?

I'm sorry man I really am but I'm certain that's what I'm doing.

$request->password is the password from the form and that's what I'm using in the Hash::check.

Activity icon

Replied to Manually Change Password - Am I Missing Something?

I think this must be the thing that I'm missing because I don't understand what you're saying here... or actually I do understand it but I believe I'm already doing it.

This is my code

   $currentPassword = Auth::User()->password;

        if (Hash::check($request->password, $currentPassword)) {
//

}

In the above, $currentPassword is the password from the database and $request->password is the password the user input in the form, so my code is doing this

   $currentPassword = Auth::User()->password;

        if (Hash::check([password they input], [password from database])) {

No?

Activity icon

Replied to Manually Change Password - Am I Missing Something?

Alright, mad shit happening. here's the steps

  1. I ran the tinker experiment like you said with a fresh user, it came back True

  2. I log in with that user and go through the password change process

  3. I am seemingly logged out and put to the login page

  4. I login successfully WITH THE NEW PASSWORD

  5. I go to password change process again and use THE NEW PASSWORD THAT I JUST LOGGED IN WITH

  6. It is false and I get the error message

  7. I try the tinker experiment again and this time it's False

  8. I log out and log back in again successfully WITH THE NEW PASSWORD

Mental.

It seems like the password change code above works one time. I can change password once, and use it to login successfully but that password is never again recognised in the password change code above.

Activity icon

Replied to Manually Change Password - Am I Missing Something?

Hmmm don't think so

$request->password is the current password the user had input

and

$currentPassword = Auth::User()->password; is the password from the DB.

Activity icon

Started a new Conversation Manually Change Password - Am I Missing Something?

Am I missing something here? I have what I would have thought to be a straight forward process.

On my user profile screen I have a form to let a user change their password.

blade

<div class="row mt-4">
                    <div class="col-12">
                        <div class="sbWidget">
                            <h4 class='sbWidgetTitle fw600 mb-2'>Password Reset</h4>
                            <p class="card-text"><i class="fas fa-info-circle"></i> You'll be logged out upon changing your password.</p>
                            <form class="mt-4" method="post" action="/passwordreset">
                                @csrf
                                <div class="input-group mb-3">
                                    <label>Current Password</label>
                                    <input type="password" name="password" class="sbInput" placeholder="Current Password" value="" id="">
                                </div>

                                <div class="input-group mb-3 mt-4">
                                    <label>New Password</label>
                                    <input type="text" name="newpassword" class="sbInput" placeholder="New Password" value="" id="">
                                </div>

                                <div class="input-group mb-3">

                                    <input type="submit" name="" class="btn-sbx btn-block" placeholder="" value="Save New Password" id="">
                                </div>
                            </form>

                        </div>
                    </div>
                </div>

controller

<?php

namespace App\Http\Controllers;

use App\User;
use Auth;
use Illuminate\Support\Facades\Hash;
use Illuminate\Http\Request;

class PasswordController extends Controller
{
    public function update(Request $request)
    {

        $currentPassword = Auth::User()->password;

        if (Hash::check($request->password, $currentPassword)) {

                $user = Auth::user();
                $user->password = Hash::make($request->newpassword);
                $user->save();

                return back()->with('success', 'Password successfully updated');
        }
        else {
            return back()->with('success', 'You entered your current password incorrectly');
        }


    }
}

it is always returning the ELSE section. Always.

Oct
21
1 week ago
Activity icon

Awarded Best Reply on Performance Issues Advice

@tray2 @neilstee

Hey guys thanks for the replies. I'm embarrassed to admit this but the problem was that my app and my db were hosted on different continents.

This morning I've migrated my production APP to US-east where the DB lives and now production is super quick.

How silly of me!!!!

To be fair though I'm quite surprised at just how much difference it made.

Activity icon

Replied to Performance Issues Advice

@tray2 @neilstee

Hey guys thanks for the replies. I'm embarrassed to admit this but the problem was that my app and my db were hosted on different continents.

This morning I've migrated my production APP to US-east where the DB lives and now production is super quick.

How silly of me!!!!

To be fair though I'm quite surprised at just how much difference it made.

Oct
20
1 week ago
Activity icon

Replied to Performance Issues Advice

Thanks for the reply. Both databases are in the cloud with JawsDB.

I've accessed each database directly within Sequel pro and run a few comparison queries:

I ran this query on both databases:

select * from users where email like "%gmail.com%";

On staging it took: 32ms On Production it took: 105ms

Tried multiple times and always staging is about 3x faster than production. And as I said these DBs are clones of each other.

I'm now thinking that my production db is in with a bad crowd; they are NOT single tenant databases so I believe that if another db on my shared instance is hammering it then I will feel the consequences of that. Would that be a correct assumption?

Activity icon

Started a new Conversation Performance Issues Advice

I've noticed my app recently being quite sluggish ( >2 seconds for page loads and Livewire requests to execute).

I figured this was either my database or my code so I set up a fresh environment on Heroku alongside a fresh virgin database.

So we have exact same code deployed to a new Heroku app (production is also on Heroku)

The new app is like lighting. So I'm ruling out my code being the problem. Must be database, right?

I made a copy of my production database and imported it to the staging database. So now I have SAME code and SAME database... The new app still is like lightning.

I can't figure out what to do next. The app on staging is SO fast and production is SO slow.

Check out this Loom video to see what I mean

https://www.loom.com/share/a98587e74be449b4b4f132b9d19ec1a2?from_recorder=1

Oct
14
2 weeks ago
Activity icon

Replied to Livewire Form With <select>

I resolved this.....

When I was passing data into the component I needed to explicitly set the track ID.

I had this:

@livewire('select-group', ['track' => $track])

And I believed because I was passing $track then I could get $track->id however this seems not to be the case.

I now pass in

@livewire('select-group', ['track' => $track, 'trackid' => $track->id])

and it all works.

Activity icon

Replied to Passing Hidden Field Value Back To Livewire Component Is Null

I am having this same problem today. If I remove wire:model then the value attribute is populated correctly. If I add wire:model the value attribute is empty. It's breaking my heart.

Activity icon

Replied to Livewire Form With <select>

This is killing my soul. Apologies I realise that I am killing your soul.

<div>
    <form wire:submit.prevent="selectNewGroup">
        @csrf
        <select wire:model="newgroup" name="nsg" id="" class="custom-select">
            @foreach($group as $g)
                <option value="{{$g->token}}">{{$g->name}}</option>
            @endforeach
        </select>
        {{$track->id}}
        <input wire:model="trackid" type="hidden" name="" class="" placeholder="" value="{{$track->id}}" id="">
        <div class="input-group mb-3">
            <button type="submit">Save</button>
        </div>
    </form>
</div>

In the above if I inspect element on the page the [value] of the select dropdown is populated correctly however the [value] of the hidden input is empty.

To add to the fun when I submit the form and DD out $this then both "newgroup" and "trackid" are NULL.

Also ifI just output {{$track->id}} onto the page as text it is there, correct. But that's exactly what I have in the value attribute and it's empty.

Activity icon

Replied to Livewire Form With <select>

Can you put a component inside a component?

Activity icon

Replied to Livewire Form With <select>

Thanks for this @snapey I'll try to digest it over my lunch break when I'm free from the ties of the day job.

Activity icon

Replied to Livewire Form With <select>

Yeah thanks I saw that first and tried to follow it through but it's not solving my problem.

I think the crucial difference is my loop.

There's a lot of stuff about having components in a loop, but haven't seen much about loops inside a component.

Oct
13
2 weeks ago
Activity icon

Started a new Conversation Livewire Form With <select>

I thought I had Livewire down (I love it btw!) but this form with a select is getting me down.

I'm looping through a bunch of music tracks and giving the user the option to allocate a TAG to each track.

Problem 1. When I change the dropdown on one form (for one track) the form on every track changes

Problem 2. When I submit the form the data I'm passing is NULL

Here is the blade

@foreach($tracks as $track)
                <div class="card p-2 mb-2">
                    <p class="card-text">{{$track->track}}</p>
                    <form id="{{$track->id}}" wire:submit.prevent="selectNewGroup" class="" method="" action="">
                        @csrf
                        <select wire:model="nsg" name="nsg" id="{{$track->id}}" class="custom-select">
                            @foreach($group as $g)
                                <option value="{{$g->token}}">{{$g->name}}</option>
                            @endforeach
                        </select>
                        <input wire:model="trackId" type="hidden" name="track_id" class="" placeholder=""
                               value="{{$track->id}}" id="">
                        <div class="input-group mb-3">
                            <button type="submit">Save</button>
                        </div>
                    </form>
                </div>
            @endforeach

and here is method


   public $nsg;
   public $trackId;

public function selectNewGroup()
    {
        $track = Track::query()->where('id', $this->trackId)->first();
        $track->group_token = $this->nsg;
        $track->save();
    }

The error says $this-> track_id and $this->nsg are null.

Oct
11
2 weeks ago
Activity icon

Replied to 404 Errors For Everything In My Public/js Directory

I downloaded the repo as a zip from GitHub (https://github.com/yairEO/tagify) because I couldn't get it to work using the NPM install route.

I dragged all the .js files into my .js directory and just referenced them all locally hopping that would work. That's when the 404 stuff started happening.

I'm so annoyed. I've wasted the whole of this evening on this. I should've dropped it and moved on to other PHP / Laravel tasks hours ago. God knows my backlog is big enough.

Activity icon

Replied to 404 Errors For Everything In My Public/js Directory

Yeah man I'm sorry. I don't know enough about this side of things to even be asking questions.

Apologies.

Activity icon

Replied to 404 Errors For Everything In My Public/js Directory

OK sorry you guys are helping me make sense of this. Here are the steps.

I have a file being called via a

<script src="">

Within that file are these lines:

import dropdownMethods from '/parts/dropdown.js'
import DEFAULTS from '/parts/defaults.js'
import templates from '/parts/templates.js'
import events, { triggerChangeEvent } from '/parts/events.js'

However these are being thrown as 404 errors in the console as they are being looked for WITHOUT the .js

If you add the .js to the urls in the console error they work.

Activity icon

Replied to 404 Errors For Everything In My Public/js Directory

Oh if I add .js I can load them in the browser

https://gf2020.test/js/parts/dropdown.js

odd.... but if I add .js to the places they are being called it still shows without the .js in the console error.

Activity icon

Replied to 404 Errors For Everything In My Public/js Directory

Yeah I can't load them in the browser address bar. Console error looks like this:

[Error] Failed to load resource: the server responded with a status of 404 () (helpers, line 0) https://gf2020.test/js/parts/dropdown

Activity icon

Replied to 404 Errors For Everything In My Public/js Directory

Do you mean having the correct capitals etc?

They are being referenced from a

is there a way I can use {{asset()}} inside a JS file?

I think it's something to do with laravel mix. I've no idea how that works.

Activity icon

Replied to Public Folder Does Not Allow Access To Its Content

This problem is still killing me.

Activity icon

Started a new Conversation 404 Errors For Everything In My Public/js Directory

I've always had 404 errors for popper.js in every laravel app I've ever created. It's annoying but doesn't bother me so I ignore it.

However tonight I had to add a punch of js files to my JS directory and I'm now getting 7 404 errors.

I need to be able to access these files but just nothing.

I've rerun npm run dev a million times.

I'm obviously missing something fundamental. Can anyone help?

Sep
29
1 month ago
Activity icon

Replied to Fresh Laravel 8 Jet Stream Install - Problem

Yeah this is what I've done.

I fear change.

Activity icon

Started a new Conversation Fresh Laravel 8 Jet Stream Install - Problem

I've just created a fresh new app with jet stream on the live wire stack.

In layouts / app there is no longer a content section. Instead there is this

{{ $slot }}

What's going on?

Sep
28
1 month ago
Activity icon

Replied to Laravel 8 ' The "--jet" Option Does Not Exist. '

I had the same problem. Thanks.

Sep
16
1 month ago
Activity icon

Replied to "Too Many Connections" Error

It doesn't seem a lot. The DB I'm on has a "max connections" of 15.

This really isn't my area of expertise :-(

Activity icon

Started a new Conversation "Too Many Connections" Error

I launched a new app on Monday and it's surprisingly picked up a bit of traction. Completely unexpected as it was a weekend build.

Anyway I keep getting the above error (too many connections). I'm wondering if this is the issue. I had a query on the homepage that looked like this:

$rand = Product::query()->inRandomOrder()->limit(1)->first();

and that was it.

I have just now (minutes ago) changed it to:

$rand = Product::query()->inRandomOrder()->limit(1)->first();
$rand->save();

as I am completely guessing that by not having the save() method then the connection was not being closed.

Can someone verify this please as it is an absolute guess 🤓

Sep
14
1 month ago
Activity icon

Replied to Laravel 8 Password Reset

But that's default laravel stuff. I haven't touched that.

Activity icon

Replied to Laravel 8 Password Reset

I haven't changed anything but now the error is this:

https://flareapp.io/share/87nN907w#F56

Activity icon

Replied to Laravel 8 Password Reset

Ah I see. I should have realised this as I'm not actually using a mail server in the traditional sense. I send all my other transactional emails using the SendGrid API.

Hmmm..... How do I hook up send grid API to my default laravel shit.

Here we go.

Activity icon

Started a new Conversation Laravel 8 Password Reset

Hey all 👋 Fresh install of L8

Getting this when I try to reset password:

Expected response code 250 but got code "550", with message "550 5.7.1 Relaying denied"

Anyone encounter this?

to be clear I get this after I put in my email address and hit the confirm button.

Sep
13
1 month ago
Activity icon

Started a new Conversation Someone Got Me With A Script Injection

I'm putting together something on Laravel 8 and a user submitted a comment via a standard textarea and included a alert('awesome') and that alert fired on every page load.

I thought Laravel took care of that? What have I missed lol?

I am outputting the contents of the text field using

{!!  nl2br($comment->comment) !!}

Please help

Aug
15
2 months ago
Activity icon

Replied to Insert Into... Query Problem

Oh my god!!

you're right. Jesus Jones!!

It was in fact an update I was wanting to do. Honestly...... 🤪

Activity icon

Replied to Insert Into... Query Problem

I ended up just doing it in PHP:

// Get the values from table one that I need

  $activity_update = DB::table('activity_updates')
            ->select(DB::raw('songbox_id, count(songbox_id) as count'))
            ->where('status', '=', 1)
            ->groupBy('songbox_id')
            ->get();

// Loop through the values, check if the row exists then update it.
        foreach ($activity_update as $update) {

            $check = Songbox::query()->where('token', '=', $update->songbox_id)->exists();

            if ($check) {
                $s = Songbox::query()->where('token', '=', $update->songbox_id)->first();
                $s->plays = $update->count;
                $s->save();
            }

        }
Activity icon

Replied to Insert Into... Query Problem

User_id is already set on the other table though. I’m only trying to update the one column plays - which is a new column.

Activity icon

Replied to Insert Into... Query Problem

Hey thanks for the super quick reply.

Yes it does. They both have a user_id column.

Activity icon

Started a new Conversation Insert Into... Query Problem

Sorry but this is a general MySQL question and not strictly Laravel related. But I wouldn't ask anywhere else as this community is the best.

I'm trying to INSERT INTO by using this query

INSERT INTO songboxes (plays)
select count(`songbox_id`)
from activity_updates as au
join songboxes on au.songbox_id = songboxes.token
where `status` = 1 
Group by songbox_id

I am getting the error

Field 'user_id' doesn't have a default value

But I'm not trying to do anything with the user ID, as you can see from the query.

I think the problem may lie in that not every row in the destination table needs updated. However... maybe that's not the problem at all. I really am quite stuck.

Anyone have any suggestions?

Aug
06
2 months ago
Activity icon

Awarded Best Reply on Group By Month And Order By Something Else?

@rodrigo.pedra @jlrdw @marianomoreyra

I solved this really simply within the blade.

I changed

@foreach($groupedposts as $post)

to

@foreach($groupedposts->sortByDesc('post_likes') as $post)

And it's perfect.

Aug
05
2 months ago
Activity icon

Replied to Group By Month And Order By Something Else?

Yeah I did but still couldn't get it to work. I appreciate the help but I solved this as detailed above.

Activity icon

Replied to Group By Month And Order By Something Else?

@rodrigo.pedra @jlrdw @marianomoreyra

I solved this really simply within the blade.

I changed

@foreach($groupedposts as $post)

to

@foreach($groupedposts->sortByDesc('post_likes') as $post)

And it's perfect.