realrandyallen

realrandyallen

Member Since 2 Years Ago

Sarasota, FL

Experience Points 154,830
Experience
Level
Lessons Completed 603
Lessons
Completed
Best Reply Awards 153
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.

22 Jan
18 hours ago

realrandyallen left a reply on This.$http Is Undefined In My Example.vue In Laravel 5.4

You can just use axios which is bundled with laravel automatically:

            axios.get('/api/user')
                .then(response => {
                    console.log(response.data);
            });
21 Jan
1 day ago

realrandyallen left a reply on FedEx Api Integration

It may just be that your credentials are not being set properly when referencing them from credentials.php....as a test try hard coding them in your test controller just to see if you get a different response:

// hard code all these instead of using the constants as a test

    $rateRequest->WebAuthenticationDetail->UserCredential->Key = FEDEX_KEY;
    $rateRequest->WebAuthenticationDetail->UserCredential->Password = FEDEX_PASSWORD;
    $rateRequest->ClientDetail->AccountNumber = FEDEX_ACCOUNT_NUMBER;
    $rateRequest->ClientDetail->MeterNumber = FEDEX_METER_NUMBER;

realrandyallen left a reply on FedEx Api Integration

Can you post all the relevant code so we can try to help you out?

realrandyallen left a reply on Change Column Name And Datatype

You can run it as a raw query in a new migration that modifies the column:

public function up()
{
    DB::statement("ALTER TABLE users MODIFY COLUMN role VARCHAR(50) NULL");
}

realrandyallen left a reply on Multiple Charts With Vue And Charts.js

You need to getContext on the canvas, but I think this.$el in your case is pointing to the section tag. One easy way is to just give the canvas a ref

<canvas width="600" height="400" ref="chart"></canvas>

