Drfraker

Experience

93,770

24 Best Reply Awards

  • Member Since 5 Years Ago
  • 1013 Lessons Completed
  • 4 Favorites

22nd October, 2018

Drfraker left a reply on Basic $emit() Function Not Working • 21 hours ago

First off your emitted events should be kebab-case not camelCase. Secondly, you have $emit('showPage') but you are listening to v-on:="showTheme"

That is probably the problem.

18th October, 2018

Drfraker left a reply on Basic $emit() Function Not Working • 4 days ago

You need to add an event listener to your vue component. Also, it's easier to read events that are past tense and then respond to them in present tense. 'pageManagerToggled' would be the event that you emit and then your component responds by 'togglePageManager'. The code reads how you would say it, which is nice.

// Assuming this is in a vue compnent...

<a href="javascript:void(0)" @click="$emit('pageManagerToggled')">
              <i class="fas fa-bars fa-2x"></i>
</a>
// add a listener to the component...
<template>

<div v-show="isVisible" class="fixed pin">

    <div class="cursor-pointer" @click="togglePageManager" v-on:pageManagerToggled="togglePageManager">
        <i class="fas fa-times text-2xl text-blue-dark"></i>
    </div>
    // reset of my code goes here 
</div>

</template>

<script>

export default {

  name: 'PageManager',

  data () {

    return {

        isVisible   :               false,
    }

  },

  methods: {

    togglePageManager : function(){

        this.isVisible = !this.isVisible;

    }

  }

}
</script>

16th October, 2018

Drfraker left a reply on Events/Jobs Inside Event Listener Never Fire • 6 days ago

I think it might work if you set 'QUEUE_DRIVER="sync"` in your .env file.

Drfraker left a reply on Call To A Member Function Where() On Integer • 1 week ago

Looks like assigned_to is coming in as an integer. Probably the user_id. You'll have to do something like $user = User::firstOrFail($request->assigned_to); instead of $user = $request->assigned_to;

9th October, 2018

Drfraker left a reply on Laravel Cashier Webhook Response From Stripe • 1 week ago

You can fake the webhook in a test to ensure that your logic is working. Then you don't have to manually go to stripe and test it. If you want to test manually you can use laravel valet and type valet share in the console. It will set up a tunnel url to your local application that you can use in the stripe webhooks testing side and actually hit your code from stripe.

I've done it both ways, but I prefer the fake webhook request in a test because it's fast and I don't have to worry about it ever again! :)

12th September, 2018

Drfraker left a reply on Strange Results Using Find() And Where() • 1 month ago

What is your database schema for the Documento table? It seems like you might have a column called 'id' that is not the primary key.

21st August, 2018

Drfraker left a reply on Mocking Stripe - How Not To Call The API • 2 months ago

Here's an overview of how I've done it based on the tdd series by Adam Wathan.

  1. Create an interface and call it PaymentGateway. Add a method to the interface called chargeOrder() that takes an order and a customer parameter. You'll also want to add other methods for getting total charges for a customer etc.
  2. Create a StripePaymentGateway and have it implement the PaymentGateway interface and all of its methods. This class is where you can import Stripe classes and actually talk to stripe. It should do some work and return whatever it returns like your current chargeOrder does.
  3. create a FakePaymentGateway and also have it implement the PaymentGateway interface. In this class you can just fake the chargeOrder method and have it return the same thing as the real implementation does when a successful transaction takes place but it won't actually talk to stripe. This class will just do something simple like store charges in an array so that you can retrieve them and ensure that they were charged properly in your test assertions.

If you go this route you will want to write contract tests in a trait to ensure that your fake and real implementation behave the same way and do not diverge. But that is more advanced and might be hard to cover in a forum post.

11th May, 2018

Drfraker left a reply on Where Would You Save Dozens Of Lists Of Arrays? • 5 months ago

How often will the list of ajdectives change? If it is something that changes often you might want to store them in your database so that you can update the list without re-deploying code. If you make a model of adjectives and store them in the database you can use sequel pro or some other database GUI to update the list without having to create an admin area with CRUD operations to make changes to the list.

Alternatively, if they rarely change you could keep it the way you have it or store them in a configuration file and use the config helper to retrieve them:

$adjectives = config('data.listOfAdjectives');

I think it really comes down to how often changes will be made to the list.

Drfraker left a reply on Axios POST Request Through API Failing To Work - Laravel 5.4 Echo Video Series. • 5 months ago

Instead of this

methods: {
    save() {
      axios
        .post("/api/projects/${this.project.id}/tasks", { body: this.newTask })
        .then(response => response.data)
        .then(this.addTask);
    },

    addTask(task) {
      this.project.tasks.push(task);
      this.newTask = "";
    }
  }

