MangleRule

MangleRule

Member Since 3 Years Ago

Experience Points 59,030
Experience Level 12

970 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 629
Lessons
Completed
Best Reply Awards 5
Best Reply
Awards
  • start-engines Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-session Created with Sketch.

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • subscriber-token Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer-token Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • lara-evanghelist Created with Sketch.

    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 Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

16 Aug
5 days ago

MangleRule left a reply on Where Should I Put Carbon Overflow Settings?

I wouldn't recommend using the index.php file. I would suggest placing that in the AppServiceProvider or maybe extend the Carbon class with your own and just override those settings.

14 Aug
1 week ago

MangleRule left a reply on Implementing Article Path

Is each piece of that path an actual url? For example:

https://my.app/Home

https://my.app/Home/Articles

https://my.app/Home/Articles/Microcontroller

https://my.app/Home/Articles/Microcontroller/ThisArticle

If they are, you can access the route path from the Route facade and explode on the /, otherwise you can use a package specifically for this purpose. https://github.com/davejamesmiller/laravel-breadcrumbs

MangleRule left a reply on Customize The Modal Buttons

Then I'm going to assume that is a component, so you need to style inside the component or pass the class through a prop.

MangleRule left a reply on Customize The Modal Buttons

You just add the class tag:

<b-modal 
    v-bind:title="modalTitle"
    v-bind:size="modalSize"
    class="btn-square"
    @ok="doDelete()"
    id="modal-xl" 
>
    {{modalContent}}
</b-modal>

MangleRule left a reply on Implementing Article Path

Are you talking about a breadcrumb trail in your markup? Where you can click any of the parts of the link to navigate to that page?

MangleRule left a reply on ActiveCampaign

In the link you listed there are two URLs at the bottom of the readme that have API documentation.

MangleRule left a reply on Does Spark Support ACH Payments In Stripe?

Honestly, I didn't want to even reply because of the way you posted.

12 Aug
1 week ago

MangleRule left a reply on Does Spark Support ACH Payments In Stripe?

Laravel Spark utilizes Laravel Cashier, currently Cashier does not support the new ACH method of payments.

01 Jan
7 months ago

MangleRule left a reply on Can Someone Fake Post Request Code?

Ultimately you should be protecting your API endpoints. It doesn't matter too much if a user can navigate to a page they aren't supposed to be on as long as the server doesn't serve them data they are not supposed to see.

Let's say you have an admin page that has a table of users or something, sure with front end code there is probably a way for them to get access to that route. The important thing is that the server checks the authenticated user and doesn't return the important data that would be on that page. Front end javascript can be modified, server responses can't by the client if no data is sent to the front end.

MangleRule left a reply on Should I And My Team Use PHP Linter Or Any Other Solution?

I think using a linting tool is important to ensure you are following good coding standards. There are tools like PHP-CS-Fixer that can integrate into VS Code and other editors to make corrections when you save.

MangleRule left a reply on Vue, Vue Router, Vuex: Issues With Initial Render Timing.

For anyone in this type of situation, this can be solved with navigation guards:

https://router.vuejs.org/guide/advanced/navigation-guards.html

13 Jun
1 year ago

MangleRule left a reply on Converting MySQL Query To Eloquent

Honestly the underlying query is the same and the data sets will be so small there is not really a performance impact on the application.

MangleRule left a reply on Converting MySQL Query To Eloquent

Mainly just to be flexible and make sections of the query adjustable.

MangleRule left a reply on Converting MySQL Query To Eloquent

|date_time |   callid   |   event   |
|----------|------------|-----------|
|1528669182|1528669531.4|ENTERQUEUE |
|1528669199|1528669531.4|EXITWITHKEY|
|1528669215|1528669531.4|CALLBACK   |
|1528669232|1527293006.0|ENTERQUEUE |
|1528669244|1527293006.0|ABANDON    |

In the example table above, I'd like to get the most recent items for each callid in the query. In the example above I should only get the CALLBACK event for callid 1528669531.4 and ABANDON for callid 1527293006.0

MangleRule started a new conversation Converting MySQL Query To Eloquent

SELECT *
FROM queue_log
WHERE date_time IN (
    SELECT MAX(date_time)
    FROM queue_log
    GROUP BY callid
)
AND event = 'CALLBACK'

How would I convert the above MySQL raw query to a nice Eloquent query?

11 Aug
2 years ago

MangleRule started a new conversation Unable To Consume External API

With a fresh installation of Laravel, I'm using Axios to pull Dark Sky's weather API but I'm getting the following error.

