arthurvillar

arthurvillar

Member Since 1 Year Ago

Experience Points 36,660
Experience
Level
Lessons Completed 222
Lessons
Completed
Best Reply Awards 22
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.

25 Apr
8 months ago

arthurvillar left a reply on Make A Foreach With A JSON Array

"Json Array" does not exist in the practical sense. Think of Json as just a string of text that looks like an object or array. For that reason, it is ready to be used as such when converted (decoded).

arthurvillar left a reply on Filtering Relationships By Other Relationships

Well, you are always fetching all the records in order to filter them after. It will drag if you have a large database.

23 Apr
8 months ago

arthurvillar left a reply on Filtering Relationships By Other Relationships

I would try something like this

class Category extends Model
{

    public function scopeProductsWithCategory($query, $category) {  
        $query->whereHas('products', function($q) {
            $q->whereHas('categories', function($q) {
                return $q->where('id', $category->id);
            });
        });
    }

}

// On a controller you could then use
$categoryOne->productsWithCategory($categoryTwo);
19 Mar
10 months ago

arthurvillar started a new conversation Campaign Monitor With TDD

Does anybody know if I can run tests for emails with Campaign Monitor? @bashy I saw that you have a Laravel wrapper for Campaign Monitor (which looks great!), is there a way to include emails sent through them in my tests?

16 Mar
10 months ago

arthurvillar left a reply on How To Update The Application After Updating Files?

@behnampmdg3 you have two good answers here. Please mark this discussion as solved.

arthurvillar left a reply on Trying To Get Property Of Non-object Sending Data To The View

The method find() only works with ids, not slugs (even if you specified to use it on the model class).