Try this:

methods: {
    save() {
      axios
        .post("/api/projects/${this.project.id}/tasks", { body: this.newTask })
        .then(response => {
        this.addTask(response.data);
    })
    },

    addTask(task) {
      this.project.tasks.push(task);
      this.newTask = "";
    }
  }

Drfraker left a reply on Laravel App In Subdirectory Of Project • 5 months ago

In the forge UI when you create a new site you can specify where the laravel entry index.php file will be located. It is "/publi"c by default but you can change that to "/path/to/src/public" and it should work fine from there.

7th May, 2018

Drfraker left a reply on Laravel 5.6 How To Build A Full Aplication By Consuming External Web Service Api • 5 months ago

Just use guzzle to pull in data and convert it to objects in your app and store stuff in the database.

30th April, 2018

Drfraker left a reply on How Should I Do My Project • 5 months ago

You mentioned React in the OP, which is similar to Vue. In my opinion, Vue might be a better choice because it is more widely used in the Laravel community. Therefore, you might get a higher percentage of people on this forum to help you with questions. If you just have static front end requirements, don't use React or Vue.

26th April, 2018

Drfraker left a reply on How To Get The Second One? • 5 months ago

Collections can be accessed like arrays because they implement the ArrayAccess and Arrayable contract.

Here is the BaseCollection file from the framework.

<?php
namespace Illuminate\Support;
use stdClass;
use Countable;
use Exception;
use ArrayAccess;
use Traversable;
use ArrayIterator;
use CachingIterator;
use JsonSerializable;
use IteratorAggregate;
use Illuminate\Support\Debug\Dumper;
use Illuminate\Support\Traits\Macroable;
use Illuminate\Contracts\Support\Jsonable;
use Illuminate\Contracts\Support\Arrayable;

class Collection implements ArrayAccess, Arrayable, Countable, IteratorAggregate, Jsonable, JsonSerializable 
{
    //...
}

Therefore, when you get a collection or Eloquent collection you can access the items as if it were an array.

//  Eloquent
$books = Book::all();
$firstBook = $books[0];
$secondBook = $books[1];

// Collection
$books = collect(['book1', 'book2', 'book3']);
$firstBook = $books[0];
$secondBook = $books[1];

25th April, 2018

Drfraker left a reply on How Should I Do My Project • 5 months ago

Laravel/VueJs pair nicely together. I'd recommend starting there. If for nothing else, the amount of community help you could get would be maximized with those tools.

12th April, 2018

Drfraker left a reply on Phpunit Not Always Right • 6 months ago

I ran this 100,000,000 times just for fun and got really close to 10%. 10.000539% to be exact.

Here's the code test code for fun:

<?php

namespace Tests\Feature;

use Tests\TestCase;
use Illuminate\Foundation\Testing\WithFaker;
use Illuminate\Foundation\Testing\RefreshDatabase;

class randTest extends TestCase
{
    /** @test */
    public function two_random_number_probablity()
    {
        $matches = 0;

        for ($i = 0; $i < 100000000; $i++) {
            $a = rand(1,10);
            $b = rand(1,10);

            if ($a === $b) {
                $matches++;
            }
        }

        $percent = ($matches / $i) * 100;
        dd($percent);
    }
}

27th March, 2018

Drfraker left a reply on Why My Json Data Does Not Show From API Database • 6 months ago

@towhid

IMHO if you have to ask how to get data from a 3rd party API you are starting out in the wrong place on this app. I would suggest going to the beginner courses on this site and starting there. You need to learn to walk before you can run.

26th March, 2018

Drfraker left a reply on How To Attach Many To Many (non Fake) To Seeder/faker • 6 months ago

$user->roles()->attach($faker->numberBetween(10,20));

I haven't tested this but it should work fine as long as the roles are seeded first.

Drfraker left a reply on Why My Json Data Does Not Show From API Database • 6 months ago

You can't just create a route called "api/v1/whatever-you-want-to-get-from-another-api" and expect to get the data back.

You actually have to call the other API and the other API has to allow you to get data from it. What your code is doing is getting lessons from your own database based on an API route you created to your own application server.

Do you have access to the 3rd party API? Do you know the endpoint that you need to hit to get that data? If so you need to use that in your controller instead of Lesson::all()

Drfraker left a reply on Why My Json Data Does Not Show From API Database • 6 months ago

Right. If you don't have any lessons in the database you will get an empty collection from the code you have.

Do you know how to add data to your database? If so, add a few lessons and it will work. If not, do this:

php artisan tinker

Once in the tinker shell...

App\Lesson::create(['title' => 'First Lesson', 'body' => 'Body of first lesson' ]);

That will create one lesson in the database for you. It should now be showing up in the Lesson collection you get in your controller.