XMLHttpRequest cannot load https://api.darksky.net/forecast/(APIKEY)/37.8267,-122.4233. Response to preflight request doesn't pass access control check: No 'Access-Control-Allow-Origin' header is present on the requested resource. Origin 'http://dashboard.dev' is therefore not allowed access.

I can access it in the browser by using the url and it shows JSON. I'm just unable to pull the API from Axios into my application.

28 Jul
2 years ago

MangleRule left a reply on I Need Guidance For Handling SPA Authentication.

I guess I didn't really consider just doing an ajax request there if the user object isn't in the store... To me that feels a lot cleaner than using a prop or something.

MangleRule started a new conversation I Need Guidance For Handling SPA Authentication.

So these are the technologies I am using when trying to build the SPA.

Laravel with Laravel Passport for the authentication and API. Vue, Vuex, Vue-Router for the front end stack.

Generally in the application, a user would log in and the created or mounted method on the root Vue component would trigger an action on the store to collect the user model using Axios and my API.

The issue I'm running into is that I'm comparing meta permission fields on routes for vue-router and matching it to the permissions on the user model stored in my Vuex store.

This turns into an issue if I navigate to a page by direct url in the browser instead of a router-link and if I refresh a page that contains any sort of permissions because the route guards trigger before the Vuex store has a chance to collect the user object. This feels really gross because there are instances where I'd like to link a user with proper permissions directly to one of those pages but they would just get redirected to the dashboard.

Question 1: Is there a way to ensure that the Vuex store has the user model accessible before the navigation guards trigger?

Question 2: Would it be better to pass the user object as Json into the root Vue component using a prop?

Any best practice advice would be really appreciated.

(I would ideally like to use the Vuex store for the user model just in case in the future I leverage something like Pusher so I could in real time update permissions and have that users dashboard adjust controls and menu items in real time)

17 Jun
2 years ago

MangleRule left a reply on Conditional Blade Template

It would be very helpful to know the exception :)

16 Jun
2 years ago

MangleRule left a reply on Conditional Blade Template

Well I believe Auth()::template would try to resolve a template method on the Auth() class. It should be more like


@if (auth()->user()->template())

MangleRule left a reply on Installation Documentation

Honestly, Taylor has done an amazing job at documenting things. When it comes to PHP extensions, most Windows LAMP stacks have them available out of the box, you just have to enable them in the configuration and if you have a linux / mac operating system there are lots of package managers that can quickly pull in the extensions. If you're using an object oriented framework you should be pretty familiar with PHP, it's extensions, and basic setup.

MangleRule left a reply on Valet Install Error

If you haven't already check out the "Setup a Mac Dev Machine from Scratch" series. You might find some useful information in there for getting your environment all setup.

MangleRule left a reply on Conditional Blade Template

The first approach should be sufficient. What error are you getting?

25 May
2 years ago

MangleRule left a reply on How To Make Axios Return A View And Get Rendered By Vue

Well traditionally you would have a guest page and a separate dashboard page.... What is the application for? You could have a basic splash page with information about the application and then after a login redirect them to a different page?

MangleRule left a reply on Query With To Eloquent

Do you just need to get a list of Universities and how many students are enrolled in each for a specific year?

MangleRule left a reply on Query With To Eloquent

Can you layout the two tables with their columns and what you want from the resulting query?

MangleRule left a reply on How To Make Axios Return A View And Get Rendered By Vue

Might I ask what you are trying to do this for? All of the Vue components are compiled and on the client end, you could get a response from Laravel I guess but once again I feel like there is a more elegant solution than picking an html response over ajax.

MangleRule left a reply on Query With To Eloquent

Maybe try the following:

DB::table('data_students')
           ->join('universities', 'data_students.id', '=', 'universities.id')
           ->select(
                'universities.name', 
                DB::raw('COUNT(data_students.university_id) as amount')
            )        
           ->where('data_students.year',$year)
           ->groupBy('data_students.university_id')
           ->get();

MangleRule left a reply on Checking For Posts Limit

What do you mean checking in multiple places? If you're just making sure they can't post, all end points you would have would have to hit the controller methods and if you place that check there then they can't post.

It would help if you could explain the application you're building and why you are wanting to prevent the posting after 10 posts.

MangleRule left a reply on Error Messages Are Not Shown After Validation

Is there a reason you aren't using the validate method? All Laravel controllers use the ValidatesRequests trait which allows you to do something like this:

public function storeLecture(Request $request)
{
    $this->validate($request, [
        'lecture_title'  => 'required',
        'body'           => 'required',
        'file'           => 'required'
    ]);

    // Lecture is valid and can be stored.
}

