wilk_randall

Full-stack Developer at Invizon

Experience

88,420

67 Best Reply Awards

  • Member Since 1 Year Ago
  • 435 Lessons Completed
  • 0 Favorites

17th September, 2018

wilk_randall started a new conversation Modifying URL Search Query With JavaScript • 3 days ago

I am using JavaScript to paginate a data set with ajax, and once the result is returned, I update the query string with the current query by modifying the history.

const replaceQueryString = newQueryString => {
    window.history.pushState(null, '', `?${newQueryString}`);
};

This part works fine and does what I want, which is modifying the string in the URL without actually reloading the page. I want the page to reload when the back button is used so that the previous query can be executed again. Currently the query string does change back to the previous one when I press the back button, but the page does not reload and nothing happens.

Is there something I'm missing here or need to listen to? Or is it just not possible to do this?

wilk_randall left a reply on A Way To Override What Request Data Is Returned When Validating In 5.5? • 3 days ago

Why not just use this for your rules?

$rules = [
    'password' => 'required|min:8|confirmed'
];

Of course you would have to rename your password confirm field to password_confirmation, but it would remove this error.

wilk_randall left a reply on Change Button Color After Ajax Request • 3 days ago

In my opinion, the backend should not know or care about what the frontend does with the UI. It shouldn't be passing back a button color; this should be decided with your JS code depending on the status of the request. To me, passing back the color just couples your backend code with your frontend code when it really shouldn't be coupled that tightly.

16th September, 2018

wilk_randall left a reply on Delete Articles And News With Their Comments • 4 days ago

You can't really use a foreign key for a polymorphic relationship since it could come from different tables. The way I would do it is by using an observer on the model.

class Article extends Model
{
    // ... your model code

    protected static function boot()
    {
        parent::boot();

        static::deleting(function ($article) {
            // replace 'comments' with your relationship name
            $article->comments()->delete();
        });
    }
|

15th September, 2018

wilk_randall left a reply on Php Artisan Migrate Returns Nothing • 5 days ago

Are you sure there are any migrations to run? They should be in the database/migrations directory.

wilk_randall left a reply on Remove Jquery Message • 5 days ago

That's not from jQuery, but from the browser itself. You can easily disable this on a form by adding novalidate to the form tag.

wilk_randall left a reply on Test A User Login From Multi Perspective • 5 days ago

You'll have a much easier time if you use PHPUnit tests.

https://laravel.com/docs/5.7/testing

14th September, 2018

wilk_randall left a reply on How To Foreach This Data • 6 days ago

Use a pivot table, it would make your life a lot easier...

wilk_randall left a reply on Login No Longer Working In Laravel 5.6.28 • 6 days ago

For one, something just doesn't stop working for no reason. You must have changed something that made it stop working. Also, we don't know what your login code is, so how do you expect an answer without providing the code that is not working?

13th September, 2018

wilk_randall left a reply on Nova, Backpack Or Another? • 1 week ago

Like the others have said, you're better off building your own, although it takes more than just some "nav + some css" to make a decent, user-friendly, robust admin panel.

wilk_randall left a reply on Array Flatten • 1 week ago

@andreasbakir - Why would you make a function to do this, when Laravel already provides this for you with what @cronix had suggested? Makes no sense...

wilk_randall left a reply on Pipeline Error • 1 week ago

That is really vague; you need to provide the entire stack trace.

12th September, 2018

wilk_randall left a reply on AXIOS Button More Shows • 1 week ago

You need to add a click event handler to the button that makes an ajax call to your endpoint to load the themes, and then when the response is returned, add them to the DOM.

wilk_randall left a reply on How To Delete After A Given Lapse Period If Status Isnt Updated • 1 week ago

@Melodia - Just an FYI, now() is just an alias in Laravel for Carbon::now()

wilk_randall left a reply on Apis • 1 week ago

Something to the effect of: $collection->paginate(10);

11th September, 2018

wilk_randall left a reply on Vue Problem • 1 week ago

@cmdobueno - this.errors is probably undefined, although it's hard to tell with what has been provided. The check would need to be like this instead:

if (this.errors && this.errors[field]) {
    return this.errors[field][0];
}

10th September, 2018

wilk_randall left a reply on Login After Registeration • 1 week ago

Also, make sure you set this model in the providers array in the config/auth.php file.

wilk_randall left a reply on Login After Registeration • 1 week ago

It's telling you that the user has to be an instance of Authenticatable, so just make sure your user model implements that contract.

7th September, 2018

wilk_randall left a reply on Admin Panel • 1 week ago

If you're willing to pay a little bit of money, I'd recommend looking through the admin templates on themeforest.net

5th September, 2018

wilk_randall left a reply on Why Laravel Dropped Elixir? Why Forcing Vue.js? What Is It That You Are Trying To Fix? • 2 weeks ago

@ruudvangeelen

Really? It works when I do it. I apologize if I came off a little rude; that wasn't my intention. I just find it funny that three developers couldn't figure it out. And let's be honest, it's really not a big deal to see the production tip in the console during development. It goes away once you run npm through production anyways.

wilk_randall left a reply on Why Laravel Dropped Elixir? Why Forcing Vue.js? What Is It That You Are Trying To Fix? • 2 weeks ago

@ruudvangeelen

This took 3 guys at least a few days to figure out what the problem was , and still, it is not solved.

How? Do these developers not know how to research problems? It literally took me less than a minute to find the solution.

Here, let me help you with this: http://lmgtfy.com/?q=vue+disable+production+tip

4th September, 2018

wilk_randall left a reply on 5.7 Requiring Ext-mcrypt • 2 weeks ago

You should probably just install the mcrypt extension

wilk_randall left a reply on Passing A Collection To Vue • 2 weeks ago

To iterate over it in JS, it would be something like:

<div v-for="hours in hoursWorked">
    {{ hours.day }} // or whatever property you  need
</div>

Or in your component code:

this.hoursWorked.forEach(hours => {
    console.log(hours.day);
});

wilk_randall left a reply on Passing A Collection To Vue • 2 weeks ago

Try removing the single quotes you have, and it should just be a normal javascript array of objects now.

<display-hours :day-check="{{ $day }}" :hours-worked="{{ $hours }}"></display-hours>

31st August, 2018

wilk_randall left a reply on How To Remove An Object Inside An Array In Browser Local Storage • 2 weeks ago

@shifoodew - I would say that you need some other kind of identifier that is unique then. Or if you already know the index you can just use it with splice without trying to find it. It's a little difficult to provide a clear answer without knowing how you're actually using the array.

30th August, 2018

wilk_randall left a reply on How To Remove An Object Inside An Array In Browser Local Storage • 3 weeks ago

You could find the index of the object and then use splice to remove it.

// this assumes you know the product id you are removing
const removeProduct = productId => {
    // get products from local storage
    let products = ...

    const index = products.findIndex(product => product.product_id === productId);

    if (index > -1) {
        products.splice(index, 1);
    }

    // store modified array back to local storage.
};

wilk_randall left a reply on Reset Password • 3 weeks ago

I usually use mail trap for local development

wilk_randall left a reply on Posting HTML To Database • 3 weeks ago

I recommend using something like HTML Purfier

27th August, 2018

wilk_randall left a reply on How Do I Test Speed In Laravel? • 3 weeks ago

This package might be helpful:

https://github.com/barryvdh/laravel-debugbar

wilk_randall started a new conversation Laravel-mix Compilation Error From Importing A Class From Node Module • 3 weeks ago

I have a utility class from an npm package I made that I am trying to import into a script I have in Laravel. It makes use of object rest spread (...), and because of that, I am receiving the unexpected token error telling me that I need the appropriate loader. I do have the babel-plugin-transform-object-rest-spread package installed, as well as a .babelrc file created to include it as a plugin, but I still receive the error.

What I find interesting is that if I make an exact copy of the class in my Laravel project and import that file, it compiles just fine. It only seems to fail when I try importing it from node_modules.

The class I'm trying to import can be found here: https://github.com/rawilk/vue-laravel/blob/master/src/js/utils/class/ajax.js

This is how I'm importing it:

// Importing this results in a compilation error
import Ajax from 'vue-laravel/src/js/utils/class/ajax';

// the local class version of this works when imported
// import Ajax from './test';

24th August, 2018

wilk_randall left a reply on Access Result Of Collect(.) Like StdClass • 3 weeks ago

But if you really want this, maybe try this: $a = collect((object) $a));.

