wilk_randall

wilk_randall

Member Since 1 Year Ago

Experience Points 160,060
Experience Level 33

4,940 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 576
Lessons
Completed
Best Reply Awards 114
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 May
1 day ago

wilk_randall left a reply on Auth::user() Not Returning All Elements

You're using ['admin'].includes(user.username). Shouldn't it be ['admin'].includes(user.role)?

wilk_randall left a reply on Ajax Validation Server Side - Conslusions?

As a rule of thumb, you should never trust user input, so even with ajax requests you should be doing server-side validation. I personally also do client-side validation via JavaScript, but that in my opinion is optional, but at a minimum you should have server-side validation in place.

wilk_randall left a reply on Want To Redirect Others Route When Error Occur For Code Or Syntax Fault

I agree with the others. You should really focus on fixing your code instead.

19 May
4 days ago

wilk_randall left a reply on Where Correct Word

@jlrdw Yea that's what I meant which is why I said "not case sensitive". I agree that people should read documentation, but it's unrealistic to expect everybody to read the docs.

wilk_randall left a reply on Where Correct Word

Mysql selects are not case sensitive by default, so what you are getting is correct. You can use BINARY in laravel if you use a DB::raw. Here is an example I found on stack overflow.

Invite::where(DB::raw('BINARY `token`'), $token)->first();

wilk_randall left a reply on Slug

I suggest using https://github.com/spatie/laravel-sluggable. It's pretty easy to setup and use.

17 May
6 days ago

wilk_randall left a reply on Best Practice For Display Current User Information

For me, I like to avoid queries in a blade whenever possible but I think it's really a preference thing when it's for something for the authenticated user. If it were me, I would query in the controller and send the data down to the view.

wilk_randall left a reply on How To Get Count From Select Query ?

DB::table('table')->where('number', 'LIKE', '%aa%')->count();
16 May
1 week ago

wilk_randall left a reply on Prevent Site Going Down When Route Does Not Exist

@chilitomato If you use GIT you can setup automatic deployments when you push to a branch and after the code is pushed you can have a script automatically run. That way nobody even has to remember to run it. You're making things much harder than they need to be.

wilk_randall left a reply on Prevent Site Going Down When Route Does Not Exist

To me, this just seems completely unnecessary. Just make a deployment script that runs php artisan route:cache during deployments automatically for you and you won't have that problem.

14 May
1 week ago

wilk_randall left a reply on Updating Database Structure

This is kind of a broad question, but basically I would export the current data to something like json or a .csv file, write an import handler to handle converting the data into the new table structure, migrate the database, then run the import process.

10 May
1 week ago

wilk_randall left a reply on Encrypted Value In .env

but I don't like it that anyone who uses my computer can easily get my password.

Sounds like you should focus on securing your computer instead.

09 May
2 weeks ago

wilk_randall left a reply on Open Local Folder In Finder/explorer From Laravel Web App

Just put it on the server. Why make things more complicated than they need to be

07 May
2 weeks ago

wilk_randall left a reply on Can Forge Provision Non-Laravel Sites

You can add whatever you want to a forge server. It doesn't matter if the repo is a laravel repo or not.

06 May
2 weeks ago

wilk_randall left a reply on Struggling With Image Submission From Vue To Laravel

@chrisgrim I've had the same issue using sending an image via FormData using a Patch request. I'm not sure if it's Laravel specific but it seems to not be able to handle that through PUT/PATCH requests. I changed mine to a POST request and it worked just fine.

If there's some kind of solution out there I'd be glad to here it, but as far as I know you need to change to a POST request for it to work.

wilk_randall left a reply on Changing Queue Driver

@cronix Sorry for late reply, but yes I did delete the existing one.

For now, I just deleted the beanstalkd queue worker I made and reverted back to database queues until I decide to try again with a different driver.

wilk_randall left a reply on Can Not Add A Foreign Key

To go along with what @edoc said, you also can also define your foreign key in the same closure as the rest of the schema and not in a separate one like you have shown.

Also not really sure why @munazzil is talking about the model here as it has nothing to do with the migrations, plus I'm pretty sure id is the default for $primaryKey and you wouldn't want to set $incrementing to false in the majority of cases that you use an integer as your primary key. Then again, I don't really know why @munazzil says half of the things he says.