The only time you are trying to access a property (which the error says it's failing) is on $conf->id, so the problem is with your variable $conf which is null.

You can quickly resolve the issue by doing

$conf = Conf::where('slug', $slug)->get();

// or pass an actual id

$conf = Conf::find($id);

arthurvillar left a reply on Unable To Upload Video File

This code is never being reached, so you can't know if it causes errors or not. But by looking at it, I wonder where does the method move() comes from. Looks like $vid is an instance of your video class, so do you have that method created in there right? If not this will fail for sure.

arthurvillar left a reply on Unable To Upload Video File

Try creating the form without using these helpers from Laravel. Create the actual tag with correct attributes and inputs. It will look like this

<form method="POST" action="/your-route-here" enctype="multipart/form-data">
<input type="file" name="Upload_video">
<input type="submit" value="Upload Video" name="submit">
</form>

ps: please use the proper format to post code here, it is very difficult to read it otherwise.

arthurvillar left a reply on Architecture For A Platform Like Shopify

This is a huge question you are asking. Architecture and process means pretty much the entire development of your project. I would recommend you many of the series in here. They cover almost everything you would need to get your project off the ground, but you do need to do your homework. Here are the ones I recommend:

Laravel 5.4 From Scratch Let's Build A Forum with Laravel and TDD How to Manage an Open Source Project How to Accept Payments Whatcha Working On

arthurvillar left a reply on Unable To Upload Video File

This error is telling you exactly what is happening: the if($request->hasFile('Upload_video') returns false, so all the logic within it never runs. The next line that runs is $vid->save(), which is adding only the created_at and updated_at. Laravel adds those automatically behind the scenes every time you insert anything new into your table.

Looks like you don't have enctype="multipart/form-data" in your form tag on the view file. If you don't have that the file will never reach the controller. Your form tag should look like this

<form method="POST" action="/your-route-here" enctype="multipart/form-data">
11 Mar
10 months ago

arthurvillar left a reply on Would Love To Hear Your Tips For A Good Payment System

There are many online payment services out there, but you should really take into consideration how much documentation you will find to help implementing the service you choose.

Laravel provides integration with Braintree and Stripe out of the box. Take a look at the docs here.

I have never used Braitree, but I read that they charge an additional 1% for international currencies, while Stripe does not. You can find a full comparison article here.

Finally, the simple fact that there are great videos right here about implementing Stripe, I would definitely go with that option. Unless you have good experience working with these APIs, they can get tricky sometimes. You should checkout the course Stripe Checkout. This one is not only about subscriptions, but also about single payments, which is closer to what you need.

07 Mar
10 months ago

arthurvillar left a reply on Refactoring A Project Update

The number of if/else in this code is gigantic, and that is a terrible design for obvious reasons. One should never let the code reach this point, for now it is just painful to refactor. You need to try out different designs and choose which one works better, there are multiple options.

The first thing you need to do is get rid of all the if statements from the largest to the smallest. Start by creating one class for each large condition and put that large sequence of updates in their classes. Keep the conditionals, just send each one to their designated class. Like this

if (Entrust::hasRole(['rprm'])) {
    NewClass::handle($request, $project);
} else if (Entrust::hasRole('rper')) {
    AnotherNewClass::handle($request, $project);
} else {
    YetAnotherNewClass::handle($request, $project);
}

This already looks better. The new classes will still look messy, so a second step I would take would be to find what is common between these new classes I just made and create a parent abstract to handle the incoming request, so that you can remove these conditionals entirely.

arthurvillar left a reply on Directly Loop A Relationship

When you run $Users = User::someCategory()->get(); you get a collection in return. Check here for the many helpers Laravel gives you to use with collections. You can use a simple each in this case

$Users->each(function($user){
    $user->transactions->each(function(){
        // Your transaction is here
    });
});

arthurvillar left a reply on Redirect User When The Db Is Empty

This is solved by creating a custom middleware. I'ts very simple, just read the docs here.

04 Mar
10 months ago

arthurvillar left a reply on Custom Redirect To Validation Fail On A Registration Form

Thanks @Snapey , both are good ideas! Maybe I'm just being too picky about this.

arthurvillar left a reply on Pushing A View Section Onto Stack Once

What a great solution, I never thought of it! I will use this on my projects too.

arthurvillar left a reply on Custom Redirect To Validation Fail On A Registration Form

Problem solved! The issue was created because I have to use a modal for login and needed to redirect to a login page instead of back and show the modal. I overrode the $redirectTo to /login on validation exception and sure enough all validation fails were going there.

I just found this answer on StackOverflow that solved the problem. I now have $redirectTo pointing to /register and I added the sendFailedLoginResponse method on the LoginController to override the natural redirection.

Do you think this is a decent way of doing this, or am I creating a bigger issue here for no reason? The client wants the modal for login but I don't like to have the browser going back and automatically opening the modal for fails, it just feels weird.

arthurvillar left a reply on Pushing A View Section Onto Stack Once

I see! Yeah, I don't think your solution is possible because the @captcha directive will always load the @push and you can't have some @if statement in there.

The only solution I can think of is to save a Session with a unique id (one for every page load) and inside the directive you can check on that session to see if the script was loaded or not, but I don't think this is a very elegant way to go about it. I would just add the script manually in this case.

arthurvillar left a reply on My Login System Not Working

None of your inputs have names. For example, the <input required class="form-control" placeholder="" type="email" id="email"> must have the attribute name="email".

This is what the inputs should look like

<input required class="form-control" placeholder="" type="email" id="email" name="email">
<input required class="form-control" placeholder="" type="password" id="password" name="password">

arthurvillar left a reply on Pushing A View Section Onto Stack Once

Why don't you include the <script src="https://www.google.com/recaptcha/api.js"></script> directly on the head of the main layout view? If you are using @extends on your views than you have a main layout view that can have that script at all times.

arthurvillar left a reply on Custom Redirect To Validation Fail On A Registration Form

It's a very recent built of Laravel 5.5. The validation on register redirects to /login, and I just want it to go back to the register view. Login redirects point to the login view, which is correct.

The class Illuminate\Validation\ValidationException has the $redirectTo property set to /login. If I override that to /register it works but then when a login fails it now goes to the register view, which makes no sense. This seems like such a weird issue...

arthurvillar left a reply on Custom Redirect To Validation Fail On A Registration Form

Thanks for the reply @yamin27 , but I still want to use the resources for registering a user that come with Laravel. I just don't want to create all the connections myself just to have a different redirect.

03 Mar
10 months ago

arthurvillar left a reply on Laracasts - Email On New Series?

@robm89 please mark this discussion as solved, thanks!

arthurvillar started a new conversation Custom Redirect To Validation Fail On A Registration Form

I just noticed that if a visitor fills out the registration form but the validation fails (too short password, for example), the app redirects to the login page. This seems to be quite a simple thing to fix, but I couldn't find a way to make the page go back to the registration view.

In short, I need to redirect back only when a registration fails. All other auth related fails should redirect back to the login page, as already is the case.

Any ideas?

26 Feb
10 months ago

arthurvillar left a reply on Globally Hide Super Users

I think you can find your answer here. This is how you can override the get(), select() and where() methods.

arthurvillar left a reply on Add A Object In Shopping Cart

I understand how the package is supposed to work, but I can't see what you missed because your code isn't here!

arthurvillar left a reply on Session Is Not Working As Expected

Looks like your post is not complete, as it is this makes no sense. What is your issue? What is your question? Where is the middleware?

arthurvillar left a reply on Fontawesome PHP Brand Icon Won't Load

Fontawesome recently merged to their new version 5 but installing them through package managers still pulls in the older version. You are probably using their current website to copy the icon html tags, but the code you have expects the old tags.

An easy way to check if this is the case is to install their CDN on the head of your page and see if the icons work.

<script defer src="https://use.fontawesome.com/releases/v5.0.6/js/all.js"></script>

Here is the documentation.

arthurvillar left a reply on Add A Object In Shopping Cart

We definitely need to see more code, there is no way of knowing why this doesn't work without seeing where it is coming from and where it is going to.

arthurvillar left a reply on Hinting Objects To Controller

Question 1 Objects injected on a controller method don't run before the method itself, they simply are available for you to use. No logic inside their classes runs until you actually call them. This only happens when you pass a model from the route, which leads to question 2.

Question 2

  • You can pass any model you want but in order to automatically access them from the controller you need to keep the same names. If you call Domains $id, for example, it will not work. $id will be an instance of the Domains class, not the single row you are expecting to get.

  • I think the answer above serves for this question. The row is determined by the id you passed into the route.

  • Laravel will expect an id to be passed into the route, but you can use any column you want. If, for example, you want to find a domain by its name and have the name on the route, just add this method the relevant model

// On Domains model
public function getRouteKeyName()
{
    return 'whatever-column-name-here';
}

You can check the docs here.

25 Feb
10 months ago

arthurvillar left a reply on How To Show Random Posts Using SortBy()?

The helper function shuffle() will do exactly what you need. Check the docs here.

arthurvillar left a reply on How To Pass A Variable From A Function To Another Function?

Take a look at your code. What is $data? You are passing into the method charge() an instance of the Request class as a variable called $request. That function knows nothing about $data so it will tell you just that (undefined variable).

If I understand correctly, you first reach out to the route /validate, then go back to the browser and then go to the route /charge.

On /charge, if you do this instead

public function charge(Request $request)
{
    dd($request);
}

What do you get?

arthurvillar left a reply on Retrieve Multiple Tables

You really should watch the basic courses found here. Laravel 5.4 From Scratch is one you should definitely watch.

arthurvillar left a reply on Speed Up Query To Large Database Using Eloquent.

Install the Debugbar (go to the docs here). Import that database into your local machine and see how many queries Laravel is actually making behind the scenes (you will probably see tons of repeated or seemingly unnecessary queries). You can fix this using through many different ways, but you first need to know exactly what is going on.

24 Feb
10 months ago

arthurvillar left a reply on How Can I Include JS Links For Nested Html Files?

@cronix is absolutely right! I based my answer on the quickest way to get the problem to be solved. This is such a basic issue, so recommending mix seems a little premature. But nonetheless @Webiondev123 , if you don't mind spending some time to learn about mix, definitely go for it!

arthurvillar left a reply on How To Create Static Busines Web With Homepage Of Static Contents Like, About Us, What We Do, Our Services

A static website by definition means no database. Having a database implies dynamic content that changes based on the user. It is very easy to create a website like you described, and you should just build each page the way you want. I absolutely recommend you to stay away from databases, it will just make a simple project become complicated.

If you are familiar with Bootstrap, there are tons of templates you can download and adapt to your needs. Here is a collection of some beautiful ones.

The Bootstrap website also has some free templates that are quite nice, see here.

Any of these pages are very simple to create as long as you have basic understanding of html and css.

arthurvillar left a reply on How Can I Include JS Links For Nested Html Files?

Always use the asset() helper function to link to your css and js files. Like this

<link href="{{asset('css/plugins/toastr/toastr.min.css')}}" rel="stylesheet">

Laravel will automatically locate the css folder on the right place, regardless of the view directory you call it from.

23 Feb
10 months ago

arthurvillar left a reply on Use Session

You can read the docs here regarding sessions in Laravel. The easiest way to go about it is to use the helper function session(). You will be able to use these three methods

// To create a new session
session()->put('session-name', 'session-value');

// To check if a session exists
session()->has('session-name');

// To get an existing session
session()->get('session-name');

// To delete a session
session()->pull('session-name');

arthurvillar left a reply on Creating A Custom Registration System For Guest Users

You used the get() method on the route, but your form's attribute method is set to POST. Just change the route to

// Use post instead of get
Route::post('check_username/{username}', '[email protected]');

arthurvillar left a reply on Url Response Code

getStatusCode() will always give you a status code, that is what this method is supposed to do. Regardless of the code, this will return it. There is no way to ask this method to not return a 200, or even if there is this would be a nonsensical thing to do.

arthurvillar left a reply on Use Session

What do you mean? Which config file? Where do you need to access the session, in the controller on on the view? Please elaborate more on your question.

arthurvillar left a reply on Confirm Box Only Deletes First Record

Last try, change the data-action from the icon into the <a> tag and add on this tag a new class. Like this

<td class="text-center"><a href="#confirm-delete" class="delete-icon" data-toggle="modal" data-target="#confirm-delete" data-action="{{ route('task.delete', $task->id) }}"><i class="fas fa-trash-alt fa-lg"></i></a></td>

Then the JQuery will look like this

$('.delete-icon').on('click', function() {
    alert('Testing if this works');
    $action = $(this).attr('data-action');
    $('#confirm-delete form').attr('action', $action);
})

If you see the alert box it means everything is working. If not, there is still some weird issue going on there.

Quick tip: always load your JS related files at the end of the body tag, not in the head tag. This will let the browser load the page before it loads the JS. Otherwise the browser will be stuck loading the JS and your page will load slower than necessary.

arthurvillar left a reply on Confirm Box Only Deletes First Record

I just added these snippets here and it works. Do you have the JQuery snippet after the JQuery links you just posted? That snippet must be the very last thing on the page. If that is not the issue, than I have no idea because it works here.

arthurvillar left a reply on Confirm Box Only Deletes First Record

So there is the issue. Do you have JQuery running? If not this will not work.

arthurvillar left a reply on How To Save Field Values To Database As JSON

Why not use compact()? Like so

$field1 = $request->input('field1');
$field2 = $request->input('field2');


$lead = Leads::created([
'additional_fields' => json_encode(compact("field1", "field2"));
]);

arthurvillar left a reply on Confirm Box Only Deletes First Record

The action method has not been filled, or it has been filled wrong.

It looks like it has been but the id was not passed to the route, so it is incomplete. MethodNotAllowedHttpException means the route doesn't exist.

Right click on the trash icon and click on inspect. You should see the html element on the browser console. Look at the data-action attribute on that icon and see if it is correct. If yes, than the issue is with the JS snippet.

If that is the case, debug by doing this

<script>
    $('.fa-trash-alt').on('click', function() {
        $action = $(this).attr('data-action');
    alert($action);
        $('#confirm-delete form').attr('action', $action);
    })
</script>

An alert box will open when you click on the icon. You should see there the correct action. If it is correct, than the issue is on passing it to the form.

Right click on the form, click on inspect and look at the action attribute on that form. By now you should be able to track down what went wrong.

22 Feb
11 months ago

arthurvillar left a reply on Confirm Box Only Deletes First Record

Not at all, the delete button will just trigger the form. Since you will only click on it once the modal is open, at that point the action will already be filled.

arthurvillar left a reply on Database Not Updating And No Error Thrown

@ryanborum if the problem is solved, please mark it solved by selecting the best answer.