topvillas

Experience

186,295

216 Best Reply Awards

  • Member Since 3 Years Ago
  • 468 Lessons Completed
  • 0 Favorites

20th August, 2018

topvillas left a reply on Remove And Edit Dynamic Rows • 1 day ago

You'll need to use some javascript to store the state and submit it when the use is done.

18th August, 2018

topvillas left a reply on Darryldecode Cart Share Cart In All Views • 3 days ago

Yeah, it will solve the issue. If you bind a singleton, you'll have access to the cart throughout the entire app.

topvillas left a reply on Darryldecode Cart Share Cart In All Views • 3 days ago

Don't put random stuff in your routes file.

Create a service provider and put the logic in there.

17th August, 2018

topvillas left a reply on Use ClientRef Value When Sending SMS With Nexmo • 4 days ago

The examples in the left hand panel shows you how to send a request in PHP.

16th August, 2018

topvillas left a reply on Org Chart Library • 5 days ago

We have no idea what you might find visually appealing.

topvillas left a reply on Form Patch Submit Only Returning Last Record Of @foreach In Form • 5 days ago

You're them all the same name (and id). Use name="name[]" if you want something to be posted to PHP as an array.

14th August, 2018

topvillas left a reply on Trying To Save Data To The Database Throws Error! Did It Like In The Video Shown! • 1 week ago

Looks like your route model binding hasn't worked. Check that.

13th August, 2018

topvillas left a reply on Should I Be Using Models In Lumen? • 1 week ago

I don't think it really matters. Unless you're writing raw SQL, you're using the QueryBuilder. When push comes to shove, Eloquent models are just a convenient way to deal with your entities.

Don't quote me but I really don't think it matters, speed wise.

topvillas left a reply on How To Get This Job Done? • 1 week ago

Yeah, use the build in auth system.

You'll have to tell us what sort of help you need.

12th August, 2018

topvillas left a reply on Create New Columns In A Select SQL Statement Using A Condition • 1 week ago

Don't try and put columns that don't exist in your SQL.

Loop over the results and do the additional processing there.

foreach ($users as $user) {
    if ($user['profession'] == 'Engineer') {
        $contractType1 = 'yes';
        $contractType2 = 'no';
    } else {
        $contractType1 = 'no';
        $contractType2 = 'yes';
    }

    $user['contractType1'] = $contractType1;
    $user['contractType2'] = $contractType2;
}

topvillas left a reply on My Create This Code But Its Not Looking Good • 1 week ago

Why do you need the non breaking spaces?

11th August, 2018

topvillas left a reply on Routing Issue • 1 week ago

That's the solution, for now.

But what are you going to do if you want to add another wildcard route in the future and you insist on sticking to your current pattern?

You should seriously think about this pattern before you get too far down the road.

10th August, 2018

topvillas left a reply on Trying To Get Property 'name' Of Non-object • 1 week ago

$user-twitter isn't an object.

9th August, 2018

topvillas left a reply on Make Execution Wait For Axios Call To Finish • 1 week ago

then doesn't stop the function from continuing, it just calls the lambda when a promise is returned from axios.

topvillas left a reply on Laravel-mix And Vue.JS • 1 week ago

No, you can remove them except cross-env, laravel-mix and vue.

topvillas left a reply on I Feel Like I Misunderstood Routing • 1 week ago

There isn't a right or wrong way to name your routes. Just do what you're happy with.

Seriously, stop sweating stuff like this. You'll find far bigger things to worry about.

topvillas left a reply on How To Send .php File When Post Call In Laravel • 1 week ago

You should read up on MVC at least.

8th August, 2018

topvillas left a reply on How To Print Province Name Using Province_id In Laravel 5.6 • 1 week ago

Maybe wait for more than fifteen minutes before moaning that nobody's solved your problem for you.

topvillas left a reply on How To Use Dependency Injection In A Class With Static Functions? • 1 week ago

If your static function relies on state then it shouldn't be static.

topvillas left a reply on Using Factories For Non-Eloquent Entities • 1 week ago

Thanks @bobbybouwmann

In the end, I just wrote a simple helper function to do what I was trying to achieve in the factory.

7th August, 2018

topvillas started a new conversation Using Factories For Non-Eloquent Entities • 2 weeks ago

An interesting problem you might be able to help me out with ...

I have an abstract currency class

abstract class Currency
{
    protected $code;
    protected $name;
    protected $symbol;

    public function code() : string { return $this->code; }
    public function name() : string { return $this->name; }
    public function symbol() : string { return $this->symbol; }
}

And several classes that extend it

final class USD extends Currency
{
    protected $code = 'USD';
    protected $name = 'United States Dollars';
    protected $symbol = '$';
}

I'm trying to create a factory to generate a random currency (based on the enum CurrencyCodes)