Hope that helps :)

Drfraker left a reply on Cannot Load Async/await Images. • 6 months ago

Lets try a hangout, it will be much easier to help that way. I'll keep it live for the next 10 minutes or so.

https://hangouts.google.com/call/65iAEdHpHZPeSrzKjgu1AAEE

Drfraker left a reply on Cannot Load Async/await Images. • 6 months ago

Oops, I had a typo before. The image data should be loaded when the component is created. getImageData(imageId) will never get called the way I wrote it before.

data() {
    return {
        imageData: '',
    }
},

created() {
    let vm = this;
    axios.get(route('images.loadId', imageId)).then((response) => {
        vm.imageData = response.data.imageData;
    });
},

Drfraker left a reply on Cannot Load Async/await Images. • 6 months ago

Scratch that, this might be a better way to go. I'm assuming that each image is its own vue component.

In template code:

<img :src="imageData">

then in js land

data() {
    return {
        imageData: '',
    }
},

getImageData(imageId) {
    let vm = this;
    axios.get(route('images.loadId', imageId)).then((response) => {
    vm.imageData = response.data.imageData;
    });
},

Drfraker left a reply on Cannot Load Async/await Images. • 6 months ago

I would do this:

In template code:

<img :src="getImageData(product.image_id)">

then just...

getImageData(imageId) {
    axios.get(route('images.loadId', imageId)).then((response) => {
    return response.data.imageData;
    });
},

Drfraker left a reply on Cannot Load Async/await Images. • 6 months ago

It looked like you were getting a promise object before. Sorry I misunderstood. Can you tell me exactly what that code above logs out?

Drfraker left a reply on Cannot Load Async/await Images. • 6 months ago

What do you get when you do this?

            getImageData(imageId) {
                return axios.get(route('images.loadId', imageId));
            },

            async loadImage(imageId) {
                let response = await this.getImageData(imageId);

                console.log(response);

                //return imageData;
            },

Drfraker left a reply on Cannot Load Async/await Images. • 6 months ago

Try this:

            getImageData(imageId) {
                axios.get(route('images.loadId', imageId)).then((response) => {
            return response.data;
        });
            },

            async loadImage(imageId) {
                let {data: imageData} = await this.getImageData(imageId);

                console.log(imageData);

                return imageData;
            },

Drfraker left a reply on Why My Json Data Does Not Show From API Database • 6 months ago

You need to create a migration for the lessons table and run it. Like the error says: "Base table or view not found: 1146 Table 'data.lessons' doesn't exist (SQL: select * from lessons)" When your application is trying to run the sql query "select * from lessons" there is not a "lessons" table available.

php artisan make:migration create_lessons_table --create=lessons

Add the pertinent information into the migration that the artisan command creates.

php artisan migrate

Afer doing this your application should work as you expect.

10th March, 2018

Drfraker left a reply on Single Request, Multiple Models Of The Same Type • 7 months ago

Create your form with name prefixes for each field. Like student_email, partner_email, etc. When you do validation you can validate them correctly.

Drfraker left a reply on Make Default Auth Uses People Credentials • 7 months ago

I think you will simply need to override this function from the trait in your User.php file:

/**
     * Get the e-mail address where password reset links are sent.
     *
     * @return string
     */
    public function getEmailForPasswordReset()
    {
        return $this->people->email; // whatever this is on the user's profile
    }

Drfraker left a reply on Conditional Vue Component In Blade • 7 months ago

If you are loading it based on the route anyway, why not add a new route and show an entirely different *.blade.php view for each route?

8th March, 2018

Drfraker left a reply on Bootstrap Sass • 7 months ago

Can't figure out how to delete a question...

Drfraker started a new conversation Bootstrap Sass • 7 months ago

Im testing something on here.

28th February, 2018

Drfraker left a reply on Add Queue Listen As Post Deployment Hook • 7 months ago

In envoyer you can create a deployment hook from the ui.

Set it up to run after the "Activate New Release" event.

cd {{release}}

php artisan queue:restart

Drfraker left a reply on Passing Boolean From Laravel Blade To Vue Component Prop • 7 months ago

Try casting it to a boolean from the model:

// User.php

protected $casts = ['two_factor_enabled' => 'boolean'];

27th February, 2018

Drfraker left a reply on How To Save Quill.js Values To Database Laravel 5.6 • 7 months ago

@sutherland I'm not copying your homework! I found the link on the Quill.js site and changed my answer so I didn't give the guy the wrong information. I didn't even know you had posted anything.

Drfraker left a reply on How To Save Quill.js Values To Database Laravel 5.6 • 7 months ago

I've never used Quill.js but if you want a regular post request when you submit a form on your page. Try attaching quill.js to a text area in your form.