wilk_randall left a reply on Can I Flexible Change Function Name In Javascript?

I would return a Promise. That way you can handle success in .then and error in .catch and you don't have to pass in a callback function.

Also, just personal preference here, but if you only have 2-3 parameters I would just define them in the function definition instead of using arguments.

24 Apr
4 weeks ago

wilk_randall left a reply on Changing Queue Driver

@beebmx I did restart the queue. I also deleted the database worker as well but it's still pushing jobs to the database table.

22 Apr
1 month ago

wilk_randall left a reply on Fetch Array Values Without Index Values

array_values($array);

wilk_randall started a new conversation Changing Queue Driver

I'm using Forge to manage a client's server and originally I set it up to use database as the queue driver. I've tried changing it to the beanstalkd driver, but for some reason Laravel is still pushing jobs to the database table, and as a result they aren't being processed.

Here's what I've done:

  • Installed pda/pheanstalk
  • Create new beanstalkd queue worker on forge
  • Updated QUEUE_CONNECTION to beanstalkd in the .env file
  • Re-cached my config (php artisan config:cache)
  • Cleared application cache (php artisan cache:clear)
  • Even restarted queues (php artisan queue:restart)
  • Checked that Beanstalk is running on the server (systemctl status beanstalkd)

I'm not sure what else I could do to get this to work. Anything that gets queued in the application just implements the ShouldQueue interface, so it's not like the queue driver is hard coded anywhere in my code.

18 Apr
1 month ago

wilk_randall left a reply on WHERE On Multiple Columns

This might be a little overkill in your case, but it's definitely useful for handling dynamic queries: https://github.com/Tucker-Eric/EloquentFilter

17 Apr
1 month ago

wilk_randall left a reply on Auth::user() Returns Null Value

You can't access the authenticated user or the session data through a controller's constructor anymore. I don't see why you would need to anyways. Just access them in the controller method itself.

You can read more about it here:

https://laravel.com/docs/5.3/upgrade#5.3-session-in-constructors https://laracasts.com/discuss/channels/laravel/cant-call-authuser-on-controllers-constructor

wilk_randall left a reply on Cloning My Project , NPM Is Not Rendering All The Js Code Properly

@munazzil Would you please stop giving people terrible advice?

15 Apr
1 month ago

wilk_randall left a reply on Interact With Vue From Vanilla Js

Another way is to use portal-vue, which I also feel is a cleaner solution.

08 Apr
1 month ago

wilk_randall left a reply on Laravel Install Shared Web Hosting

You can but you're better off using a vps hosted through a service such as linode or digital ocean if you're able to.

wilk_randall left a reply on Laravel Date Error

@munazzil Seriously? toArray() gives you an array, not a collection. I mean it's even in the name... And also, Carbon is not a collection, so it won't have that method anyways.

05 Apr
1 month ago

wilk_randall left a reply on Passing Two Variables Through A Route

change it to an array:

ajax: '{{ route('this.conditions-datatable', ['variable_id' => $variable->id, 'boolean' => true]) }}'
04 Apr
1 month ago

wilk_randall left a reply on How Do I Give Access To One User (admin) To View All Other Peoples Projects?

For one, you should probably change href="{{ $project->id }}" to href="{{ $user->id }}". Then in your controller, you could do something like this:

public function records(User $user)
{
     // this assumes your user model has a relationship called "projects" on it
     $projects = $user->projects;
     dd($projects);
}

wilk_randall left a reply on How Do I Give Access To One User (admin) To View All Other Peoples Projects?

Just add it to the data you're sending already:

public function adminforms(Project $project)
{
    $users = User::get();

    return view('smiledesign.adminforms', compact('users', 'project'));
}

wilk_randall left a reply on How Do I Give Access To One User (admin) To View All Other Peoples Projects?

You're missing the $ on your variable, which is why you have the error you do.

Try this

<a href="/smiledesign/{{ $project->id }}/records>{{ $user->name }}</a>

wilk_randall left a reply on How Do I Give Access To One User (admin) To View All Other Peoples Projects?

It depends on how you identify a user as an admin. For example, if you had a method called isAdmin() on your user model, you could do something like this on the policy:

public function view(User $user, Project $project)
{
      if ($user->isAdmin()) {
           return true;
      }

      return $project->user_id === $user->id;
}

Or to prevent having to do that in all your policy methods, you could is Gate::before() to check if the user is the admin:

