Building APIs at Automica HQ

Member Since 3 Years Ago

Bristol, UK

Experience Points
327,420
Total
Experience

0 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
1009
Lessons
Completed
Best Reply Awards
313
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.

  • Community Pillar

    Earned once your experience points ranks in the top 10 of all Laracasts users.

Level 50
327,420 XP
May
11
9 hours ago
Activity icon

Replied to Laravel BelongsToMany With Multiple Tables

@sonle Can I be bold and ask why you aren't following convention for table naming?

what it looks like you have is

  • creatives
  • titles
  • images

and a relationship between Creative and Set models defined as creative_set

compound table names such as title_set should define the relationship between Title and Set models.

If you follow conventions you'll be able to use build in laravel features and will make defining ORM much simpler.

Activity icon

Replied to I Want Each Category With Products

You’ll also want to order by count

Activity icon

Replied to I Want Each Category With Products

You can use DB:Raw if you want to use the above sql. If you convert it to eloquent it’ll be converted back to sql before execution so there’s no functional benefit.

Activity icon

Replied to Not Able To Go Back To Login Page

Your back button doesn’t go back, it just hits a logout route. If that is on the page they get sent to if they can’t login then logging out won’t do anything either.

If you are checking an additional column on login, you should extend the login method and do the check there.

Activity icon

Replied to The Problem Of Retrieving And Sending Data

Can you add your full Vue component so I can see what you are doing?

Activity icon

Replied to The Problem Of Retrieving And Sending Data

It’s a little unclear how you are getting your data into your Vue component. Where are you calling your get() method?

Also can you explain why you are doing

<a v-bind:href="'api/post/'+ user.name" class="link"><i class="icon-like"></i> <font class="font-medium">{{ user.votes }}</font></a>

You’ve bound a route which is defined as POST to an anchor which will trigger a GET (which won’t work).

If the intention is to hit you post method, then you should replace the href with an @onclick event, and trigger the post() method.

Personally I would switch to using a button instead of anchor as you won’t then need to add the preventDefault.

Also you don’t need to add an argument to your post method as you can pick up username from data user.name

May
10
1 day ago
Activity icon

Replied to I Want Each Category With Products

@tinaye how are you deciding which are the top three categories?

if you had a collection of three categories in your blade your could do:

@foreach($categories as $category)

<h2>{{$category->title}}</h2>

@foreach($category->products as $product)

// output product

@endforeach

@endforeach
Activity icon

Replied to Laravel 8 Gloudemans Shopping Cart Quantity Not Adding

@msaad you cant really expect a fast reply if you post a topic over the weekend, especially when you are posting about a package rather than code directly within the Laravel codebase.

Regular contributors are less likely to reply to posters if they create duplicate threads.

Activity icon

Commented on Leverage Algolia Places

you can simplify your $location if you use null coalescing operator.

$location = request()->location ?? 'Toronto/Canada';
Activity icon

Commented on Fetch Weather Data With The OpenWeather API

also, if you want to use a package rather than just copying request from API docs, checkout https://github.com/dnsimmons/openweather

Activity icon

Commented on Fetch Weather Data With The OpenWeather API

I started looking at openweather api and found it quite limiting with regards to what data it returned.

I have recently switched to tomorrow.io which has far more options on the free package. You are limited to only 25 requests an hour which gets gobbled up rather quickly when developing so good to wrap some caching around the call so you dont hit the live service every request.

The first paid tier for tomorrow.io is only $27 per month and offers way more requests per hour/ day so will be the one I use when I send my app to production.

Activity icon

Replied to Renaming Uploaded File Before Download

@maltekiefer please start a new thread for your question rather than reopening an old, answered one.

Activity icon

Replied to Laravel 8 Project Hosting 403 Error

have you cleared all the caches on your remote server after uploading the site?

php artisan optimize:clear

should empty all caches.

you should also ensure you have correct file permissions for folders and files.

Good practice is to set all your directories to 755 and all of your files to 644… SET file permissions using the following command:

sudo find /path/to/your/laravel-directory -type f -exec chmod 644 {} \;

