spekkionu

spekkionu

Member Since 4 Years Ago

Antioch, CA

Web Developer at Digital Canvas

Experience Points 186,890
Experience Level 38

3,110 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 1312
Lessons
Completed
Best Reply Awards 127
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.

26 Apr
1 year ago

spekkionu left a reply on [HELP] About Mysql 8.0 Problem

Do you have NO_AUTO_CREATE_USER as one of the options for the sql_mode in your database config? It was removed in mysql 8 and should be removed from your config as well.

https://dev.mysql.com/doc/refman/8.0/en/mysql-nutshell.html

spekkionu left a reply on Retrofit

What do you mean you can't modify the code?

You can add an accessor and a mutator for the attribute to your model to handle the serializing and unserializing for you.

https://laravel.com/docs/5.6/eloquent-mutators#accessors-and-mutators

spekkionu left a reply on Retrofit

Looks like you should be able to json_decode it.

25 Apr
1 year ago

spekkionu left a reply on Cant Understand Eloquent Distinct

If you return all the fields the records will no longer be unique.

Distinct only combines records where all the selected fields match.

This makes sense as how would it know which values to use for the other fields?

Say you have a "John Doe" and a "John Smith". Both have the same first name but what would the last name be for the record? Because they are different a "SELECT DISTINCT" query would return them both unless you only were pulling the first name column.

What are you trying to accomplish with your query? There likely is a different way to get the data you need.

spekkionu left a reply on Change In Node_modules File Does Not Reflect The Change In UI

You should not be modifying files in your node_modules folder. These are vendor dependencies much like the vendor folder is for php.

The watcher (assuming the default laravel configuration) keeps an eye on files in your resources directory which is where your javascript should go (much like the app folder for your php code).

spekkionu left a reply on What Things Can Cause A Memory Leak In A Laravel Project?

A memory leak is a specific type of problem where something is put in memory but never removed. This is much less a problem for a HTTP request as when the request is complete the process goes away so even if you have a memory leak it likely wont matter much. They are much more problematic for a long running process or a cli script.

https://en.wikipedia.org/wiki/Memory_leak

Php is pretty good at garbage collection so memory leaks aren't too common but they do happen from time to time.

Generally where you need to watch out for them is in loops. To avoid memory leaks in your scripts you really just need to close any open file streams, destroy image resources, or close any open socket connections when you no longer need them. Also if you have a variable that takes up a large amount of memory you might want to unset it yourself one you don't need it anymore rather than wait for the garbage collector to do it for you.

The other thing you might need to watch out for is cyclic references.

https://en.wikipedia.org/wiki/Circular_reference

Overall this isn't something you should be too worries about. I've probably only had one cause an issue a dozen times or so in the 12+ years I've been programming in php.

spekkionu left a reply on Excel Data Too Large To Parse. Suggest Hack To Deal With Large Set Of CSV Data

Are you trying to insert one record into the database for each row in the file? If so try something like this.

$reader = \League\Csv\Reader::createFromPath($request->file('import_file')->getRealPath(), 'r');
$reader->setHeaderOffset(0);
$header = $records->getHeader();
$records = $reader->getRecords();
foreach ($records as $offset => $record) {
    Csv_data::create([
        'csv_filename' => $request->file('import_file')->getClientOriginalName(),
        'csv_header' => json_encode($header),
        'csv_data' => json_encode($record)
    ]);
}

The csv parser uses generators so there is no need to do any resultset chunking.

spekkionu left a reply on Excel Data Too Large To Parse. Suggest Hack To Deal With Large Set Of CSV Data

To get the header for the file.

use League\Csv\Reader;

$csv = Reader::createFromPath('/path/to/file.csv', 'r');
$csv->setHeaderOffset(0);
$header = $csv->getHeader();

spekkionu left a reply on Need Help Category Wise Post Show

I suggest you pull back and give the documentation for eloquent relationships a read.

https://laravel.com/docs/5.6/eloquent-relationships

Also a video on the subject from this site.

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

This will give you a basic understanding of what to do much more than just someone here writing your code for you.

