Mick79

Mick79

Member Since 1 Year Ago

Glasgow

Founder at SongBox

Experience Points 9,950
Experience Level 2

50 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 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.

20 Mar
2 days ago

Mick79 started a new conversation Get "country" With Google Places API

I'm trying to consistently get "country" from the google places API, however by Google's own admission this isn't the easiest thing to do as their response array varies in consistency depending on the input.

the response looks something like this

{
   "results" : [
      {
         "address_components" : [
            {
               "long_name" : "1600",
               "short_name" : "1600",
               "types" : [ "street_number" ]
            },
            {
               "long_name" : "Amphitheatre Pkwy",
               "short_name" : "Amphitheatre Pkwy",
               "types" : [ "route" ]
            },
            {
               "long_name" : "Mountain View",
               "short_name" : "Mountain View",
               "types" : [ "locality", "political" ]
            },
            {
               "long_name" : "Santa Clara County",
               "short_name" : "Santa Clara County",
               "types" : [ "administrative_area_level_2", "political" ]
            },
            {
               "long_name" : "California",
               "short_name" : "CA",
               "types" : [ "administrative_area_level_1", "political" ]
            },
            {
               "long_name" : "United States",
               "short_name" : "US",
               "types" : [ "country", "political" ]
            },
            {
               "long_name" : "94043",
               "short_name" : "94043",
               "types" : [ "postal_code" ]
            }
         ],
         "formatted_address" : "1600 Amphitheatre Parkway, Mountain View, CA 94043, USA",
         "geometry" : {
            "location" : {
               "lat" : 37.4224764,
               "lng" : -122.0842499
            },
            "location_type" : "ROOFTOP",
            "viewport" : {
               "northeast" : {
                  "lat" : 37.4238253802915,
                  "lng" : -122.0829009197085
               },
               "southwest" : {
                  "lat" : 37.4211274197085,
                  "lng" : -122.0855988802915
               }
            }
         },
         "place_id" : "ChIJ2eUgeAK6j4ARbn5u_wAGqWA",
         "types" : [ "street_address" ]
      }
   ],
   "status" : "OK"
}

But the problem is that "address_components" varies a lot from address to address, even locally when you enter towns close to each other. Is there any way anyone can suggest to get "country" accurately every time?

11 Mar
1 week ago

Mick79 left a reply on Show Users Not In Table

Thank you @cronix and @jirdw

Here is the loop inside the blade:

 @foreach ($list as $item)
        <tr>
            <td>{{$item->fname}} {{$item->sname}}</td>
            <td>{{$item->email}}</td>
            <td>{{$item->mobile}}</td>
            <td>
                @foreach ($item->meals as $element)
                     {{$element->meal_name}}<br>
                @endforeach
            </td>
        </tr>
    @endforeach

Mick79 left a reply on Show Users Not In Table

For anyone interested I solved this by setting up a hasManyThrough relationship from "users" to "item_sold"

public function shiftmeals()
    {
        return $this->hasManyThrough(
            'App\ShiftMeal', //orderitem
            'App\Meal', //order
            'user_id', // Foreign key on Meal table... foreign from users to Meal
            'meal_id', // Foreign key on ShiftMeal table... foreighn from ShiftMeal to Meal
            'id', // Local key on user table... local for users to Meal
            'id'); // Local key on Meal table... local for Meal to ShiftMeal
    }

Also a hasMany relation from users to Meals

public function meals()
    {
        return $this->hasMany('App\Meal', 'user_id', 'id');
    }

and then a very simple eloquent query did the trick

$list = User::query()
            ->whereHas('meals')
            ->whereDoesntHave('shiftmeals')
            ->get();

Mick79 left a reply on Show Users Not In Table

I'm thinking I need to do a

hasManyThrough

and query on Users

Mick79 left a reply on Show Users Not In Table

@cronix - ok I've decided to go with your suggestion as it's cleaner in my mind. The query now looks like this

$list = Meal::query()
            ->whereDoesntHave('shiftmeals')
            ->get();

However this is returning users who may have three of four items listed and sold 2 and not sold 2.

I need it to only return users who have sold nothing at all. It's bursting my head.

so... for example this is returning 2 instances of "John" if John has 2 items that haven't sold, even if he has 3 items that did.

Mick79 left a reply on Show Users Not In Table

@jirdw How do you query for not sold? Like... how do you query for something that isn't there?

I have this but it's definitely not right