<form action="/some/route" method="post">
    <textarea id="editor" name="body"></textarea>
    <button type="submit">Save</button>
</form>

Drfraker left a reply on Redirect From The Auth/LoginController • 7 months ago

What is the uri that is being returned from Session::get('uri')? How is that being set in the session when they log in?

Try this:

// LoginController.php

protected function redirectTo() {

     return dd(Session::get('uri'));
}

What is the result of that? You can also specify a default value in the case that the 'uri' variable isn't set like this:

Session::get('uri', '/dashboard');

Drfraker left a reply on Change Id Field To People_id • 7 months ago

Your primary key is set on the model as 'id'. If you want it to be something different you have to specify that by setting the property in your model to the new 'people_id'. I wouldn't recommend doing this because eloquent works out of the box by following conventions. You will fight this to some degree each time you want to set up a relationship with People.php.

To change it here is what you need to do:

// People.php
protected $primaryKey = 'people_id';


//CreatePeopleTable.php
$table->increments('people_id');

23rd February, 2018

Drfraker left a reply on Time Not Saving Correctly • 8 months ago

Show the code. We can't help if we don't see what you are actually doing.

Drfraker left a reply on Where Do I Start With Testing This Small Class? • 8 months ago

If you aren't worried about github api changing, or it isn't that important to the core functionality of your app, then maybe consider mocking Zttp. This will have the benefit of being faster and not requiring internet connection for the test to run with the downside of not actually testing that you can get information from github.

If it is critical to make sure that the API call is working, you can make it more of an integration test and hit the github API for a repository of yours with a known value of stars and make sure that it is returning the correct data. Or build the world in the test and use the github API to create a repository and star it, then use this class to confirm that you can access the repo and see that it has one star. Finally delete the repository once the test has run.

I have some tests like this and I do both options, but I place all of the Integration tests in a separate test suite and only run them before I push to production. In my day to day testing I don't run them because they are slow.

Drfraker left a reply on Moving From Shared Server To Forge - Subfolder Redirect To Subdomain • 8 months ago

Create a new site on the forge server called sub.domain.com and install your laravel app there. (you won't need to put it in domain.com/subfolder/public) In your dns settings point the address sub.domain.com to the IP address of your server.

12th February, 2018

Drfraker left a reply on Weird Issue With Queued Jobs Not Processing • 8 months ago

That is strange. I would move to laravel horizon. With horizon you get a dashboard that you can see jobs running and see when they fail. It might give you some insight into when they are failing and offer more debugging options.

Drfraker left a reply on Ubuntu And PHP 7.1 • 8 months ago

Not sure. Sorry.

Drfraker left a reply on Ubuntu And PHP 7.1 • 8 months ago

I'm running PHP 7.2 on an ubuntu 16.04 server. So I'd say you might be missing something.

Drfraker left a reply on What Is A Good Approach To Getting Model Properties? • 8 months ago

If you want to decouple it from the column name, you could do this:

class User extends Model 
{
    public function email(){
        return $this->email; // this can change if you change the column name.
    }   
}

Drfraker left a reply on Why Is My Vue In Laravel Not Showing? • 8 months ago

Take a moment to help the people that are helping you and include your route and controller logic. It is impossible to diagnose the issue with the code you provided.

Drfraker left a reply on Multiple Parameters To Crud • 8 months ago

@dsml you can type

php artisan route:list 

in the console and see all of the routes in your app. This might help you understand what the resource routes are creating for you.

Drfraker left a reply on Subpages Laravel • 8 months ago

Hey @littlebox

I think it might be easier to break this out into multiple controllers so that you can follow a rest pattern all the way down from a podcast to the finer details about an episode. It also makes the routing easier. I'm not sure what "serials" are so I'm going to use a concept that is easy for me to understand, Podcasts. This is very quick and dirty and you may want to change the structure a bit, but I think you'll get the gist of it.

web.php might have the following.

// Show all podcasts in the database
Route::get('podcasts', '[email protected]')->name('podcasts.index');

// Show information about a specific podcast including all seasons
Route::get('podcasts/{podcast}', '[email protected])->name('podcasts.show');

// Show information about a specific podcast season. which shows all episodes for the given season
Route::get('seasons/{season}/episodes', '[email protected]')->name('episodes.show');

// Show all information about a specific episode
Route::get('episodes/{episode}', '[email protected]')->name('episodes.show');

This assumes that you have a data structure like this: podcasts id, name, meta...

seasons id, podcast_id, name, meta...

episodes id, season_id, name, meta...

You can use has hasManyThrough relationship to connect episodes to a podcast through the seasons relationship.

Edit Your Profile
Update

Want to change your profile photo? We pull from gravatar.com.