Member Since 2 Years Ago

Experience Points 640
Experience Level 1

4,360 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 2
Best Reply Awards 0
Best Reply
  • start-engines Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-session Created with Sketch.

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • subscriber-token Created with Sketch.


    Earned if you are a paying Laracasts subscriber.

  • lifer-token Created with Sketch.


    Earned if you have a lifetime subscription to Laracasts.

  • lara-evanghelist Created with Sketch.

    Laracasts Evangelist

    Earned if you share a link to Laracasts on social media. Please email [email protected] with your username and post URL to be awarded this badge.

  • chatty-cathy Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

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

27 Jul
3 weeks ago

afletcher started a new conversation Npm Run Dev - Unable To Locate Dependency

I'm running laravel on homestead, and I'm trying to install a vue dependency via NPM.

npm version 6.7.0

I have successfully installed the module via NPM, however when I try to reference the module in my VUE file upon compiling it I get "module is not found error"

This dependency was not found:

* vuetify-material-dashboard in ./resources/js/app.js

To install it, you can run: npm install --save vuetify-material-dashboard

The module is there, and other modules installed are loaded correctly. (app.js)

import Vue from 'vue';
import VueRouter from 'vue-router';
import routes from './routes';
import VueResource from 'vue-resource';
import { TableComponent, TableColumn } from 'vue-table-component';
import Vuetify from 'vuetify';
import Card from 'vuetify-material-dashboard';

I have removed all node modules and reinstalled, deleted the package.json, ssh into the box environment / performed this all locally but the error still persists.

24 Jul
3 weeks ago

afletcher left a reply on Undefined Variable