$list = User::query()
            ->select('fname as fname','sname as sname','mobile as mobile', 'email as email', 'users.id as id', 'um.id as meal_id')->distinct()
            ->leftJoin('user_meals as um', 'um.id', '=', 'users.id')
            ->leftJoin('shift_meals as sm', 'sm.meal_id', '=', 'um.id')
            ->where('users.membertype','=','cook')
            ->whereNull('sm.meal_id')
            ->get();

Mick79 left a reply on Show Users Not In Table

@NIPUN - I stated what I want to know in my post

I need to provide list of users who have items listed but never sold any. Tables are connected like this

Mick79 started a new conversation Show Users Not In Table

I have 3 tables

users
items
items_sold

I need to provide list of users who have items listed but never sold any. Tables are connected like this

users

id | name
1 | Steve
2 | John
Items

id | item_name | user_id
1 | Toothpicks | 1
2| Anvils | 2
items_sold
id |sold_at| item_id
1 | [date] | 2

With the above as an example I would like to return this:

Steve

(because he has an item listed - toothpicks - but has never sold any)

Any help appreciated I'm really struggling.

04 Mar
2 weeks ago

Mick79 left a reply on Distinct Count In Eloquent

I'm pretty astonished and pleased that I might have figured out something that might help you.

Mick79 left a reply on Distinct Count In Eloquent

I actually got there in the end. Thanks for your help:

Transaction::query()
                ->select(DB::raw('DISTINCT(count(cook_id)) AS orders,cook_id as cook,u.email as email,u.name as name'))
                ->leftJoin('users as u', 'u.id', '=', 'cook_id')
                ->where([
                    ['transactions.created_at', '>=', $fromdate],
                    ['transactions.created_at', '<=', $todate],
                ])
                ->groupBy('cook_id')
                ->orderBy('orders', 'DESC')
                ->paginate(10);

Mick79 left a reply on Distinct Count In Eloquent

Ok thanks a lot for this.

Mick79 left a reply on Distinct Count In Eloquent

Aye... I think I'm just going to limit to 30 and forget about it. Kinda annoying that I can't achieve what I want to do easily. It can't be that uncommon of a query.

Mick79 left a reply on Distinct Count In Eloquent

Ah ok... I know Eloquent. Is there not the similar problem selecting distinct count with normal Eloquent?

Mick79 left a reply on Distinct Count In Eloquent

@JLRDW - I'm sorry but I don't know what that means.

Mick79 left a reply on Distinct Count In Eloquent

Hmm that's interesting but it's not working. I should be getting three rows returned but implementing that solution just returns an integer "3"

Mick79 started a new conversation Distinct Count In Eloquent

I have a query that works, but I really want to translate it into something Eloquent. Here is the working query:

SELECT DISTINCT(count(cook_id)) AS orders, u.name as name, u.email as email, cook_id as cook FROM transactions AS a
left join users as u on u.id = a.cook_id
WHERE a.created_at >= "'.$fromdate.'"
AND a.created_at <= "'.$todate.'"
GROUP BY cook_id
ORDER BY orders DESC
LIMIT 10

Here is the best I can do eloquent style, but I can't figure out how to translate the distinct count:

DB::table('transactions as a')
                ->select('cook_id AS orders', 'u.name as name', 'u.email as email', 'cook_id as cook')
                ->leftJoin('users as u', 'u.id', '=', 'a.cook_id')
                ->where([
                    ['a.created_at', '>=', $fromdate],
                    ['a.created_at', '<=', $todate],
                ])
                ->groupBy('a.cook_id')
                ->orderBy('orders', 'DESC')
                ->paginate(10);

Any and all help gratefully received.

17 Feb
1 month ago

Mick79 left a reply on Placing Markers With Google Maps JavaScript API