spekkionu left a reply on Excel Data Too Large To Parse. Suggest Hack To Deal With Large Set Of CSV Data

Take a look at the league/csv library. It uses streams and iterators so even very large csv files should not be a problem.

https://csv.thephpleague.com/

spekkionu left a reply on Need Help Category Wise Post Show

What does the relationship on your models look like? Is it a one-to-many where each post is in exactly one category? Is it a many-to-many where a post can be in more than one category?

spekkionu left a reply on How To Separate Frontend And Backend Completely?

You will likely want to use a front end framework to handle routing for you. Common options for this are react with react-router, Angular, Ember, and Vue with vue-router. There are dozens of javascript mvc frameworks out there. Vue seems to be the most common choice for the Laravel community (especially on this site) and react is probably the most common choice overall. You can watch some of the videos on this site to get started with Vue.

spekkionu left a reply on Can't Turn An Object Into An Array.

What does the RetsFeedApiResult class look like? Unless it is a simple object with public properties you will likely have to write your own toArray method.

22 Apr
1 year ago

spekkionu left a reply on Return Response (json) And Abort

In your example you can just return the result from your function.

$this->validateData();

If it were a function that you on;y sometimes want to return a response you would instead want to throw an exception.

http://php.net/manual/en/language.exceptions.php

function myfunction(){
    if(!$contidion){
        throw new Exception('My condition failed');
    }

}
try{
    $this->myfunction();
}catch(Exception $e){
    return response()->json($e->getMessage());
}

It would be better to extend the exception class and use a more specific name for it that described what the exception is for so you can differentiate it between other errors. With a custom exception you can also pass extra data along by adding properties to your exception class.

It this is a common pattern you use in your application that is always handled in the same way you can add a handler for your custom exception to app/Exceptions/Handler.php that turns it into a response and you wont need the try catch block in your controllers.

21 Apr
1 year ago

spekkionu left a reply on Best Practice For Migrations And Null?

For me personally I just assume any field should be null by default unless there is a reason for it not to be.

spekkionu left a reply on How To Properly Add A Package To My Project

Just add a script tag in your view. Just make sure it is after the script tags that load jquery and bootstrap.js. You will also need to add a link tag to point to the stylesheet.

Being a jquery plugin it doesn't require anything fancy.

spekkionu left a reply on Is There Any Significant Difference To Setting Up Your API Endpoints In Routes/api.php As Opposed To Routes/web.php

Being in separate files is just a way to keep things more organized. They are in route groups that use different middleware groups that you can configure independently of each other but you could get that setup in the same file as well.

I think the main reason some people will use one over the other depends on the type of api authentication they plan on using.

The web routes includes things like sessions, cookies, and csrf tokens that are not needed if you aren't using cookie-based authentication for your api. Generally a dedicated publicly available api will use either an api token header / parameter or something like JWT / oath, in which case you don't want cookies. Just adding a couple of routes to your app for use with ajax requests would instead use the web routes with all the cookie and session stuff.

spekkionu left a reply on How To Properly Add A Package To My Project

It does, you just need to add some configuration to your composer.json to tell it where your public directory is. By default it copies the scripts into /components you need to tell it to stick the library into the public folder instead.

I think something like this:

"config": {
    "component-dir": "public/assets",
    "component-baseurl": "/assets"
}

You will need this in place before installing the package as it is triggered on installation.

The reason people use composer to install front end packages is to avoid having to install extra dependencies like nodejs and also having yet another thing to learn. Even with the installer I think it is a better idea to use npm or yarn rather than installing front end assets with composer. If you want to do things like combine scripts or transpile ES6 javascript or use a css preprocessor like sass or less you are probably going to have to install node anyway. Laravel mix makes using npm libraries much easier as you don't have to do much configuration to get them working.

spekkionu left a reply on How To End Up With The Right File/folder Ownership Of Log Files (root Vs Www-data)

You can also use linux acl to give specific users different permissions to the storage directory.

https://www.thegeekdiary.com/how-to-configure-aclaccess-control-lists-in-linux-filesystem/