SET directory permissions:

sudo find /path/to/your/laravel-directory -type d -exec chmod 755 {} \;

Activity icon

Replied to Not Able To Go Back To Login Page

You should only allow the user access to a page with a log out link if they are logged in.

For logout, the convention is to use JavaScript to submit a hidden form with post to your logout method.

If you’ve logged out, where would your ‘back’ take you back to?

Activity icon

Replied to Reverse Of Pluck()

I would add a type hint of array to your columns argument to ensure you protect against passing in a string by mistake.

You should also add a return type of array too.

Activity icon

Replied to Reverse Of Pluck()

Can you post your long and ugly way of doing it so I can see what your trying to do?

May
09
2 days ago
Activity icon

Replied to Comparing Dates In The Same Table

@tomasnorre Answering the question aside, I find it more useful to lift the code from an external source and quote that in an answer on laracasts,

This allows any other posters to see exact bit of code you are referencing - and (more importantly) puts that code into the search index which will help anyone else who has this issue.

Btw the answer looks pretty sound. I can’t help think that there’s already a built in method to check for overlapping data. @michaloravec may be able to suggest something here.

Activity icon

Replied to Laravel Sail For Older Laravel Versions

@avrahamm an equivalent way to get sail like functionality for Laravel 7 would to use @sinnbeck's package https://github.com/sinnbeck/laravel-served

Activity icon

Replied to Attempt To Read Property "title" On Bool

@michaloravec @ajvanho should really be looking at returning a 204 (no content) response when updating a resource.

Activity icon

Replied to Attempt To Read Property "title" On Bool

can you show your resource too?

Activity icon

Replied to Attempt To Read Property "title" On Bool

The test looks like it should work so seems likely an issue with your controllers method.

What does the method at $this->put('/api/products/' . $product->slug, $edited_product); look like?

Activity icon

Awarded Best Reply on Only All Posts Page In Vue In A Multipage App

You can embed vue components into single routes in laravel if you like. Not all apps need to be SPAs.

Heres a good tutorial. As you aren't using wildcard routes you can skip half way down for the vue bit. https://dev.to/37shadesofgrey/setting-up-vue-in-laravel-8-580m

Activity icon

Replied to Only All Posts Page In Vue In A Multipage App

You can embed vue components into single routes in laravel if you like. Not all apps need to be SPAs.

Heres a good tutorial. As you aren't using wildcard routes you can skip half way down for the vue bit. https://dev.to/37shadesofgrey/setting-up-vue-in-laravel-8-580m

May
08
3 days ago
Activity icon

Replied to Laravel 8 Shopping Cart Quantity Display Issue

check also you have added all the fields you want to save to your $fillable array in your model.

Activity icon

Awarded Best Reply on Dynamic Use Of Cities Table

depends on how you are storing your translations.

Actually if you are using localisation, and your cities are keyed by name then you won't need the accessor and can just render the translation in the view using trans helper.

@foreach($cities as $city)
<option value="{{$city->id}}">{{ trans('city.' . $city->city) }}</option>  
@endforeach

https://laravel.com/docs/8.x/localization

Activity icon

Replied to Dynamic Use Of Cities Table

depends on how you are storing your translations.

Actually if you are using localisation, and your cities are keyed by name then you won't need the accessor and can just render the translation in the view using trans helper.

@foreach($cities as $city)
<option value="{{$city->id}}">{{ trans('city.' . $city->city) }}</option>  
@endforeach

https://laravel.com/docs/8.x/localization

Activity icon

Replied to Dynamic Use Of Cities Table

If you use an accessor on your cities model you can run whatever method you are doing to translate your city name and output it as if it is a field from your cities table.

public function getTranslatedCityAttribute()
{
return $this->translateCity($this->city);
}

This would allow you to pass in the cities array with id and translatedName to build up your select list, rather than translating in the blade.

@foreach($cities as $city)
<option value="{{$city->id}}">{{$city->tranlatedCity}}</option>  
@endforeach

https://laravel.com/docs/8.x/eloquent-mutators