<script>
    export default {
        mounted() {
            console.log('Graph component mounted.')
            var context = this.$refs.chart.getContext('2d');

    ...
20 Jan
2 days ago

realrandyallen left a reply on Get Position In Rating By Scope

@DRONAX - You'll need to make a decision, do you want Shop's to be ranked overall (all Shops) or only by how they rank within their category, or do you want the system to do both?

  1. All Shops: Keep your logic the way it is and when you group by Category don't use the position field from the DB, just use where you currently are in the loop as the Shop's rank.

  2. By Category Only Update the updateRanks method to filter by a Shop's category_id

  3. Both Consider adding another field to your Shop table, category_position, and add another method updateRanksByCategory when you create or edit a Shop that would update those values in the db

realrandyallen left a reply on Model Factory Relation Error: Column XYZ Cannot Be Null

@VOIDMRVOID - This hit me at an ungodly hour randomly last night but you're using make here:

$order = factory(\App\Models\Order::class)
            ->make([
                'handler_id' => 1,
                'categories' => ['first', 'second']
            ]);

Which means no id is being generated (because you aren't persisting to the DB. So when you do this:

$factory->afterMaking(App\Models\Order::class, function ($order) {
    $order->progress()->save(factory(\App\Models\OrderProgress::class)->make([
        'order_id' => $order->id
    ]));
});

There is no $order->id

19 Jan
3 days ago

realrandyallen left a reply on Router Link Error

In app.js did you actually feed your routes const to your Router? See this exapmle:

https://router.vuejs.org/guide/essentials/named-routes.html#named-routes

realrandyallen left a reply on Get Position In Rating By Scope

@DRONAX - You byRating scope can just be added on to to filter by category, which should then rank every shop within that category:

$shops = Shop::byRating()->where('category_id', 1)->get();

You could also make another scope byCategory that would make it reusable and clean

//controller
$shops = Shop::byRating()->inCategory(1)->get();

// model

public function scopeInCategory($query, $category_id)
{
    return $query->where('category_id', $category_id);
}

realrandyallen left a reply on Code Review: Is This Okay, Or Should I Be Doing Something...

Maybe something like this:

// Controller
public function upload(Request $request)
{
    $attachment = (new Attachment)->store($request);

    $attachment->addNotes(1);

    return back();
// Model
public function store($attachment)
{
    $attachment->file('file')->storeAs('/public/', preg_replace('/[, ]+/', '-', $attachment->file->getClientOriginalName()));

    $this->user_id        = $attachment->user()->id;
    $this->file_name      = preg_replace('/[, ]+/', '-', $attachment->file->getClientOriginalName());
    $this->original_name  = $attachment->file->getClientOriginalName();
    $this->file_type      = $attachment->file->getClientMimeType();
    $this->file_ext       = $attachment->file->getClientOriginalExtension();
    $this->file_path      = Storage::url($this->file_name);
    $this->web_path       = asset('/storage/' . $this->file_name);
    $this->custom_name    = $this->file_name;

    $this->save();

    return $this;
}

public function addNotes($client_id)
{
    $this->notes()->attach($this->id, ['client_notes_id' => $client_id]);

    return $this;
}

realrandyallen left a reply on Data Don't Update

The field names in your forms don't match what you're specifying in your controller, i.e. it should be this for the customer email

$request->customer_email

realrandyallen left a reply on Model Factory Relation Error: Column XYZ Cannot Be Null

If this is what you're doing:

    $order->progress()->save(factory(\App\Models\OrderProgress::class)->make([
        'order_id' => $order->id
    ]));

Try wrapping the order id in a closure like in my sample:

$factory->define(App\Models\OrderProgress::class, function () {
   return [
      'order_id' => function() {
         return factory(Order::class)->create()->id;
      },
   ];
});

realrandyallen left a reply on How To Include Specific Portion Of One Blade File To Another

@ABDULBAZITH - Ah I missed that part, I suppose in that case you could go back to one partial and also include a data type:

@include('Monthly_statement.tbody', ['data' => $salesDetails, 'type' => 'sales'])

Monthly_statement.tbody

@if($type == 'sales')
    @foreach($purchaseDetails as $vendorName => $details)
        @isset($details['rate'])
            <tr>
                <td>{{ $details['rate'] }}</td>
                <td>{{ $vendorName }}</td>
                <td>{{ $details['total_litres'] }} </td>
                <td>{{ $details['total'] }}</td>
            </tr>
        @endisset 
    @endforeach 
@endif

realrandyallen left a reply on Model Factory Relation Error: Column XYZ Cannot Be Null

@VOIDMRVOID - Try running composer dump-autoload, you may have a cache issue

realrandyallen left a reply on Model Factory Relation Error: Column XYZ Cannot Be Null

@VOIDMRVOID - How are you calling it? I.e.

factory(\App\Models\OrderProgress::class)->create()

Or something different?

realrandyallen left a reply on Include Components By Condition

Honestly I probably would have done it the exact way you have, ordering could be an issue I suppose but it seems like a good solution to me

realrandyallen left a reply on How To Include Specific Portion Of One Blade File To Another

What not just have separate partials for each table?

@include('Monthly_statement.purchases', ['data' => $purchaseDetails]) 

...

@include('Monthly_statement.sales', ['data' => $salesDetails]) 

Monthly_statement.purchases

<table>
    <tbody>
        @foreach($data as $vendorName => $details)
            @isset($details['rate'])
                <tr>
                    <td>{{ $details['rate'] }}</td>
                    <td>{{ $vendorName }}</td>
                    <td>{{ $details['total_litres'] }} </td>
                    <td>{{ $details['total'] }}</td>
                </tr>
            @endisset
        @endforeach 
    </tbody>
</table>

then just do the same for sales

18 Jan
4 days ago

realrandyallen left a reply on Pass DateTime To Vue Component (countdown Timer)

@TREVORPAN - It's gonna be hard for me to tell without seeing a dump of all the code, app.js, the main view for jobs and the job partial for each job.

In the end you shouldn't be using #countdown at all, if setup correctly you won't need to have that as an id on anything element

realrandyallen left a reply on Model Factory Relation Error: Column XYZ Cannot Be Null

@VOIDMRVOID - You would keep the code you have

$factory->afterMaking(App\Models\Order::class, function ($order) {
    $order->progress()->save(factory(\App\Models\OrderProgress::class)->make([
        'order_id' => $order->id
    ]));
});

You just need to tell the OrderProgress factory what fields it should expect to create or receive. Same thing in your Order factory, you have to have "defaults" in there that you can then override in your tests

realrandyallen left a reply on Cant Send Mail In Laravel 5.3

Try clearing your config cache php artisan config:clear

You could also try hardcoding your settings directly into config/mail.php just to see if it makes a difference.

The code you have seems like it'd work fine in 5.3

https://laravel.com/docs/5.3/mail

realrandyallen left a reply on Event Subscriber Doesn't Work Well When Event Fired

@HSNTNGR - Are you getting any errors? Are you dispatching the event?

realrandyallen left a reply on Pass DateTime To Vue Component (countdown Timer)

@TREVORPAN - So, it sounds like it's working except the placement of the deadline on the page? Is there any CSS related to the deadlinejobpage class?

realrandyallen left a reply on Model Factory Relation Error: Column XYZ Cannot Be Null

Specify an order_id in your OrderProgress factory:

$factory->define(App\Models\OrderProgress::class, function () {
    return [
    'order_id' => function() {
        return factory(Order::class)->create()->id;
    },
    ];
});

This will create an order_id if you don't override it

realrandyallen left a reply on Event Subscriber Doesn't Work Well When Event Fired

Could be a namespace issue, by default your Subscribers will be namespaced to App\Listeners but you're specifying App\Subscribers in your Subscriber

realrandyallen left a reply on How To Include Specific Portion Of One Blade File To Another

Not sure exactly what you're trying to do but one of these solutions will probably work...either create the tbody itself inside the loop:

// view.blade.php
<table>
    @include('Monthly_statement.tbody')
</table>

//Monthly_statement.tbody
@foreach($purchaseDetails as $vendorName => $details)
    @isset($details['rate'])
        <tbody>
            <tr>
                <td>{{ $details['rate'] }}</td>
                <td>{{ $vendorName }}</td>
                <td>{{ $details['total_litres'] }}</td>
                <td>{{ $details['total'] }}</td>
            </tr>
        </tbody>
    @endisset
@endforeach

Or you specifically send whatever data you want to Monthly_statement.tbody

// view.blade.php
<table>
    <tbody>
        @include('Monthly_statement.tbody', ['data' => $someData])
    </tbody>
</table>

//Monthly_statement.tbody
@foreach($data as $vendorName => $details)
    @isset($details['rate'])
            <tr>
                <td>{{ $details['rate'] }}</td>
                <td>{{ $vendorName }}</td>
                <td>{{ $details['total_litres'] }}</td>
                <td>{{ $details['total'] }}</td>
            </tr>
    @endisset
@endforeach

realrandyallen left a reply on Laravel Get Count Items By Status

@DRONAX - You'd have to either do the query again so you can get all the counts, or you can go back to the code you had before (with get()) and then implement this method to paginate a collection:

https://gist.github.com/vluzrmos/3ce756322702331fdf2bf414fea27bcb

17 Jan
5 days ago

realrandyallen left a reply on Laravel Get Count Items By Status

@DRONAX - You could do this instead:

$shops = Shop::where('user_id', Auth::user()->id)->byRating()->paginate(10);

$counts = $shops->groupBy('status')->map->count();

return view('home', compact('shops', 'counts'));

Only difference is your $counts will only be for the 10 records that you've pulled via pagination.

realrandyallen left a reply on Prop 'options' Requires Default Value To Be Set

@JET - Since placeholder is a string you'd have to default it as a string:

placeholder: {
    type: [String],
    default: function () {
        return '';
    } 
}

You could also just make it not required:

placeholder: {
    type: [String],
    required: false,
}

realrandyallen left a reply on Prop 'options' Requires Default Value To Be Set

Give the prop options a default value:

props: {
    options: {
        type: [Array, Object],
        default: {} 
    },
}

realrandyallen left a reply on Error With Office 365 Mail

@ORJIJR - Your MAIL_FROM_ADDRESS should be the same as what you're using for MAIL_USERNAME can you confirm that's what you're doing?

realrandyallen left a reply on Error With Office 365 Mail

My guess is the smtp server doesn't like you trying to override MAIL_FROM_ADDRESS and MAIL_FROM_NAME...try removing them from your .env file and see what happens when you try to send the mail again. I'm thinking Laravel might inject the defaults from your config/mail.php though so the issue might remain.

realrandyallen left a reply on Remove Exception Clutter From My Controller Methods

You could them to Laravel's exception handler and handle them there:

Controller

<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use Stripe\Stripe;
use Stripe\Charge;
use Stripe\Customer;

class StripeController extends Controller
{
    
    public function customerCheck(Request $request) {
        $user = Auth::user();

        if(! $user) {
            return response()->json([
                'user' => $user,
                'message' => 'Registrate para poder realizar la compra'
            ]);
        }

        if(! $user->customerId) {
            return response()->json([
                'user' => $user,
                'message' => 'No hay tarjetas registradas a este nombre'
            ]);
        }


        if($user->stripeCustomerId) {
            Stripe::setApiKey(config('services.stripe.secret'));
               
            $customerSources = Customer::retrieve($user->stripeCustomerId)->sources->all(array("object" => "card"));
    
            return response()->json([
                'customerSources' => $customerSources,
                'message' => 'Elije la forma de pago segura'
            ], 201);
        }

        return response()->json([
            'user' => 'It worked!',
        ]);
    }
}

app/Exceptions/Handler.php

...

use Stripe\Error\Card;
use Stripe\Error\ApiConnection;
use Stripe\Error\InvalidRequest;
use Stripe\Error\Api;
use Stripe\Error\Base;

...

public function render($request, Exception $exception)
{
    if ($exception instanceof ApiConnection) {
        return response()->json([
            'message' => 'Sorry, Network is having trouble. Please try again later.',
        ]);
    }

    if ($exception instanceof InvalidRequest) {
        return response()->json([
            'message' => 'Sorry. One of our programmer forgot to drink their caffein.',
        ]);
    }

    // etc
        
    return parent::render($request, $exception);
}

That gets your exception handling out of the Controller at least, I do agree with @manojow though that the customer check itself shouldn't live in the controller either and should be moved to a Model

realrandyallen left a reply on Vuex Store (state Undefined)

Try these changes:

export const store = new Vuex.Store({ //added export
import { store } from '../Store' //lowercase store, I think Store is a reserved word

computed: {
    items() {
        return store.state.items; // access store directly rather than through vue
    }
},

realrandyallen left a reply on Laravel Get Count Items By Status

@DRONAX - Change this line:

$shops = Shop::where('user_id', Auth::user()->id)->byRating()->get();
16 Jan
6 days ago

realrandyallen left a reply on Reactivity Of Deep Properties

@PK_06 - Seems like it should, have you console.log el to make sure you’re actually getting to the inside of that conditional? Even if you did use this.$set.choices wouldn’t it be this.$set.choices[i].is_answered?

Other than that this is typically an issue of this not being what you’d expect inside your closure, but you’re using an => function so this should be your Vue component

realrandyallen left a reply on Reactivity Of Deep Properties

Does

if (el.choice_id == choice_id) {
    el.is_answered = 1;
}

not work?

realrandyallen left a reply on Laravel Get Count Items By Status

Consider this structure:

$shops = Shop::where('user_id', Auth::user()->id)->byRating();

$counts = $shops->groupBy('status')->map->count();

$shops = $shops->paginate(10);

return view('home', compact('shops', 'counts'));

realrandyallen left a reply on Pass DateTime To Vue Component (countdown Timer)

@TREVORPAN - I think the issue is you're instantiating Vue each time, and re-using #countdown which would have to be unique. This is typical the setup in a Laravel app to use Vue:

resources/js/app.js

require('./bootstrap');

window.Vue = require('vue');

const files = require.context('./', true, /\.vue$/i)
files.keys().map(key => Vue.component(key.split('/').pop().split('.')[0], files(key).default))

const app = new Vue({
    el: '#app' // <- important, your entire app should be contained in a div with that id
});

app.blade.php or some other master template file

<!DOCTYPE html>
<html lang="{{ app()->getLocale() }}" class="h-full">
<head>
    <meta charset="utf-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1">

    <meta name="csrf-token" content="{{ csrf_token() }}">

    <title>{{ config('app.name') }}</title>

    <link href="{{ mix('css/app.css') }}" rel="stylesheet">

</head>
<body>
    <div id="app"> <!-- note the #app which was referenced in app.js -->
        <div >
                 @yield('content')
        </div>
    </div>   

    <script src="{{ mix('js/app.js') }}"></script>

</body>
</html>

Remove these lines from your jobs partial:

<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/vue.js"></script>
<script>Vue.config.devtools = true;</script>
<script>new Vue({el: '#countdown'})</script>

Run npm run dev

realrandyallen left a reply on Pass DateTime To Vue Component (countdown Timer)

@TREVORPAN - The @ symbol in your first block of code was the issue, that tells blade to ignore it and doesn't print the job deadline to the page (assuming it will be handled by some other js framework. However, in this case you do want blade to handle that request so removing the @ fixed the issue.

So inside your jobs.job view you have

<countdown until="{!! $job->deadline !!}" expired-text="This job had been bidded."></countdown>

? If so, then yes, there should be a countdown component for each job, try passing the job to your partial:

@include ('jobs.job', ['job' => $job])

realrandyallen left a reply on Pass DateTime To Vue Component (countdown Timer)

@TREVORPAN - The code you had in the original post actually works fine aside from the couple changes I mentioned - now that vue dev tools is up in running can you see your until prop in the component (in dev tools)?

realrandyallen left a reply on Laravel Get Unique Views

distinct actually doesn't except a column, it will insert whatever column you're trying to count automaticaly. However, I think this is going to generate two queries, this should work:

$shops = DB::table('shops')
        ->selectRaw('shops.*, count(distinct visitor) as visitor_count')
        ->leftJoin('views', 'shops.id', '=', 'views.viewable_id')
        ->where('viewable_type', 'App\Shop')
        ->groupBy('shops.id')
        ->get();

Consider making this scope in your Shop model so it's reusable

realrandyallen left a reply on Pass DateTime To Vue Component (countdown Timer)

@TREVORPAN - Also normal, you should see on the left panel, click that

realrandyallen left a reply on Pass DateTime To Vue Component (countdown Timer)

@TREVORPAN - That's normal to see that in the console, you should be able to click 'Vue' at the top right and see your components, you can click a component and see all the props / data etc. You'll be able to see there if until is being passed to your component

~vue dev tools

realrandyallen left a reply on Get Position In Rating By Scope

@DRONAX - You're welcome :) I think you'll be ok, this is one query now - the old method it would have been a big issue

realrandyallen left a reply on Pass DateTime To Vue Component (countdown Timer)

@TREVORPAN - You should be able to see your component and props in vue dev tools, any errors or anything?

realrandyallen left a reply on Get Position In Rating By Scope

@DRONAX - Try changing your updateRanks function to this:

    public static function updateRanks()
    {
        DB::statement("update users set position = (SELECT FIND_IN_SET( CONCAT(points, '_', created_at), (SELECT GROUP_CONCAT( CONCAT(points, '_', created_at) ORDER BY points desc, created_at desc ) FROM (select * from users) as user_rankings)))");
    }

realrandyallen left a reply on Pass DateTime To Vue Component (countdown Timer)

@TREVORPAN - Ah yeah, you can't use the script tag like that for your Vue components. Vue components are loaded in your resources/js/app.js file. Depending on what version of Laravel you're on you should see this in that file:

const files = require.context('./', true, /\.vue$/i)
files.keys().map(key => Vue.component(key.split('/').pop().split('.')[0], files(key).default))

That will automatically register every Vue component in your resources directory. Alternatively you can manually register your component in that same file:

Vue.component('countdown', require('./components/Countdown.vue'));