sudo setfacl -R -m u:www-data:rwx -m u:cliuser:rwx path/to/storage
sudo setfacl -dR -m u:www-data:rwx -m u:cliuser:rwx path/to/storage

This will give www-data and cliuser (whatever user you use to run artisan commands and the owner of the files in the application) access to the storage directory. The second line will set these settings as the default so the permissions will even apply to files created by root.

I would still set the scheduler cron and the queue workers to run as non-root though.

You might need to install acl and configure your disks to use it depending on the linux distribution you are using. Most seem to have it by default now though.

spekkionu left a reply on Error In Eloquent Pagination Outside Laravel

The laravel pagination has a dependency on the laravel view renderer so if you aren't using blade you wont be able to use the $pagination->links()method and will instead have to write your own pagination html using the given data.

spekkionu left a reply on How Do I Go About Testing In Laravel

This is quite a lot of code for a controller. I like to move these types of things to a query scope on your model. Your entire controller code could then look something like this.

$search = $this->validate($request, [
        "county" => "required",
        "town" => "required",
        "type" => "required",
        "min-bedrooms" => "required",
        "max-bedrooms" => "required",
        "min-bathrooms" => "required",
        "max-bathrooms" => "required",
        "min-rent" => "required|max:4",
        "max-rent" => "required|max:4",
]);

$properties = PropertyAdvert::search($search)->get();

https://laravel.com/docs/5.6/eloquent#query-scopes

You could go even further and move the validation to a form request.

The advantage here other than an easier to understand controller is that you can now test your search code independently of your controller.

A simple test might look something like the following:

  • Add a few records in the database using a model factory.
  • Call the PropertyAdvert::search query scope.
  • Check that the results included the records you expect.

spekkionu left a reply on Laravel Package Class Class_name Does Not Exist ReflectionException

What does your service provider look like? The string you return in getFacadeAccessor should match the key the class was bound to in your service provider.

spekkionu left a reply on How To Override Html Collective Functions In Laravel 5.4

It should actually be $this->app->bind inside a service provider.

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

Are there any states without a ruling? This would cause that error when trying to access the name property.

spekkionu left a reply on How To Override Html Collective Functions In Laravel 5.4

You can put it in the register method of your AppServiceProvider in app/Providers/AppServiceProvider

spekkionu left a reply on How To Properly Add A Package To My Project

This is not php but a javascript package. You will need to include the library with a script tag or require it in your app.js using a module loader.

When installed using composer the package uses composer-installer to copy the library out of the vendor folder. You will need to configure it to point to a public directory so you can load it in a browser.

https://github.com/RobLoach/component-installer

Because Laravel mix makes working with npm packages easy you are much better off using yarn or npm to install this package rather than composer.

spekkionu left a reply on How To Override Html Collective Functions In Laravel 5.4

You should be able to extend the class then bind your version to the service container in a service provider.

$app->bind('html', 'YourClass');
20 Apr
1 year ago

spekkionu left a reply on Git Bash Weird Characters

I'll second the use of WSL. It takes a way a lot of the pain of trying to get things build for linux working on windows.

You can get ansi colors working in the default windows console and powershell with ansicon.

https://github.com/adoxa/ansicon

spekkionu left a reply on Category Tree

There are two common ways of storing hierarchical data in a relational database.

The first an the one you are currently using is called an adjacency list. Here you store the id of the parent node in each record. With this method you need to rebuild the tree each time you need to use it which generally involve recursion and can be slow for larger trees. Caching is a must which also adds the complexity of cache invalidation.

The second method is called a nested set which is a bit more complex. I don't really know how to describe this method without diagrams so I'll just link to a good article that explains it.

http://mikehillyer.com/articles/managing-hierarchical-data-in-mysql/

The major benefit here is building the tree is much easier and faster. The downside is that adding, removing, or deleting a node requires rebuilding part of the tree and updating all the affected nodes.

There are two popular packages in laravel to allow for nested set eloquent models. Both are good and it really doesn't matter which one you use.

https://github.com/lazychaser/laravel-nestedset

http://etrepat.com/baum/