Activity icon

Replied to Form Input Type = "_method" Not Working

Can you reformat your question using three back ticks before and after your code blocks. This will make it easier to read

May
07
4 days ago
Activity icon

Replied to Cashier Mollie - Still Maintained In The Future?

@shadrix

There’s a comment on the bottom of this lesson which suggests otherwise

https://laracasts.com/series/billing-with-laravel-cashier/episodes/8

I quote:

Good question. I'm the author of Cashier for Mollie and will continue to support it with my team. With full backing from Mollie.

Only the docs have been removed from laravel.com . Cashier for Mollie's internal mechanics are an entirely different beast, i.e. running all of the payment scheduling locally instead of depending at an external service. The Laravel core team is not completely familiar with it (it's a lot to take in) and Taylor decided not to portray it as their work. Which is totally understandable.

We're now preparing for the v2 alpha release in March/April 2021 🤞. It's launching to a closed test group at first. If you're interested you can sign up here.

Along with the launch we'll release a dedicated documentation website.

Hope that helps!

Maybe @sandervanhooft can provide a further update for you?

Activity icon

Replied to Polling With Vuejs And Inertia

I’m pretty new to inertia, but have been watching the series where Jeffrey goes though the ping SPA demo app.

So I guess you are switching page, and inertia loads the new route but doesn’t destroy the interval?

Which Vue component are you running your interval on? Are you able to run to on the component you are swapping out?

Activity icon

Replied to Polling With Vuejs And Inertia

I’m been looking at this recently and am using clearInterval within beforeDestroy method.

When you are switching page how are you sure that your interval is still ticking?

I’ve not using Vue with intertia though.

Activity icon

Replied to Modifying An Array Of Model - The Best Way

This is the sort of thing API Resources are used for

https://laravel.com/docs/8.x/eloquent-resources#generating-resources

<?php

namespace App\Http\Resources;

use Illuminate\Http\Resources\Json\JsonResource;

class AllegetiResource extends JsonResource
{
    /**
     * Transform the resource into an array.
     *
     * @param \Illuminate\Http\Request $request
     * @return array
     */
    public function toArray($request)
    {
        return [
            'id' => $this->id,
            'op' => 'be', //this is my customized value and this field does not exists in the tab
            'id_doc' => $this->id_doc,
            'path' => $this->path,
            'type' => $this->type,
            'typeDesc' => $this->typeDesc
        ];
    }
}

in your case, you would define a Resource and then return a collection of the resources

public function getAllegati(Request $request)
{
     $results = Allegati::where('id_doc', $request->get('id_doc'))->get();

     return AllegatiResource::collection($results);
}
Activity icon

Awarded Best Reply on Don Crawler - Scrap Website , And Get The Javascript Property That Is In The DIV

You can use

$node->filter('.my-div-node')->attr('onclick')

To get the whole string and then remove the window.location using substr equivalent.

There should be something in the docs about that https://symfony.com/doc/current/components/dom_crawler.html#usage

Activity icon

Replied to Don Crawler - Scrap Website , And Get The Javascript Property That Is In The DIV

You can use

$node->filter('.my-div-node')->attr('onclick')

To get the whole string and then remove the window.location using substr equivalent.

There should be something in the docs about that https://symfony.com/doc/current/components/dom_crawler.html#usage

May
06
5 days ago
Activity icon

Replied to Laravel Session Is Not Working Correctly

Api should be stateless. If you need seasons move your route to web.php

Activity icon

Replied to SQL To Querybuilder

@johnw65 if you are new to Laravel , I would suggest you read through the documentation:

https://laravel.com/docs/8.x/queries

Whilst it is possible to write raw sql using query builder, the real power of laravel is utilising Eloquent ORM as that "makes it enjoyable to interact with your database"

https://laravel.com/docs/8.x/eloquent

Eloquent queries get reduced to SQL before running against your DB but is much easier to interact with, especially when accessing complex model relationships.

Activity icon

Replied to Do You Use Laravel At Work?