I don't know if that will actually work since I didn't test it myself.

wilk_randall left a reply on Access Result Of Collect(.) Like StdClass • 3 weeks ago

I really don't see the big deal in using something like $a['k1']. Why create the extra work for yourself and overhead just because you don't like the syntax?

17th August, 2018

wilk_randall left a reply on Check If ID Exists Then Do Not Display • 1 month ago

You're not providing much info to go on, but here are some examples of this basic task.

In a blade:

@if (! $record->id)
    <button>Your button here</button>
@endif

// Or like this if it is a model instance
@if (! $record->exists)
    <button>Your button here</button>
@endif

In vuejs:

<button v-if="! record.id">Your button here</button>

12th August, 2018

wilk_randall left a reply on Possible Store New Record And Save The Inserted Id In To Same Row Other Column Same Time? • 1 month ago

@newbie360 - You can temporarily disable the timestamps like this:

$contract->timestamps = false;
$contract->doc_path = '2018-01-02__' . $contract->id;
$contract->save();

wilk_randall left a reply on Possible Store New Record And Save The Inserted Id In To Same Row Other Column Same Time? • 1 month ago

The way I would do it is with an observer. I would listen to the created event on your model and insert a value into that column like this:

// On your contract model
public static function boot()
{
    parent::boot();

    static::created(function ($contract) {
        $contract->update(['doc_path' => '2018-01-02__' . $contract->id]);
    });
}

wilk_randall left a reply on Automated Supervisor Install/configure Bash Script • 1 month ago

I did implement some changes to my script based off that thread, but I think the real issue was with the server. I tried the script on a fresh server setup and it worked just fine.

9th August, 2018

wilk_randall started a new conversation Automated Supervisor Install/configure Bash Script • 1 month ago

