Snapey

at Novate / Microlise

Hire Me

Experience

406,135

655 Best Reply Awards

  • Member Since 2 Years Ago
  • 738 Lessons Completed
  • 1 Favorite

26th March, 2017

Snapey left a reply on Csrf_token Regeneration On Window.onfocus() • 8 hours ago

two options

  1. after logout, direct the user to a page that does not have a login form. Maybe acknowledge that they are logged out and show a login button that loads the login page

  2. exclude the login page from csrf check... it serves no practical purpose on that form.

Snapey left a reply on Querying Nested Relations (once More) • 9 hours ago

public function getTitleAttribute()
{
    if(!$this->relationLoaded('metadata_registry')) {

        $this->load('metadata.metadata_registry');

    }
    
    return $this->metadata->metadata_registry->title;

}

Snapey left a reply on MethodNotAllowedHttpException In RouteCollection.php Line 233 • 9 hours ago

ok, so on the second form, you need to tell the forms package that the method should be GET

Snapey left a reply on MethodNotAllowedHttpException In RouteCollection.php Line 233 • 13 hours ago

what is your intention with the second form?

you mention posts.show but that is the route to get a single post

Snapey left a reply on Trying To Get Property Of Non Object Error • 14 hours ago

where does it blow up?

Snapey left a reply on MethodNotAllowedHttpException In RouteCollection.php Line 233 • 14 hours ago

@darkroast I don't use Form package because it's a giant waste of time which pretty soon you grow out of, but, are you sure you need to use raw output? it seems very unsafe practice?

@ElvinGizWiz it's funny, i expect your first form to fail because you don't say which post you want to store

Snapey left a reply on Trying To Get Property Of Non Object Error • 14 hours ago

you can use or in blade tags or ?? operator in php7


{{ $object->attr or ' unset' ))

{{ $object->attr ?? ' unset' ))

or resort to testing with isset

Snapey left a reply on Unique For Nullable Attribute • 14 hours ago

use the sometimes rule

Snapey left a reply on Get Array From Publick Function In Index.blade.php • 14 hours ago

have a look at laravelfromscratch.com

Snapey left a reply on How To Update IsApprove Value In Database Upon Clicking Approve Button? • 16 hours ago