Sorry I solved this one myself (I have a habit of doing that immediately after I've asked a question on here):

I needed to pass headers in the controller. Solved as such:

return response()->view('mapdata')->header('Content-Type', 'text/xml');

Mick79 started a new conversation Placing Markers With Google Maps JavaScript API

Right off the bat I apologise - I realise this is more of a JS question but the Laravel aspect of it is tripping me up:

This is the example code google gives and it works:

 <script>
            var customLabel = {
                restaurant: {
                    label: 'R'
                },
                bar: {
                    label: 'B'
                }
            };

            function initMap() {
                var map = new google.maps.Map(document.getElementById('map'), {
                    center: new google.maps.LatLng(-33.863276, 151.207977),
                    zoom: 12
                });
                var infoWindow = new google.maps.InfoWindow;

                // Change this depending on the name of your PHP or XML file
                //downloadUrl('/mapdata', function (data) {
                    downloadUrl('https://storage.googleapis.com/mapsdevsite/json/mapmarkers2.xml', function (data) {
                    var xml = data.responseXML;
                    var markers = xml.documentElement.getElementsByTagName('marker');
                    Array.prototype.forEach.call(markers, function (markerElem) {
                        var id = markerElem.getAttribute('id');
                        var name = markerElem.getAttribute('name');
                        var address = markerElem.getAttribute('address');
                        var type = markerElem.getAttribute('type');
                        var point = new google.maps.LatLng(
                            parseFloat(markerElem.getAttribute('lat')),
                            parseFloat(markerElem.getAttribute('lng')));

                        var infowincontent = document.createElement('div');
                        var strong = document.createElement('strong');
                        strong.textContent = name
                        infowincontent.appendChild(strong);
                        infowincontent.appendChild(document.createElement('br'));

                        var text = document.createElement('text');
                        text.textContent = address
                        infowincontent.appendChild(text);
                        var icon = customLabel[type] || {};
                        var marker = new google.maps.Marker({
                            map: map,
                            position: point,
                            label: icon.label
                        });
                        marker.addListener('click', function () {
                            infoWindow.setContent(infowincontent);
                            infoWindow.open(map, marker);
                        });
                    });
                });
            }


            function downloadUrl(url, callback) {
                var request = window.ActiveXObject ?
                    new ActiveXObject('Microsoft.XMLHTTP') :
                    new XMLHttpRequest;

                request.onreadystatechange = function () {
                    if (request.readyState == 4) {
                        request.onreadystatechange = doNothing;
                        callback(request, request.status);
                    }
                };

                request.open('GET', url, true);
                request.send(null);
            }

            function doNothing() {
            }
        </script>

I have replaced this line:

downloadUrl('https://storage.googleapis.com/mapsdevsite/json/mapmarkers2.xml', function (data) {

with this:

downloadUrl('/mapdata', function (data) {

and here is how all that plays out:

Route:

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

Controller:

<?php

    namespace App\Http\Controllers;

    use Illuminate\Http\Request;

    class MapController extends Controller {

        public function show()
        {

            return view('mapdata');
        }
        
    }

View:

<markers>
    <style class="darkreader darkreader--safari-fallback">
        html, html * { background-color: #17181c !important; border-color: #595959 !important; color: #e8e7e3 !important; }
    </style>
    <marker id="1" name="Billy Kwong" address="1/28 Macleay Street, Elizabeth Bay, NSW" lat="-33.869843" lng="-151.225769" type="restaurant"/>
    <marker id="2" name="Love.Fish" address="580 Darling Street, Rozelle, NSW" lat="-33.861034" lng="151.171936" type="restaurant"/>
    <marker id="3" name="Young Henrys" address="76 Wilford Street, Newtown, NSW" lat="-33.898113" lng="151.174469" type="bar"/>
    <marker id="4" name="Hunter Gatherer" address="Greenwood Plaza, 36 Blue St, North Sydney NSW" lat="-33.840282" lng="151.207474" type="bar"/>
    <marker id="5" name="The Potting Shed" address="7A, 2 Huntley Street, Alexandria, NSW" lat="-33.910751" lng="151.194168" type="bar"/>
    <marker id="6" name="Nomad" address="16 Foster Street, Surry Hills, NSW" lat="-33.879917" lng="151.210449" type="bar"/>
    <marker id="7" name="Three Blue Ducks" address="43 Macpherson Street, Bronte, NSW" lat="-33.906357" lng="151.263763" type="restaurant"/>
    <marker id="8" name="Single Origin Roasters" address="60-64 Reservoir Street, Surry Hills, NSW" lat="-33.881123" lng="151.209656" type="restaurant"/>
    <marker id="9" name="Red Lantern" address="60 Riley Street, Darlinghurst, NSW" lat="-33.874737" lng="151.215530" type="restaurant"/>
</markers>

But it's not working. Either the XML is wrong in the blade template OR the javascript can't access that route in the same way it accesses a URL.

Help :-)

13 Feb
1 month ago

Mick79 left a reply on Download Link To A File Stored In S3

Sorted it:

return redirect('https://s3.eu-west-2.amazonaws.com/xxxx/yyyyy/Welcome+Booklet.pdf');

Mick79 started a new conversation Download Link To A File Stored In S3

I'd like to create a friendly link to a file I have stored in s3.

I'd like something like myapp.com/the-asset

I've tried this but it didn't work:

return response()->download('https://s3.eu-west-2.amazonaws.com/xxxx/yyyyy/Welcome+Booklet.pdf');

any ideas?

12 Feb
1 month ago

Mick79 left a reply on Laravel Telescope Styling In Production / Override View

That asset_url thing fixed it. Thanks so much.

Mick79 left a reply on Laravel Telescope Styling In Production / Override View

@BOBBYBOUWMANN - Hi @bobbybouwmann - yeah the url is fine apart from being http://

I'll try the asset_url - thanks.

11 Feb
1 month ago

Mick79 started a new conversation Laravel Telescope Styling In Production

I've deployed Telescope to production but the css isn't working. I need to edit the view to make sure it uses secure_asset as opposed to just asset.

However the view is in vendor/telescope which doesn't get committed or deployed.

Can I override the view somehow, or is there another solution?

Mick79 left a reply on 404 Errors Logging Twice

@snapey how do you just know this shit?

Thanks

Mick79 started a new conversation 404 Errors Logging Twice

Here is the code I'm using to Log 404 errors

public function report(Exception $exception)
        {
            if ($exception instanceof \Symfony\Component\HttpKernel\Exception\NotFoundHttpException)
                Log::error( '404 error: ' . \Request::fullUrl());
        }

For a single 404 error it is outputting two logs:

Feb 12 01:06:30 UNKNOWN php: [2019-02-12 01:06:30] local.ERROR: 404 error: https://xxx.dev/dsdsassssssggggg   
Feb 12 01:06:31 UNKNOWN php: [2019-02-12 01:06:30] local.ERROR: 404 error: https://xxx.dev/svg/404.svg

it logs the error and then ALWAYS the /svg/404.svg line

How can I make it log the error and not the SVG url?

10 Feb
1 month ago

Mick79 left a reply on Can't Login After Password Reset - And Reset Token Not Being Removed From Table

For anyone interested I fixed this by redoing all the routes manually.

I don't know what the problem was but just by going step by step and adding manual routes to the WEB file and then making sure this routes were manually in there too on the forms etc. It now works.

This may be to do with having upgraded from 5.5 to 5.7, maybe? I dunno. But it was a pain in the hole for me all day today.

Mick79 left a reply on Can't Login After Password Reset - And Reset Token Not Being Removed From Table

Another thing that's odd - I went into another, newer laravel app that I have and the same blade file in that app points at

                    <form method="POST" action="{{ route('password.update') }}">

very odd. I'm at a loss.

Mick79 left a reply on Can't Login After Password Reset - And Reset Token Not Being Removed From Table

This is seriously doing my head in. Locally it works fine.

Something else interesting - in local if I create a new password like "xxx" I get a validation error saying "password must be at least 6 characters" however in production if I do that it does exactly as described in my previous post. So no validation is happening.

Mick79 left a reply on Can't Login After Password Reset - And Reset Token Not Being Removed From Table

Hi @snapey - there are no validation errors. The form submits just fine with the email address and then new password / confirm new password.

so the form is here:

/password/reset/token

I get to this via the link in the email

I fill out the form and I'm output here:

/password/reset?token=68a85504f0929bc2705fd4be6e127ed5fe34e007f7d2484b3413cf34e297ae8f

Ah... I may have just spotted something. is ?token= the same as /token - should they be the same?

and the actual form itself is as such:

 <form method="POST" action="{{ route('password.request', ['token' => $token]) }}">
                        @csrf

                        <input type="hidden" name="token" value="{{ $token }}">

                        <div class="form-group row">
                            <label for="email" class="col-md-4 col-form-label text-md-right">{{ __('E-Mail Address') }}</label>

                            <div class="col-md-6">
                                <input id="email" type="email" class="form-control{{ $errors->has('email') ? ' is-invalid' : '' }}" name="email" value="{{ $email ?? old('email') }}" required autofocus>

                                @if ($errors->has('email'))
                                    <span class="invalid-feedback">
                                        <strong>{{ $errors->first('email') }}</strong>
                                    </span>
                                @endif
                            </div>
                        </div>

                        <div class="form-group row">
                            <label for="password" class="col-md-4 col-form-label text-md-right">{{ __('Password') }}</label>

                            <div class="col-md-6">
                                <input id="password" type="password" class="form-control{{ $errors->has('password') ? ' is-invalid' : '' }}" name="password" required>

                                @if ($errors->has('password'))
                                    <span class="invalid-feedback">
                                        <strong>{{ $errors->first('password') }}</strong>
                                    </span>
                                @endif
                            </div>
                        </div>

                        <div class="form-group row">
                            <label for="password-confirm" class="col-md-4 col-form-label text-md-right">{{ __('Confirm Password') }}</label>

                            <div class="col-md-6">
                                <input id="password-confirm" type="password" class="form-control" name="password_confirmation" required>
                            </div>
                        </div>

                        <div class="form-group row mb-0">
                            <div class="col-md-6 offset-md-4">
                                <button type="submit" class="btn btn-primary">
                                    {{ __('Reset Password') }}
                                </button>
                            </div>
                        </div>
                    </form>

Mick79 started a new conversation Password Reset Email Request Form Not Working In Production

I have an odd problem where password reset works fine in dev, but in production (heroku) when I enter my email address and submit the form I get a bad method error.

I've been trying to debug by fucking about with router.php (I read somewhere that nginx doesn't play well with routes that contain /email) but no joy so far.

Any ideas?

03 Feb
1 month ago

Mick79 started a new conversation Is It Necessary To Always Type "php Artisan"? Why Not Just "artisan"

I know this will probably be to do with putting something accessible globally - but I don't know what that is. Is it possible?

26 Jan
1 month ago

Mick79 left a reply on Buying New MacBook Pro - Options?

That’s great insight @cronix and it’s not info that I’m ignorant to.

In my dayjob I have a 15” MBP with touchpad. Been using it for two years and I hate it. I also hate typing on the paper thin keyboard. Your point about robots is interesting because yeah they can tell you how many strikes a keyboard can take but they can’t tell you how it feels. I hate to say it but I just feel like Jobs would have been all over that.

In my other life (founder / freelancer) I use my 15” 2014 fully specced out MPB which is SO much better.

I’m thinking of “upgrading” to a new MPB because I really want a 13” model now, for various reasons. One of which is the smaller screen. I do a lot if my coding at home at night and the light output from my Mac is annoying to my wife and daughter, and the machine is also pretty heavy.

So I want a 13” for reduced weight and reduced light output (front and back - the apple logo doesn’t light up on the new ones) but I’m really struggling with the compromises that means making - shit keyboard, touchbar etc.

First world problems yes, but problems all the same.

25 Jan
1 month ago

Mick79 left a reply on @include Creates A Gap Like A 10px Margin

Can you please post your markup?

Mick79 left a reply on Buying New MacBook Pro - Options?

Thanks it does help. You don't find you're losing anything with the 7thGen I5 VS the 8thGen I7?

Also - I have a 15" MBP with Touch Bar at work and I just hate it.

Mick79 started a new conversation Buying New MacBook Pro - Options?

Hi sorry for the general nature of this but I'm genuinely interested in folks opinions.

I'm annoyed that Apple are only offering their top spec machines in the Touch Bar model. I MUCH prefer physical function keys, but I'm struggling to bring myself to buy a new machine that ISN'T top of the range.

I develop almost exclusively with Laravel, using Valet, on phpStorm. I infrequently develop apps on Xcode.

These days my video editing requirements are close to zero (probably actually zero).

Other than that I use photoshop and Lightroom heavily.

Do you think 16GB is enough? I want a 13" model this time and they only go as high as 16GB. The other factor is do I get the 8th Gen I7 processor (which means the Touch Bar) or get physical function keys but with the 7th Gen Processor.

Help.

23 Jan
1 month ago

Mick79 left a reply on Installing Laravel On A Freelancers Machine

Thanks a lot @jkenyon and @burlresearch

That helps a lot.

This is very annoying as I’ve setup Laravel and valet loads of times previously with no issue. But it’s like this dudes machine is haunted.

I’m now getting a 502 bad gateway nginx error.

22 Jan
2 months ago

Mick79 left a reply on Installing Laravel On A Freelancers Machine

ok.... now this is where you want to walk way from me....

I've opened up php.ini but can't see any reference to it. Also when I type "which php" I get this:

/usr/bin/php

but when I go to /usr/bin there is no PHP folder?

Mick79 left a reply on Installing Laravel On A Freelancers Machine

Thanks @ty

here's the thing. If I type php -v I get this:

PHP 7.1.16 (cli) (built: Apr  1 2018 14:10:37) ( NTS )
Copyright (c) 1997-2018 The PHP Group
Zend Engine v3.1.0, Copyright (c) 1998-2018 Zend Technologies

BUT I have installed, deleted and re-installed php7.2 and php7.3 multiple times via brew - but I can't really get it to take.

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
2 months 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 months 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 months 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.