If the validate function fails, it will automatically redirects back with the proper errors.

MangleRule left a reply on Role/permission In Vue

Well what you could do is make the root instance of Vue a component and using a prop you can pass the user with eager loading or even a second prop for just permissions like this:


<app id="app"
    :user="{{ auth()->user() }}"
    :permissions="{{ auth()->user()->permissions()->get() }}"
></app>

Then you can access the information from your other components by accessing the data on the root component or you could just use some meta tags in your document that have the information which you can access with javascript. There are quite a few ways to go about it. Just make sure everything on your backend is secure.

MangleRule left a reply on Error Messages Are Not Shown After Validation

$errors is an object and an instance of Illuminate\Support\MessageBag. If you want to iterate it the way you are trying to, you need to use the all() method on the $errors object like this:


@foreach ($errors->all() as $error)
    <li>{{ $error }}</li>
@endforeach 

MangleRule left a reply on Query With To Eloquent

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

Definitely give this a look through. Everything is exampled out and it covers joins as well. It would probably be better and more impactful for you to read the documentation and get a feel for it than have someone just give you the code.

MangleRule left a reply on Forge User Password

You will have to contact the VPS provider and get the password changed.

MangleRule left a reply on Resetting Vue-router Keep Alive State

https://vuejs.org/v2/guide/computed.html#Watchers

You could just use a watcher to observe the variable and when the variable changes, you could fire a method that would reset the state of the form by setting all the appropriate fields blank?

MangleRule left a reply on Checking For Posts Limit

Well assuming you have a relationship setup between Users and Posts, on the PagesController create method just leverage the relationship to count the users total posts. Then you can simply do something like


if (auth()->user()->posts()->count() < 10) {
    // Create the post
} else {
    // Throw exception or flash the message to the session
}

I wouldn't worry much about dedicated middleware, policies, or anything like that for something simple.

MangleRule left a reply on Whats An Appropriate Way To Handle This?

Just to clarify, a trait is used to extract code and make it reusable. If you have multiple models or classes that use similar functionality you can extract a trait and share logic from a single source.

In this situation I feel like the architecture is a little flawed. I personally would change some design implementations.

I feel like you should have the following models: Event, Contestant, Prize.

If you do it this way, you will have full flexibility for any number of events, prizes, and contestants.

The Event can be responsible for knowing who won, who is a contestant, and what the prize is for that event. The Prize can just be concerned about information important to the prize and the contestant can be responsible for the contact information for the entrant.

Then you can add prizes to the database, assign the prize(s) to certain events, and then figure out how you want to enter contestants to the events. I don't feel like the prize should check if there is a winner by phone number, it should be more like the event will check for a contestant with that phone number and assign them as the event winner.

MangleRule left a reply on Whats An Appropriate Way To Handle This?

This would realistically require more information on what you are trying to accomplish and what a comfortable workflow for you would be.

Are you creating a prize before or after there is a winner?

Are you creating multiple prizes in advance before there are winners?

Do you mind giving more details on your thought process?

MangleRule left a reply on Trying To Get Property Of Non-object

Now that I think about it, I don't think pluck is appropriate for this instance. You should try it using select instead:


$users = User::where('id', '!=', auth()->id())->select('username', 'id')->get();

I just double checked and pluck() creates an array of key value pairs. By saying pluck('username', 'id') it creates an array likes this:


[
    "Username 1" => 1,
    "Username 2" => 2,
]

Since this is returning an array, you can't iterate through it like a collection. Using select instead of pluck will actually modify the database query and give you a collection of users with just the two specified columns.

MangleRule left a reply on Trying To Get Property Of Non-object

Now dump a single user in the collection and see how it's formatted.

MangleRule left a reply on Trying To Get Property Of Non-object

What does it show if you just dd($users) in the view?

MangleRule left a reply on Trying To Get Property Of Non-object

If you're getting a property of non-object error then something is returning null when it's trying to get an instance of the user. Try to die and dump the $users variable in the controller and make sure it is actually getting a collection of users, if it is then you might not be passing the variable into the view properly.

MangleRule left a reply on Migrations Not Peristing

Well I can't think of anything unless you are using DatabaseTransactions somewhere and it's rolling back your changes. The best thing to do would be open up Jeffrey's github page for this series and review the code in comparison with yours and see if you can identify differences.

MangleRule left a reply on Migrations Not Peristing

Well if your phpunit.xml is as shown, what does your .env file look like?

02 Mar
2 years ago

MangleRule left a reply on Syntax Error Or Access Violation: 1071 Specified Key Was Too Long