I work as an IT contractor and will now just choose contracts for companies already using or wanting to move their codebase to Laravel.

Having been working on a legacy codebase for a financial services company for the last few years, whilst my knowledge of testing and pipelines increased, I was getting stale when stuck in old symfony (or vanilla php).

Im half way through my career at the moment and think staying constant will give me a better chance at staying relevant, even if that means getting your head round many front end frameworks and various ways to do authentication.

Hoovering up laracasts lessons has massively helped as well as reading all the posts on Laracasts

May
05
6 days ago
Activity icon

Replied to Laravel Booking Code

@alewa you should be able to do:

  $booking->client()->attach(Auth::id());
Activity icon

Replied to Returning Extra Information In An API Resource

I would recommend you look at using an API Resource for this https://laravel.com/docs/8.x/eloquent-resources

May
04
1 week ago
Activity icon

Awarded Best Reply on 404 Not Found. Ajax Route Get Request Not Working As I Wanted To :-(

@rebelutionairy You shouldn’t need to run this command in development.

I suspect your problem is that you actually need to clear your cache for your new routes to show.

By running route:cache you are regenerating the cache. If you destroy the cache with php artisan route:clear you will always have access to new routes if you’d change your routes file and don’t need to run any route commands.

Caching your routes is only necessary on production.

Activity icon

Replied to Returning A View From Controller Goes Wrong.

Can you try with another browser and see if you get the same issue?

Activity icon

Replied to With GDPR Is Everyone Encrypting Names And Emails?

Would you suggest encryption of all personal identifiable information before its stored in the database?

I’m playing devils advocate here btw. Having recently refreshed my OWASP knowledge, I’m curious about how you might get access to a database without getting it via the application. If that was the case, you’d have to report a data breach even if data was encrypted.

@snapey Is encryption of PII something you do in laravel by default? The package that @chrisan mentioned looks interesting but it’s not something I’d thought of doing before I this thread.

May
03
1 week ago
Activity icon

Replied to With GDPR Is Everyone Encrypting Names And Emails?

@snapey if you are encrypting before storing in a database, but have the encryption key available in your app to decrypt, you aren't doing any GDPR protection if someone can compromise your server and then get access to your database.

You should be obfuscating personal identifiable information if you are exporting your data for development use, which would prevent these database copies from having any intrinsic value to unauthorised 3rd parties.

That aside, I’m still interested in why @chrisan would see encryption on the way in being of use, unless you are encrypting to write to the logs.

Activity icon

Replied to With GDPR Is Everyone Encrypting Names And Emails?

@chrisan can you explain how encrypting names and email addresses has any effect on GDPR?

Activity icon

Replied to 404 Not Found. Ajax Route Get Request Not Working As I Wanted To :-(

@rebelutionairy You shouldn’t need to run this command in development.

I suspect your problem is that you actually need to clear your cache for your new routes to show.

By running route:cache you are regenerating the cache. If you destroy the cache with php artisan route:clear you will always have access to new routes if you’d change your routes file and don’t need to run any route commands.

Caching your routes is only necessary on production.

Activity icon

Replied to Laravel On ARM?

Laravel runs in php which is supported on ARM.

Activity icon

Replied to Laravel 8 CORS For Subdomain API

@wadeshuler can you start a new thread with your issue? This one has been marked as solved so won’t be as visible as a new thread

May
01
1 week ago
Activity icon

Awarded Best Reply on Why Does Select In Query Not Speed Things Up?

It’s certainly cleaner to only get the columns you need, but on the query you are doing you won’t see much difference in performance (as you are finding out).

It your table had more columns in it, you might see a little more variation.

If you want to check performance, you could try seeding 10000 rows and then rerunning your tests.

Apr
30
1 week ago
Activity icon

Replied to Deploy To Server Fails

You’ll need to run at least php 7.3 if you are using laravel 8 now. I suspect that is your issue if I understand you correctly,

https://laravel.com/docs/8.x/deployment#server-requirements

Jr you don’t have the means to do this yourself then ask your ISP to switch it on your current package or move to a server which runs this version.