can you edit your original post and put three backticks ``` before and after your file blocks

Snapey left a reply on Possible To Convert Laravel Project To PHP Or Similar • 18 hours ago

only if you access the page in your browser, right click and view the HTML source.

Snapey left a reply on Get Array From Publick Function In Index.blade.php • 18 hours ago

tell me, you seem to be early in your development, what made you choose Lumen?

Snapey left a reply on Get Array From Publick Function In Index.blade.php • 18 hours ago

because you build an array, you cannot access it as an object (using the object pointer)

Learn a bit of basic php and top

Snapey left a reply on Possible To Convert Laravel Project To PHP Or Similar • 18 hours ago

No, it does not make any sense. Laravel is php code.

Snapey left a reply on Why Am I Finding It Difficult To Use A Framework? • 18 hours ago

Don't just look at one set of tutorials either. There are a lot out there, both video and written, and even with the most basic ones I end up picking up new techniques and different perspectives.

Snapey left a reply on Get Array From Publick Function In Index.blade.php • 21 hours ago

best start with some basic tutorials...

Snapey left a reply on What's The Difference Between @include And @yield???? • 22 hours ago

@include is the same concept as a php include, get the named file and insert it at this point in the document.

@yield is more complicated but still quite simple.

When you load a view, eg 'home', at the start of the file it might declare that it extends a master layout.

At this point, control transfers to the master layout and the content from the master is output until you reach a @yield (like 'give way'). Now, control switches to a named section in the original view, until the end of the section, when it then reverts back to the master again

//    Welcome blade                   Master blade
//    
//    extend master  ------------------>
//                                    content
//                                    content
//                                    content
//                                    yield ('body')
//       <------------------------------
//    @section 'body'
//    content
//    content
//    content
//    end section
//       ------------------------------>
//                                    content
//                                    content
//                                    content

Snapey left a reply on Send User Password Reset Link After Creation By Admin • 22 hours ago

What have you tried?

25th March, 2017

Snapey left a reply on Does Eloquent Prepare The Output Of The Data In The Collection When Relationships Are Eager Loaded? • 1 day ago

One of the differences with Eloquent ORM is that the relations are nested and not duplicated on every row - as you would get with a join.

Maybe a GroupBy on the email is needed on your query builder approach?

Snapey left a reply on Storing User's Date Of Birth As A Timestamp Object? • 1 day ago

Yes, use a date field so that you are not restricted to dates since 1970

Chances are that you will want to get the date from your form in a format that is friendly to your user.

You can use accessors and mutators to manage the date field.

Supposing your date comes from your form in the format 03 Mar 2017 then you can parse it in a mutator so that you can just send the date to the model.

    public function setBirthDateAttribute($value)
    {
        $this->attributes['birth_date'] = $this->parseDate($value);
    } 

    public function parseDate($date=null)
    {
        if(isset($date))
        {
            return Carbon::createFromFormat('d M Y',$date);
        }
        return null;
    }

The isset check allows you to throw the date field into the model and if the user has not provided a date then it won't throw an error.

Obviously I don't know what your field name is here.

Snapey left a reply on Using Eloquent To Return Results Ordered By Eager Loaded Model Property. • 1 day ago

Supposing you wanted to list them by the total of their orders (given that a user can have many orders;

On the User model;

    public function getOrdersTotalAttribute()
    {
        $sum=0;
        foreach($this->orders as $order){
            $sum+=$order->price;
        }
        return $sum;
    }

So now we have made an attribute on the user which is the total of their orders, and can be used for sorting;

$result = Users::with('order')->get()->sortByDesc('ordersTotal');

Snapey left a reply on Using Eloquent To Return Results Ordered By Eager Loaded Model Property. • 1 day ago

When you load a collection of models, and use with to eager load, then these are fetched from the database as separate queries and then merged.

It is not possible therefore to order the parent model by the child when you have not yet loaded the child.

The power of collections comes to your aid and allows you to sort the collection after it has been merged with the child relation;

$result = Users::with('order')->get()->sortBy('order.price);

You have a conflict however. Since you have orders (plural) the relationship is itself a collection and cannot be sorted in the same way.

What if User 1 has one order of '10' and user 2 has one order of '5' and another of '6' - which user should be listed first?

In such cases, its usually better to list all the orders with their user as the related model.

Snapey left a reply on Filter By Unanswered Questions • 1 day ago

$topics = App\Topic::doesntHave('comments')->get();

Snapey left a reply on ErrorException In HasRelationships, Class Not Found • 1 day ago

it's at this point I try random things like Composer dump-autoload

Your category model looks fine. Your Genre model looks fine

just check, the filename of your genre model is Genre.php and not genre.php

Snapey left a reply on ErrorException In HasRelationships, Class Not Found • 1 day ago

Can you post the top 10 or so rows of the stack trace?

Snapey left a reply on Send User Password Reset Link After Creation By Admin • 1 day ago

create a mailable and send the new user a notification.

Its easy enough, just a matter of putting the components together

You can pick up some ideas from Matt Stauffer's post https://blog.tighten.co/creating-a-password-less-medium-style-email-only-authentication-system-in-laravel

This is about adding password verification to the registration process but a lot of the steps once the account is created will be the same.

Snapey left a reply on ErrorException In HasRelationships, Class Not Found • 1 day ago

remove the braces from each @if($category->genre()->name == 'Fiction')

eg @if($category->genre->name == 'Fiction')

but you should really eager load them in the controller;

$categories = Category::with('genre')->get();

Snapey left a reply on Routes Problem With Controllers • 1 day ago

No, just remove those lines.

Snapey left a reply on Routes Problem With Controllers • 1 day ago

This in your controller

    public function __construct()
    {
        $this->middleware('auth');
    }

says you must authenticated to access any of the methods,

Snapey left a reply on Routes Problem With Controllers • 1 day ago

because when you go to / it gets sent to your controller but caught by the auth middleware

Are you logged in when you do these tests?

Have you changed the App/Exceptions/Handler.php?

Snapey left a reply on Routes Problem With Controllers • 1 day ago

I see you have authentication specified in the controller

So, when you try it in the web,php file, no authentication is performed.

When you try it in the controller, something is happening to redirect to /index my guess is that you know something about that?

Snapey left a reply on How To Use Created Event In Laravel 5.4? • 1 day ago

You can create an observer class, or put this in each of your models;

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

        self::creating(function ($model) {

            $model->createdBy = Auth::user()->id ?? 0;
        
        });
    }

This hooks into the creating event and inserts the id of the current user. Note that it will fall over if no-one is logged in, so the ?? (php 7) will set it to zero if that is the case.

Remember to import Auth at the top of the model also

use Auth;

Snapey left a reply on Routes Problem With Controllers • 1 day ago

Show your complete controller please?

Snapey started a new conversation Popular This Week And Popular All Time • 1 day ago

Hi @JeffreyWay

perhaps the Popular threads should by the number of participants rather than how chatty two people have been about an issue?

Snapey left a reply on Session Id At Login Changes • 1 day ago

It will only be called if the user clicks logout.

The server is doing nothing in the background when there are no requests, and when there are requests, randomly, expired sessions are cleaned up by deleting the session records. I would be surprised if the event is called then but admit I don't know?

Snapey left a reply on Laravel RAM Usage Problem • 1 day ago

So you build a site that shows a list of users, maybe it allows posts and comments.

But then you realise that you need to do session management better, and then perhaps an ORM would help, oh, and an eventing system... ok, so Ram use is starting to creep up a bit.

Oh, and we want to send emails from our application, and some caching would help, plus its really tedious building out views without any helpers, and some middleware would help filtering and processing of requests, plus some things need to come in via ajax into an API.

Wow, these images on my cheap shared server are really eating up the space, perhaps I ought to create a storage framework that allow images to be pushed off to S3.

It would be nice to have some sort of mechanism that allows notifications to be pushed to users so that they know when their friends have posted....

But hey, I now have a right bunch of spaghetti code and my Ram use is really worryingly high

I wish I had just gone with a polished framework in the first place since now I have all this functionality I'm using a lot more RAM than I expected.

Oh F-it I'll just get a server with 2GB ram since ram is so cheap these days.

Snapey left a reply on How To Save Html And Markdown For A Model, 2 Columns Or 1? • 1 day ago

I would probably have a type column and store in that, if the content was created as html or markdown.

Then use that flag when rendering the output.

The choice is then per post, rather than a config setting.

The user might like an option to switch type, in which case, you migrate the content and change the flag.

You can have something like a 'getBodyAttribute()' accessor that checks the flag and returns the html or parses the markdown and returns the result

Also a getBodyRawAttribute() accessor that just returns body without any processing for use in your edit form.

24th March, 2017

Snapey left a reply on Querying Nested Relations (once More) • 2 days ago

1st option $project->metadata_registry->title

assuming the obvious answer is not the one you want, in the project model;

public function getTitleAttribute()
{
    return $this->metadata_registry->title;
}

this will cause a failure if the relation is not loaded so you can check first if necessary

public function getTitleAttribute()
{
    if(!$this->relationLoaded('metadata_registry')) {

        $this->load('metadata_registry');

    }
    
    return $this->metadata_registry->title;

}

Snapey left a reply on Laravel RAM Usage Problem • 2 days ago

worry about it when it becomes an issue... not now.

Snapey left a reply on Splitting One Table Into Two Tables • 2 days ago

you accidentally ran it twice?

Snapey left a reply on Blade - How To Concatenate Input Fields To Create Query String? • 2 days ago

why make life complicated? just send them to your controller as two parameters

http://localhost/search?type=namestartswith&term=Lara

Snapey left a reply on Eloquent Dropping HTML Tags? • 2 days ago

Thats good. I suspected something like that which is why I was asking questions.

Snapey left a reply on Eloquent Dropping HTML Tags? • 2 days ago

how are you creating the breaks?

Snapey left a reply on How To Pass Data To Specific View In Laravel 5.4 • 2 days ago

you pass the value from the controller.

if you need the variable on every page, because it is in your master layout, then you need to put the code in a view composer.

as suggested 12 hours ago

Snapey left a reply on Eloquent Dropping HTML Tags? • 2 days ago

so, you write the excerpt listed to the database and then viewing the record with your favourite sql tools, the br's have all vanished?

It would be a pretty bad database if that happened.

What are we missing from the story?

Snapey left a reply on Understanding The Move And The StoreAs Methods For Saving/uploading Files To The Filesystem • 2 days ago

it's all explained in the docs.

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

store will use your default disk, which you can set to be other than the storage folder, or, you can create a new disk in config and then specify that as the second parameter for the store command.

Snapey left a reply on Define Relation From Table With Link Tables Primary Key • 2 days ago

if you cannot describe what that table is doing for you then it's probably not needed.

What do you mean, no easy way of looking for type or manufacturer. In what context?

Snapey left a reply on Redirect User After Log In To Different Pages According To Its Type LARAVEL 5.4 • 2 days ago

you were following the right approach in the first place. I suggested a way to identify that it was the guest middleware causing the issue, but I cannot see that you tried it?

Snapey left a reply on Looking For A Vue Js Csv Parser. • 2 days ago

You want to parse csv file in the client?

Edit Your Profile
Update

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