Just in case anyone is wondering, as Cronix mentioned Laravel 5.4 is in fact using utf8mb4. If you're running MySQL prior to 5.7.7 or MariaDB prior to 10.2.2 you will get this error. If you want to use utf8mb4 then just upgrade your MySQL, MariaDB, etc. to the most recent or development versions.

10 Jan
2 years ago

MangleRule started a new conversation Vue, Vue Router, Vuex: Issues With Initial Render Timing.

I'm starting to build a simple router.beforeEach guard. Essentially each route I need protected has a meta field called permission. For each of those routes I want to check the vuex store to see if the user has the permission requested. For example, to view the /settings page, the route has

meta: { permission: 'settings.view' }

In my router.beforeEach I would like it to check the Vuex store and see if the meta permission is in the array of the users permission. The issue happens when I first load the page. The user in the store hasn't been filled at the time of render and the route breaks if I refresh on a protected route or if I send someone a link to a protected page, they login and when they try to load that page the app breaks because user at that time is undefined.

I really don't want to have to check if the user in the store is undefined and do a rouge ajax call. I'd much rather have it commit a mutation/action if the user is undefined so that it is coupled with the store. How can I trigger a vuex action and have it wait for the user in the store to get populated and then check the permission of the user?

22 Dec
2 years ago

MangleRule started a new conversation Conditionally Use Router-links

How can I conditionally render <router-link :to="">? Basically I have a database of navigational items. Some of the items are meant to trigger drop down to children items so they don't have a url to go to. When I dynamically fill the :to prop and the value is null, router-link will fill it with the current pages route. How can I remove the :to prop if the value is null so that it won't try to change the current route? I just want to click the link and have it open the sub menu.

21 Dec
2 years ago

MangleRule started a new conversation How Do I Return Parent > Child Relationship From Same Table?

Esentially what I'd like to do is have one database table called navigationMenu. In the table there would be these type of entries:

| id | parent_id | description | url | |:---:|:---:|:---:|:---| |1|0|Dashboard|/ |2|0|Accounts|/accounts |...|...|...|...| |6|0|Settings|/settings |7|6|Users|/settings/users| |8|6|Notifications|/settings/notifications

I'm using Vue and Axios to get the navigation menu from the database using ajax. Right now I'm basically sending a get request to my api which does the following:

return DB::table('navigationMenu')->where('parent_id', 0)->get();

With this I can loop through the items with Vue to make a navigation on my page like the following:

<ul>
    <li>
        <a href="/">Dashboard</a>
    </li>
    <li>
        <a href="/">Accounts</a>
    </li>
    <li>
        <a href="...">...</a>
    </li>
    <li>
        <a href="/">Settings</a>
    </li>
</ul>

If I were to instead do something like

$navigationItems = DB::table('navigationMenu')->where('parent_id', 0)->get();

foreach ($navigationItems as $items) {
    ...
}

How could I have Eloquent take each root element (parent_id = 0) and check the other entries for items with the parent_id of the current loop item and insert an attribute called 'children' that would contain an array of each child like the following:

[
    {
        id: "6",
        parent_id: "0",
        description: "Settings",
        url: "/settings",
        children: [
            {
                id: "7",
                parent_id: "6",
                description: "Users",
                url: "/settings/users"
            },
            {
                id: "8",
                parent_id: "6",
                description: "Notifications",
                url: "/settings/notifications"
            }
        ]
    }
]

This way I can loop through it all and end up with something like

<ul>
    <li>
        <a href="/">Dashboard</a>
    </li>
    <li>
        <a href="/">Accounts</a>
    </li>
    <li>
        <a href="...">...</a>
    </li>
    <li>
        <a href="/">Settings</a>
        <ul>
            <li>
                <a href="/settings/users">Users</a>
            </li>
            <li>
                <a href="/settings/notifications">Notifications</a>
            </li>
        </ul>
    </li>
</ul>

It would also be nice to go additional levels if I needed to so the return from the ajax request would automatically create a child attribute for each object that has children. I hope my goal is clear. I'm not entirely sure how to word this in a better way.

MangleRule left a reply on Router-Link: Conditionally Render 'exact' Attribute

Apparently it is just a prop so I was able to evaluate " item.url == '/' " which returns true for my navigation item that goes to the '/' url.

MangleRule started a new conversation Router-Link: Conditionally Render 'exact' Attribute

I'm rendering my navigation menu from a database ajax call. I'd like to conditionally render the 'exact' attribute only to any navigation items rendered with the url '/'. What is the proper way to do this?