$factory->define(Currency::class, function (Faker $faker) {
    $currencies = CurrencyCodes::keys();
    $code = array_rand($currencies);
    $currency = app()->make("Currency\Currencies\" . $code);
    
    return $currency;
});

But, of course, it tells me that it cannot instantiate the abstract class Currency. I don't really even know if this is even possible with non-eloquent entities. Should I write my own factory class to produce what I need for testing?

topvillas left a reply on Models Within Models Directory • 2 weeks ago

Just include the path on the model name ...

php artisan make:model Models\MyModel

6th August, 2018

topvillas left a reply on Universal Deletion Route • 2 weeks ago

Because your controller will become a bloated mess.

topvillas left a reply on Universal Deletion Route • 2 weeks ago

No.

5th August, 2018

topvillas left a reply on Buy A File In Laravel • 2 weeks ago

Please try and rephrase the question.

topvillas left a reply on Testing Cookie Before Response • 2 weeks ago

Thanks for the pointers, @Cronix

But am I really wasting my time with this test? If the unit is simply calling already tested framework functionality, should I not bother testing the outcome of the api call and leave things for a feature test?

topvillas left a reply on Testing Cookie Before Response • 2 weeks ago

You might right @Cronix, but what I'm trying to test is that what's been queued up to be sent in the cookie corresponds to the currency that was passed in. Rather than if the cookie is actually queued up.

topvillas left a reply on Testing Cookie Before Response • 2 weeks ago

Thanks @bobbybouwmann but that doesn't quite cut it. I want to check if the cookie has been queued up for the response. Rather than checking an actual response from a request.

The class is part of the API of a layered structure and so isn't called directly with an HTTP request.

topvillas started a new conversation Testing Cookie Before Response • 2 weeks ago

I'm trying to test if a cookie has been queued up and it's making my brain hurt!

Here's what I'm trying to unit test ...

class SetUserCurrency
{
    public function using(Currency $currency) : Currency
    {
        session(['currency' => $currency->code()]);
        cookie()->queue('currency', $currency->code(), config('cookie.month'));

        return $currency;
    }
}

How would I test if the cookie has been queued?

4th August, 2018

topvillas left a reply on Brevity Is The Essence Of Wit! • 2 weeks ago

Yeah, I do like to stick it to the man!

It's important to know what standards you're ignoring.

I watched an interesting talk by Bob Martin about how software is one the few industries that isn't regulated. Amazing thought, as our lives are controlled by it in almost every way.

They'll come a day when my petty dislikes will be regulated.

topvillas started a new conversation Brevity Is The Essence Of Wit! • 2 weeks ago

I've recently taken to leaving the public access modifier off of function declarations, as it's the default.

I find it much more pleasing to the eye to not have crap hanging about that isn't needed.

As PHP can be pretty verbose, does anybody else have their own habits or tricks to try and cut down on the code they have to look at everyday?

topvillas left a reply on Wordpress To Laravel • 2 weeks ago

You can't just turn a Wordpress site into a Laravel app with a few simple steps.

Wordpress is a publishing framework and Laravel is an app development framework.

You're going to have to learn Laravel from scratch before you do anything ...

https://laracasts.com/series/laravel-from-scratch-2017

3rd August, 2018

topvillas left a reply on Api Requests • 2 weeks ago

topvillas left a reply on DISPLAY Data In Laravel Blade. • 2 weeks ago

Your $response looks like an array. You'll have to loop over it to get access to it;s elements.

topvillas started a new conversation Comparing Password Hashed In Laravel 4.2 • 2 weeks ago

We have an old Laravel 4 application and we're currently writing some API services using Lumen which access it's database.

Everything is going well but there's a snag. While writing a login system using JWT comparing passwords hashed with Laravel 4.2 using Lumen 5.6 doesn't seem possible.

Does anyone know of a way around this?

31st July, 2018

topvillas left a reply on How To Use Both Mysql And Mongodb In Laravel Project? • 3 weeks ago

No, of course it's not official. But that isn't a reason not to use it.

topvillas left a reply on Probability Of Same UUID • 3 weeks ago

About the same as winning the lottery then being hit by an asteroid during the zombie apocalypse .

29th July, 2018

topvillas left a reply on Chunk Returns Empty Array • 3 weeks ago

Yeah, that would work if you were working directly on the Eloquent collection.

topvillas left a reply on Chunk Returns Empty Array • 3 weeks ago

chunk doesn't take a closure as a parameter.

Read the docs.

https://laravel.com/docs/5.6/collections#method-chunk

topvillas left a reply on Chunk Returns Empty Array • 3 weeks ago

It returns nothing because your dumping in the closure.

topvillas left a reply on Need To Learn How To Make Middleware Auth For Admin • 3 weeks ago

What ideas have you had so far?

topvillas left a reply on How To Achieve This Route? • 3 weeks ago

Format your code so we can see what the link looks like.

28th July, 2018

topvillas left a reply on Storing (Days) In Database • 3 weeks ago

You don't store the day. Just use a datetime type, use the dates array in your model and use Carbon to format the date,

26th July, 2018

topvillas left a reply on Controller Trying To Return Some JSON Data So My View Can Use It. • 3 weeks ago

No, the word 'trying' does not imply that the return statement is not working.

Good luck fixing it,

topvillas left a reply on Controller Trying To Return Some JSON Data So My View Can Use It. • 3 weeks ago

Oh, ok. Good luck fixing it.

topvillas left a reply on Controller Trying To Return Some JSON Data So My View Can Use It. • 3 weeks ago

Do you have a question?

25th July, 2018

topvillas left a reply on How To Write General Query In Laravel Format • 3 weeks ago

The select method on an Eloquent model accepts a list of fields not SQL statements.

You'd be better off using the query builder for this.

https://laravel.com/docs/5.6/queries

24th July, 2018

topvillas left a reply on Explanation Of Why Save Method Is Not Working • 4 weeks ago

Use first OR get.

First will return a model and get will return a collection.

Edit Your Profile
Update

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