Gate::before(function ($user, $ability) {
    if ($user->isAdmin()) {
        return true;
    }
});

More info here: https://laravel.com/docs/5.8/authorization

wilk_randall left a reply on How Can I Use A Singular Form For Both ``create`` An ``edit`` .

I usually pass the object in as a prop and then create a new property on the component based on what is passed in, like this:

props: {
     dataUser: {
         type: Object,
         default: () => ({})
     }
},

data () {
    return {
         user: { ...this.dataUser } // this will work for both create and edit
    };
}

Also, you typically use an object instead of an array for the data model, which I have shown in my above example.

01 Apr
1 month ago

wilk_randall left a reply on How To Print All Data Of This JSON-structure?

@cronix I understand that. Usually I just want to see the first object, so I use dd, but of course dump would be used if you wanted to see them all.

wilk_randall left a reply on Can Not Use Variable Outside Of If Statement

@pickab00 you should still initialize $push before the conditional like many others above have told you to. If that conditional fails you're going to run into the same issues with the variable not being defined. But if the conditional always evaluates to true, then why do you even have it?

wilk_randall left a reply on How To Print All Data Of This JSON-structure?

First of all, I would decode it like this so it's an array: $resp_json = json_decode($response, true);

Then you could iterate through the data property to do what you need with each object

foreach ($resp_json['data'] as $object) {
     // do something with the object
     dd($object);
}
29 Mar
1 month ago

wilk_randall left a reply on Upload A Queue With Data From One Form At The Same Time.

Do it like this instead:

const formData = new FormData();
formData.append('file', this.file);

Object.keys(this.form).forEach(key => {
    formData.append(key, this.form[key]);
});

axios.post('/projects/store', formData)
     .then(this.onSuccess)
     .catch(this.onFailure);

wilk_randall left a reply on Upload A Queue With Data From One Form At The Same Time.

You will need to add each key of your form to the form data object

Object.keys(this.form).forEach(key => {
    formData.append(key, this.form[key]);
});

wilk_randall left a reply on How Do I Avoid Showing End Users The Laravel Error Page?

When you deploy the application, you will set these values in your .env file:

APP_ENV=production
APP_DEBUG=false

Doing that will disable the whoops error screen

wilk_randall left a reply on Best Data Table Approach With Laravel And Vue

I use the tables from bootstrap-vue. They are very powerful and can do everything you need them to do.

27 Mar
1 month ago

wilk_randall left a reply on Referring The Json Data To Html Template | Laravel

As far as I know, it's not possible with jQuery. If you use a data driven framework like Vue, you would be able to remove the html from your ajax call.

wilk_randall left a reply on Dynamically Creating A Button With A URL

Something like this:

@foreach($subjects as $subject)
     <a href="/target/targetView/{{ $subject->name }}">Edit</a>
@endforeach

wilk_randall left a reply on Possible To Use Multiple Mailgun Domains?

The changes you make to the config like that are temporary, so you should only need the line config()->set('services.mailgun.domain', 'mg.domain2.com');. Once your request is finished, the config value will be back to the original value again.

26 Mar
1 month ago

wilk_randall left a reply on About Importing A Javascript Function From Ther File

A better way would be to use a mixin. You could do something like this:

Mixin File

export default {
     methods: {
          parsedDate(usedDate) {
              return Vue.moment(usedDate).format('D/M/YYYY -  HH:mm:ss');
          }
     }
}

Component

import parsedDate from '../../../config/dates.js';

export default {
     // add this line in your component
     mixins: [parsedDate]
}

wilk_randall left a reply on What's The Best WYSIWYG

There's a bunch of them out there.

Some include:

Google wysiwyg editor and you'll find plenty of others to try.

25 Mar
1 month ago

wilk_randall left a reply on Laravel Constructor - How To Use It Correctly?

I agree with @salmon. Typically you pass variables to your controller methods either through the Request object, route parameters, or route model binding (which is still route parameters). Typically, at least for me, you use the constructor in a controller for dependency injection.

wilk_randall left a reply on Cronjob

File::put('path/to/file.json', $contents);

Change .json to whatever file extension you're using.

wilk_randall left a reply on Cronjob

dd($result->getBody()->getContents());

That should show you what was returned from the api. From their, you can process and persist the data how you need to.