I've tried this, to no avail.

            async checkItem(item) {
                try {
                   await axios.get('' + item.issn);
                   this.saveitem = true
                } catch (err) {
                    this.saveitem = false


 save() {

                if (this.editedIndex > -1) {

                if (this.editedIndex = -1) {

``` it returns false regardless of wether the API call fails or not

afletcher left a reply on Undefined Variable

I'm really unfamiliar with vue/js, so are you saying that console.log(this.$http); should return the variable from the save() function?

afletcher left a reply on Undefined Variable

NB, if I console.log(response) I get an Undefined.

afletcher started a new conversation Undefined Variable

I'm trying to wrap my head around promises. I am making an API call to check to see if an ISSN exists (via crossref).

I think this is an issue with promises, but I cant seem to get any of the stack overflow to fit with what I'm doing.

methods: {
  checkItem(item) {
                return new Promise((resolve, reject) => {

                            + item.issn
                        .catch(function (error) {
                        .then(response => {
                          if(response.status = 200){
                              return true;
                          if(response.status = 404){
                              return false;

            save() {

                if (this.editedIndex > -1) {
                    Object.assign(this.journals[this.editedIndex], this.editedItem)
            //edit in table and save via API call

                if (this.editedIndex = -1) {
                        //save via api call
            // display error messages

Any resources to help me? I'm struggling to grasp the concept.

21 Jun
1 month ago

afletcher left a reply on Searching Elasticsearch From Vue

Oh, the mounted() axios.get is just a call to test a restful API, to see if it worked before I implemented the elasticsearch

afletcher started a new conversation Searching Elasticsearch From Vue

Good afternoon!

I'm attempting to search my elasticsearch repository through vue + axios.

 import axios from 'axios';
    import { loadProgressBar } from 'axios-progress-bar'
    import 'axios-progress-bar/dist/nprogress.css'


    const query = {
        query: {
            match: {
                "_source": true


    axios.get('http://test.lar:9200/output/_search', {
        params: {
            source: JSON.stringify(query),
            source_content_type: 'application/json'
    }).then((res) => {

    export default {

        data: function() {
            return {
                outputs: []

        mounted() {
                .then((response) => {
                    this.outputs =;
                    console.log('Outputs loaded')
                .catch((err) => {



Now if i curl / manually check the elasticsearch it works fine ( returns repository status. However I'm getting an error message of

outputs:1 Access to XMLHttpRequest at 'http://test.lar:9200/output/_search?source=%7B%22query%22:%7B%22match%22:%7B%22_source%22:true%7D%7D%7D&source_content_type=application%2Fjson' from origin 'http://test.lar' has been blocked by CORS policy: No 'Access-Control-Allow-Origin' header is present on the requested resource.

Now I don't have a CORS policy as far as I'm aware?

How do I rectify this, and what is a CORS policy?

16 Jun
2 months ago

afletcher left a reply on Vue Files Not Updating

Thanks @aurawindsurfing I was having a moment!

afletcher started a new conversation Vue Files Not Updating

I'm trying to follow the laracast SPA + vue guide, and for the life of me, I cannot get the Vue files to update. The blade works fine, but any edits to any .vue file isnt reflected in the browser. I'm using homestead.

I've ran -npm run dev -npm run watch -poll -deleted the cache -restarted the virtualhost

All which run successfully.


import Home from './components/Home';
import About from './components/About';

export default {

    mode: 'history',

    routes: [
            path: '/',
            component: Home,
            name: 'home'
            path: '/about',
            component: About,
            name: 'about'



    <div class="uppercase font-bold mb-3">test123</div>

    export default{};
window.Vue = require('vue');

import Vue from 'vue';
import VueRouter from 'vue-router';
import routes from './routes';


const app = new Vue({
    el: '#app',

    router:new VueRouter(routes)

<!doctype html>
<html lang="{{ str_replace('_', '-', app()->getLocale()) }}">
    <meta charset="utf-8">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <title>Laracasts Assets</title>
    <link rel="stylesheet" href="{{ mix('/css/app.css') }}">
<body class="font-sans">
<div id="app">
    <div class="container mx-auto">
        <header class="py-6 mb-8">
                <img alt="Laracasts" src="">

        <main class="flex">
            <aside class="w-1/5">
                <section class="mb-8">
                    <div class="uppercase font-bold mb-3">The Brand</div>

                    <ul class="list-reset">
                        <li class="text-sm leading-loose"><router-link class="text-black" to="/">Logo</router-link></li>
                        <li class="text-sm leading-loose"><router-link class="text-black" to="/about">Logo Symbol</router-link></li>
                        <li class="text-sm leading-loose"><router-link class="text-black" to="/about">Colors</router-link></li>
                        <li class="text-sm leading-loose"><router-link class="text-black" to="/about">Typography</router-link></li>

                    <div class="uppercase font-bold mb-3">Doodles</div>

                    <ul class="list-reset">
                        <li class="text-sm leading-loose"><router-link class="text-black" to="/">Mascot</router-link></li>
                        <li class="text-sm leading-loose"><router-link class="text-black" to="/about">Illustrations</router-link></li>
                        <li class="text-sm leading-loose"><router-link class="text-black" to="/">Loaders and Animations</router-link></li>
                        <li class="text-sm leading-loose"><router-link class="text-black" to="/about">Wallpapers</router-link></li>

            <div class="primary flex-1">

<script src="/js/app.js"></script>

There are no errors in the browser console either. When I visit the browser the home page still shows "home" and not test123

12 May
3 months ago

afletcher started a new conversation Jobs And Queues - Best Practice

So I'm currently making an application which is downloading information from different API resources.

I have an output model which has a DOI (digital object identifier), and an abstract.

The majority of Output's information is derived from one API. I fire off a job and it collects all the information correctly.

I want to fire off a second job to get the Abstract from a different API.

The abstracts are in the Eutilz Pubmed Service and I've currently got the information through guzzle requests. This works fine for single jobs.

class ProcessAbstract implements ShouldQueue
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    public $tries = 1;
    public $timeout = 120;
    protected $output;

     * Create a new job instance.
     * @return void
    public function __construct(Output $output)
        $this->output= $output;

     * Execute the job.
     * @return void
    public function handle()

        Redis::funnel('key')->limit(1)->then(function () {
            // Job logic...
            $abstract = new AbstractFetcher($this->output);
        }, function () {
            // Could not obtain lock...
            return $this->release(10);


class AbstractFetcher
    protected $output;
    public $apikey ='*************';

    public function __construct(Output $output)
        $this->doi = $output->doi;
        $this->output = $output;

    public function fetch(){

        //TODO check the response codes
        $client = LaravelGuzzleThrottle::client(['base_uri' => '']);
        $res = $client->get($this->getAPIUrl());
        Storage::append('Fuzzle.log', $res->getStatusCode());
        $xmlid = simplexml_load_string($res->getBody());
        $xmlid = $xmlid->IdList->Id->__toString();
        $client = LaravelGuzzleThrottle::client(['base_uri' => '']);
        $res = $client->get($this->getOutputUrl($xmlid));
        $xmlid = simplexml_load_string($res->getBody());

            foreach($xmlid->PubmedArticle->MedlineCitation->Article->Abstract->AbstractText as $text) {
                $stringpieces[]= (string) $text;
            $abstract= implode(' ', $stringpieces);

            Output::where('doi', $this->doi)->update(['abstract' => $abstract]);
        } else {

    } catch(Exception $e){
        Log::alert('Error with processing abstract');
        Log::alert('Output ID ' . $this->output->id);
        Log::alert('Error Message' . $e->getMessage());
        Log::alert('API Url ' . $this->getAPIUrl());
        Log::alert('Output Url ' . $this->getOutputUrl('test'));


    public function getAPIUrl (){
        return  ''.$this->doi . '$api_key=' . $this->apikey;

    public function getOutputUrl($xmid){
        $field = array('db' => 'pubmed', 'retmode' => 'xml', 'rettype' => 'abstract', 'id' => $xmid);
        return "".http_build_query($field);


It also correctly fetches all empty abstracts I for-loop through a collection of Outputs with empty abstracts as a single job.

class ProcessEmptyAbstracts implements ShouldQueue
    use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

    public $tries = 1;
     * Create a new job instance.
     * @return void
    public function __construct()

     * Execute the job.
     * @return void
    public function handle()

        Redis::throttle('key')->allow(1)->every(5)->then(function () {
            $outputs = Output::where('abstract', null)->get();

            foreach ($outputs as $item) {

                $url = $this->getAPIUrl($item->doi);
                $xml_str = file_get_contents($url); //grab the contents
                $xml = new SimpleXMLElement($xml_str); //convert to SimpleXML

                // removes all the actual ones without any abstracts, content pages etc
                if (!empty($xml->ErrorList)) {
                } // hasnt thrown an error so why is it not putting the abstract?
                else {
                    $xmlid = $xml->xpath('IdList/Id');
                    $xmlid = strval($xmlid[0]);
                    $curl = curl_init();
                    $field = array('db' => 'pubmed', 'retmode' => 'text', 'rettype' => 'abstract', 'id' => $xmlid);

                    curl_setopt_array($curl, array(
                        CURLOPT_URL => "".http_build_query($field),
                        CURLOPT_RETURNTRANSFER => true,
                        CURLOPT_ENCODING => "",
                        CURLOPT_TIMEOUT => 30000,
                        CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
                        CURLOPT_CUSTOMREQUEST => "GET",

                        CURLINFO_HEADER_OUT => true,
                        CURLOPT_HTTPHEADER => array(
                            'Content-Type: application/json',
                    $response = curl_exec($curl);
                    $err = curl_error($curl);

                    Output::where('doi', $item->doi)->update(['abstract' => $response]);



        }, function () {
            return $this->release(10);

    public function getAPIUrl ($doi){
        return  ''.$doi;


Now if I try to fire off the job through a model observer, it returns multiple errors of

[2019-05-12 14:21:02] local.ERROR: App\Jobs\ProcessAbstract has been attempted too many times or run too long. The job may have previously timed out. {"exception":"[object] (Illuminate\Queue\MaxAttemptsExceededException(code: 0): App\Jobs\ProcessAbstract has been attempted too many times or run too long. The job may have previously timed out. at /home/vagrant/code/homestead/vendor/laravel/framework/src/Illuminate/Queue/Worker.php:405) [stacktrace] #0 /home/vagrant/code/homestead/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(321): Illuminate\Queue\Worker->markJobAsFailedIfAlreadyExceedsMaxAttempts('redis', Object(Illuminate\Queue\Jobs\RedisJob), 1) #1 /home/vagrant/code/homestead/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(277): Illuminate\Queue\Worker->process('redis', Object(Illuminate\Queue\Jobs\RedisJob), Object(Illuminate\Queue\WorkerOptions)) #2 /home/vagrant/code/homestead/vendor/laravel/framework/src/Illuminate/Queue/Worker.php(118): Illuminate\Queue\Worker->runJob(Object(Illuminate\Queue\Jobs\RedisJob), 'redis', Object(Illuminate\Queue\WorkerOptions)) #3 /home/vagrant/code/homestead/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(102): Illuminate\Queue\Worker->daemon('redis', 'abstracts', Object(Illuminate\Queue\WorkerOptions)) #4 /home/vagrant/code/homestead/vendor/laravel/framework/src/Illuminate/Queue/Console/WorkCommand.php(86): Illuminate\Queue\Console\WorkCommand->runWorker('redis', 'abstracts') #5 /home/vagrant/code/homestead/vendor/laravel/horizon/src/Console/WorkCommand.php(46): Illuminate\Queue\Console\WorkCommand->handle() #6 [internal function]: Laravel\Horizon\Console\WorkCommand->handle() #7 /home/vagrant/code/homestead/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(32): call_user_func_array(Array, Array) #8 /home/vagrant/code/homestead/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(90): Illuminate\Container\BoundMethod::Illuminate\Container\{closure}() #9 /home/vagrant/code/homestead/vendor/laravel/framework/src/Illuminate/Container/BoundMethod.php(34): Illuminate\Container\BoundMethod::callBoundMethod(Object(Illuminate\Foundation\Application), Array, Object(Closure)) #10 /home/vagrant/code/homestead/vendor/laravel/framework/src/Illuminate/Container/Container.php(576): Illuminate\Container\BoundMethod::call(Object(Illuminate\Foundation\Application), Array, Array, NULL) #11 /home/vagrant/code/homestead/vendor/laravel/framework/src/Illuminate/Console/Command.php(183): Illuminate\Container\Container->call(Array) #12 /home/vagrant/code/homestead/vendor/symfony/console/Command/Command.php(255): Illuminate\Console\Command->execute(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\Console\OutputStyle)) #13 /home/vagrant/code/homestead/vendor/laravel/framework/src/Illuminate/Console/Command.php(170): Symfony\Component\Console\Command\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Illuminate\Console\OutputStyle)) #14 /home/vagrant/code/homestead/vendor/symfony/console/Application.php(908): Illuminate\Console\Command->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput)) #15 /home/vagrant/code/homestead/vendor/symfony/console/Application.php(269): Symfony\Component\Console\Application->doRunCommand(Object(Laravel\Horizon\Console\WorkCommand), Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput)) #16 /home/vagrant/code/homestead/vendor/symfony/console/Application.php(145): Symfony\Component\Console\Application->doRun(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput)) #17 /home/vagrant/code/homestead/vendor/laravel/framework/src/Illuminate/Console/Application.php(90): Symfony\Component\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput)) #18 /home/vagrant/code/homestead/vendor/laravel/framework/src/Illuminate/Foundation/Console/Kernel.php(122): Illuminate\Console\Application->run(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput)) #19 /home/vagrant/code/homestead/artisan(37): Illuminate\Foundation\Console\Kernel->handle(Object(Symfony\Component\Console\Input\ArgvInput), Object(Symfony\Component\Console\Output\ConsoleOutput)) #20 {main} "}

I'm really sorry if this is obvious, but I have very limited PHP experience. I can't seem to understand why it intermittently fails one way but not another?

19 Feb
2 years ago

afletcher left a reply on Laravel Hasmanythrough But With Manytomany

Thank you very much for the responses. Snapey's response helped me out massively.

Of note whereIn('id', $ids); threw an error

Integrity constraint violation: 1052 Column 'id' in where clause is ambiguous

which I fixed by prefixing the table name to the wherein

whereIn('', $id)

afletcher left a reply on Laravel Hasmanythrough But With Manytomany

Like this?

 $cats = self::find($this->id)->Categories;

foreach ($cats as $item){
    $articles = Article::with(['categories' => function ($query) {
        $query->categoryID = $item->id;

except I don't seem to be able to pass the $item to the $query as its undefined

Also even if you set

  $cats = self::find($this->id)->Categories;
    $articles = Article::with(['categories' => function ($query) {

        $query->categoryID = 5;


its returning a collection of all the articles.

afletcher left a reply on Laravel Hasmanythrough But With Manytomany

So if I'm reading this correctly.

As I have 3 tables (Articles, Categories and UserDetails) I would have to pull all the user categories

Then loop through it for each category and then pull out all the articles?

afletcher started a new conversation Laravel Hasmanythrough But With Manytomany

I have looked at the previous responses on the topic but I'm not sure it works for what I've set up. I have two pivot tables (unfortunately, I didn't follow the typical naming for the tables, as I couldn't find any information on how to name the columns for pivot tables) and hence my pivot tables have their own column names.

Each user has many categories. Each category has many articles. I want to retrieve all the articles from a set of categories which the user has.

So say a user has category 1, category 2, I want to retrieve all articles from category 1 and category 2.

For each of these belongsToMany relationships below, I have my own pivot tables.


id | articleID | categoryId


id | user_details_id | categories_id



public function categories()
    return $this->belongsToMany('App\Categories', 'article_categories', 'articleID', 'categoryID');


public function Categories()
    return $this->belongsToMany('App\Categories', 'users_cats', 'user_details_id', 'categories_id');


public function articles()
    return $this->belongsToMany('App\Article', 'article_categories', 'categoryID', 'articleID');

public function UserDetails()
    return $this->HasMany('App\UserDetails', 'users_cats', 'user_details_id', 'categories_id');

I have tried to use HasMany through but It doesn’t work with a many to many relationship as far as I can tell.

Currently (as a sort of “work around”) I've been using this.

  $user=\App\UserDetails::with(['categories.articles' => function($query){
            $query->orderBy('date', 'desc');


        foreach($user->categories as $category)

        return $category->articles->unique();

However, I don’t think it will scale well with increasing data (it's already producing over 1k queries with only 1000 articles, taking over 8 seconds to load).

13 Jan
2 years ago

afletcher left a reply on Twitter Streaming Api

Any solution with this, I am running into the same error.