spekkionu left a reply on Form In Blade With Vue Functionality

There are a number of ways to get data from php into vue.

You can pass the data to the vue component by creating props for the data you want to pass and have something like :propname="{{ json_encode($data) }}" on the component. You can have the data initialize from the prop data.

You can use data attributes to pass the data in blade and have vue read those properties when mounted or created to set the data. This is kinda more like a jQuery style of thinking and I think most people who use it are probably a bit newer to the difference in thinking.

You can set global variables using something likewindow.variable = {{ json_encode($data) }}; These variables would be available in vue. I don't really recommend this method pretty much ever but I have seen it done a number of times.

You can have your vue component to an ajax request to pull data from the server rather than pass it from vue.

In your case I would recommend turning the form into a separate component that accepts the subscription object as a prop and have the data object use the prop values to initialize.

spekkionu left a reply on Send All Requests To Another Server

This wouldn't actually be doing redirects but the requests would be proxied to another server.

For nginx

https://docs.nginx.com/nginx/admin-guide/web-server/reverse-proxy/

For apache

https://httpd.apache.org/docs/2.4/howto/reverse_proxy.html

spekkionu left a reply on MVC Structure - API Wrappers, Object Formatters, And General Helpers

The definition of a service is pretty broad. Pretty much any class or set of classes that "do something" is a service. All of the examples you gave would be considered services. What you are calling "libraries" are also a type of service but not all services are libraries. None of this is actually really helpful to you figuring out how to structure your application.

There isn't really a standardized way of organizing your services and pretty much everyone will do it differently.

One way is to create a namespace for a particular domain and put all of your classes that have to do with that domain in it. To take your example you would have a namespace where you would put your class that calls the methods from the authnet sdk, as well as any models or value objects that also have to do with payments. This method makes it easy to find things as things that are related tend to be in the same place. The downside is that some things might be very hard to place like what do you do with a class that basically connects two domains.

Another is to group classes that have a similar functionality. You would have a namespace for your models, one for your value objects, and so on. The class you talked about that calls the methods on the authnet sdk and returns value objects could be considered a model as it wraps the sdk much like eloquent models wrap database calls for a table. This is closer to how the core of laravel is organized. All the controllers are together, all the event are together, all the console commands are together and so on. The downside here is your domain will be spread out in different places and it might be harder to find things in your project.

As you said yourself it really is up to you and the needs of your project.

19 Apr
1 year ago

spekkionu left a reply on JavaScript::put - Method Not Found

The \Javascript class is a facade. The methods will be on whatever class the facade references.

PHPStorm doesn't know this and just sees that there is no static put method on the facade class. This isn't anything yo worry about as long as the facade and service provider are set up correctly.

The class makes your variables available to blade but javascript wont see them unless they are printed in your layout. Your layout or view should contain @include ('footer') where the variables will be set as javascript variables.

18 Apr
1 year ago

spekkionu left a reply on Authentication And Ajax

Ajax requests send the same cookies as a normal request so the session is available the same way in both.

For ajax requests rather than redirecting to the login page Laravel returns a 401 response code. You can catch this in your javascript code and do the redirect there in a SPA.

17 Apr
1 year ago

spekkionu left a reply on Laravel And Ajax

As far as performance and usability benefits go generally the first load is faster to just bundle it in the original request but anytime you need to refresh the data it is much faster to reload it with an ajax call rather than a full page reload.

So if you have various buttons, forms, or links that would cause you to need to reload the data it is much better to use ajax in that case. Examples would be things like tables with sortable columns and filters for the data.

Also if you have a large amount of components on the page that each need their own data (like a dashboard) it is much better to have them each pull their own data as your controllers can get a bit messy otherwise.

Where you draw the line is subjective and if neither is too slow you should just do whichever one you prefer. Component-based frameworks like vue and react make working with javascript much easier then the jQuery days or even worse before that when you had to provide multiple ways of doing an http request depending on which browser was being used.

spekkionu left a reply on Undefined Property: Illuminate\Http\JsonResponse::$id

Most likely the problem is in App\Http\Resources\PersonResource but it could also be in one of your middleware.