I have a CentOS 7 server and I wrote a bash script to install and configure supervisor automatically for you and optionally run migrations for the job tables. Everything works fine, except for the part that starts the supervisord service.

The script I'm using can be found here: https://github.com/rawilk/new-server-setup/blob/master/bash-scripts/laravel-queues.sh

When the script runs and gets to the part where it is supposed to start supervisord, it outputs the following error:

Failed to start supervisord.service: Unit not found.
error: <class 'socket.error'>, [Errno 2] No such file or directory: file: /usr/lib64/python2.7/socket.py line: 224
error: <class 'socket.error'>, [Errno 2] No such file or directory: file: /usr/lib64/python2.7/socket.py line: 224
unix:///var/run/supervisor/supervisor.sock no such file

What I find interesting about this is that if I run systemctl start supervisord after I run this script, it starts up just fine.

27th July, 2018

wilk_randall left a reply on Stream PDF Bytes To Browser • 1 month ago

Try this package: https://github.com/barryvdh/laravel-dompdf

It's very easy to use.

26th July, 2018

wilk_randall left a reply on Casting To Boolean • 1 month ago

@pilat - Did you even cast it on your model? I've always been able to do something like $user->is_admin === true when using $casts on the model.

wilk_randall left a reply on Accept Http And Https • 1 month ago

Why? IMO it's better to have all endpoints secured instead of only some of them.

wilk_randall left a reply on Controller Trying To Return Some JSON Data So My View Can Use It. • 1 month ago

@seamuswc - It's actually helpful if you explain what you're trying to do, not just show code and expect people to guess.

As far as your problem is concerned, try this instead:

return response()->json(['usd' => $usd]);

wilk_randall left a reply on Inserting Data Each Month Automatically • 1 month ago

Sounds like you need scheduled commands:

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

12th July, 2018

wilk_randall left a reply on How To Allow User To View Only And Restrict User Perform Action In Certain Page? • 2 months ago

Sounds like you need roles and permissions. There are a few packages out there already that can help you with this that I suggest looking at:

https://github.com/spatie/laravel-permission

https://github.com/JosephSilber/bouncer

wilk_randall left a reply on Adding Row To Another Table On Create Of New User • 2 months ago

Instead of calling employee() on the controller like it looks like you're doing, you need to call it on the user that was just created instead.

$user->employee()->create();

Laravel will automatically insert the user_id for you when called like this, so the only data you would need to pass to the create method would be any columns you have on the table that need to be filled.

wilk_randall left a reply on How To Some White Space Before The Text • 2 months ago

@LaraStorm - That's not going to do anything useful. Like mentioned above, it would be much better to use CSS to add margin or padding instead. Plus, it's (IMO) a much cleaner and manageable solution.

wilk_randall left a reply on How To Change Login Url • 2 months ago

I agree that obscurity is not security. Also, you don't need to call auth()->attempt() twice like you are. Your function could be re-written like this:

public function login()
{
    if (auth()->attempt(request(['username', 'password']))) {
        return redirect('/pending');
    }

    // login was not successful
    return redirect('/bluelogin');
}

27th June, 2018

wilk_randall left a reply on Retrieve Username Based On Id In Users Table • 2 months ago

If you create a classroom like this, you will have the id and then you can do whatever you need to with it:

$classroom = Classroom::create($data);

dd($classroom->id); // would give you 1 if it's the first record

wilk_randall left a reply on Retrieve Username Based On Id In Users Table • 2 months ago

@geekshubh - So you're attaching a class room to the user? If so and you have your relationship set up correctly, it would be something like this:

public function store(Request $request)
{
    // find the user and attach selected class room to user
    $user = User::find($request->id);
    $user->classrooms()->attach($request->classroom_id);
}

I'm not really sure if that's going to help you though; you didn't give much information about it. If you haven't read the documentation on it, I think it might help: https://laravel.com/docs/5.6/eloquent-relationships

26th June, 2018

wilk_randall left a reply on Cleaning Up A Method • 2 months ago

One thing I would maybe do is move the logic of uploading the cover_image to the model itself. I would also add an observer method to the model for setting the approved attribute.

// Your post model
class Post extends Model
{
    protected $guarded = []; // for mass assigning in the controller

    public function setCoverImage($file)
    {
        // your logic for storing the file

        // then update the model (variables come from your logic)
        $this->update(['cover_image' => $fileName, 'thumb_image' => $thumbnailpic]);
    }

    public static function boot()
    {
        parent::boot();

        static::creating(function ($post) {
            $post->approved = auth()->user()->type == 'admin' ? '1' : '0';
        });
    }
}

With that in your model now, your controller method could be something like this:

public function store(PostRequest $request)
{
    // Create post
    $post = new Post([
        'title' => $request->input('title'),
        'url' => $request->input('url'),
        'slug' => str_slug($request->input('title')),
        'body' => $request->input('body'),
        'user_id' => auth()->id(),
    ]);

    // Set cover image if set
    if ($request->hasFile('cover_image')) {
        $post->setCoverImage($request->file('cover_image'));
    }

    return redirect('/')->with('success', 'Post Created');
}
Edit Your Profile
Update

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