You are trying to access a id property on a response object. Maybe you were expecting it to be a model?

spekkionu left a reply on Passing The Data To Another Method From The Result Of One Method.

I recommend using eager loading like @burlresearch mentioned but to fix your specific example it should be:

user::find(85)->member->announcements

Calling the relationship as a method returns the relationship itself while calling it as a property pulls the data and returns the result.

spekkionu left a reply on Test Queue Connection Works For Healthcheck

The queue has a size method that returns the number of jobs in the queue.

You can likely use this to check the queue connection.

If things are down you will probably get some sort of exception thrown.

https://github.com/laravel/framework/blob/5.6/src/Illuminate/Contracts/Queue/Queue.php#L13

spekkionu left a reply on Looking For Any Suggestions

A useful option would be to rebuild a previous project using Laravel. This will provide a real-world project that had actual requirements to fill a need.

At the end your project will have an update code base that you should be much happier with and likely can make changes to much easier and safer (assuming you also write tests).

This is of course assuming that you are new to Laravel but not new to web development in general. In which case I recommend keeping it simple like a blog.

The forum project here is great and you should go through it but I recommend trying to build something on your own before tackling a project for a client or employer on your own. There is a big difference when you have to make the difficult decisions on your own without Jeffrey to make them for you. There are a lot of things he makes look easy that wont seem that way on your own.

Even if you don't ever use it for a real project it will be a great leaning experience and give you an idea of what trouble spots you are likely to run into on real projects.

spekkionu left a reply on Count Number Of Posts In A Category In Vuejs

When you pull the category list add a ->withCount('posts') to the query.

https://laravel.com/docs/5.6/eloquent-relationships#counting-related-models

spekkionu left a reply on Big Dashboard Page Or Lots Of Separate Includes

To take this even further I recommend not only using includes for each part of the dashboard but for any partials that need any variables passed to the view, rather than running all of the queries and other data-pulling in one controller, I would use a view composer for each partial that needs data which pulls the data only that partial needs. This will keep your controller much cleaner.

https://laravel.com/docs/5.6/views#view-composers

spekkionu left a reply on Php Version

I guess for downgrading you can just follow the same steps in reverse.

Really though you are better off upgrading php. There should not be any issues if you stay within the 7.1 branch and Laravel 5.6 works great in 7.2 so upgrading should be an easy process unless you have some older applications on the server as well. PHP should be kept up to date within the minor branch or you will miss out on any security fixes in each release.

16 Apr
1 year ago

spekkionu left a reply on How To Load Javascript ES6 Class In View?

You will also need to run the script that uses the class through babel to be able to use the class.

spekkionu left a reply on Php Version

Follow the directions in the upgrade guide.

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

spekkionu left a reply on Laravel Subfolder Installation

You would be much better off adding another virtual host with a subdomain than using a subfolder.

It is really recommended to not have any laravel files inside the webroot other than what is in the public directory. There are ways to mitigate these problems but it is more work than just adding another virtual host.

13 Apr
1 year ago

spekkionu left a reply on How To Perform Conditional Routing

You can create a 404.blade.php template that will be shown whenever a user requests a url that doesn't match any routes.

spekkionu left a reply on How To Create Dynamically Create Config/custom.php Config File

You are probably better off using the cache component rather than the config component.

12 Apr
1 year ago

spekkionu left a reply on Laravel To VueJs Limit Characters To Show

Javascript doesn't know how to run php code.

You can this in in php for example by adding an accessor to your model and inclusing that field in your query.

https://laravel.com/docs/5.6/eloquent-mutators#accessors-and-mutators

Or you can change it to use javascript string methods.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/String

spekkionu left a reply on Help Creating Wordpress Pages From Laravel App

You can bootstrap WordPress by including the wp-load.php file.

Note that you will either need to do this before the vendor autoloader is included or at least include wp-includes/l10n.php as both have a _ helper function.

Try adding require 'path/to/wordpress/wp-load.php' to the top of the bootstrap/app.php file.

You should then be able to use any of the WordPress functions like wp_insert_post