Snapey

at Novate / Microlise

Hire Me

Experience

927,035

1405 Best Reply Awards

  • Member Since 3 Years Ago
  • 898 Lessons Completed
  • 1 Favorite

26th April, 2018

Snapey left a reply on Show Single Post In Laravel With Ajax Call • 8 hours ago

isn't val() just for form input elements (things that use value=) should you instead use .html() ?

You don't show the actual single post code

Snapey left a reply on Unable To Update Record • 9 hours ago

the unique rule takes three parameters. The name of the table, the name of the field, and the id of the row that should be ignored

My example joins the id to the parameter list with concatenation

You dont have any other fields you need to force to be unique?

Snapey left a reply on Show Single Post In Laravel With Ajax Call • 9 hours ago

any console errors?

the problem could be getting the value or setting the .val

if between the the you console.log the variables are they being set according to the bitton clicked?

Snapey left a reply on Cant Understand Eloquent Distinct • 9 hours ago

sorry, doesnt make any sense to me?

Snapey left a reply on Unable To Update Record • 9 hours ago

you are saying that the title must be unique but ignoring the record I am currently updating

I dont understand your question?

Snapey left a reply on Show Single Post In Laravel With Ajax Call • 9 hours ago

where is ajax?

Snapey left a reply on Unable To Update Record • 9 hours ago

using the example from the docs

'email' => 'unique:users,email_address,'.$user->id

so your equivalent would be

'title' => 'required|max:255|unique:products,title,' . $product->id,

then you can also remove the Rule line

Snapey left a reply on Unable To Update Record • 9 hours ago

you are trying to mix two different methods of defining the same thing.

Plus, your ignore needs to ignore the same record, not the same title

Snapey left a reply on Retrofit • 9 hours ago

Where's the thumbs down button?

Snapey left a reply on Deploying A Laravel Application To DreamHost Shared Hosting • 10 hours ago

You are getting ahead of yourself with one link;

Deploy Laravel 6 application on shared hosting

:-)

Snapey left a reply on Cant Understand Eloquent Distinct • 10 hours ago

If you just want to know all the first_names so that you can list them in a dropdown for instance, then;

User::distinct()->pluck('first_name');

will give you a list of all the firstnames in the database

If, on the otherhand, the user has already selected 'john' from the dropdown (or keyed it) and now you want to list all the Johns ("and to show all of user data") then its a simple where that is required

$users = User::where('first_name',$first_name)->get();

Snapey left a reply on One To Many And Inverse 'Class Not Found.' • 10 hours ago

If you want to see 4 zones in realm 1

$zones = Realm::find(1)->zones()->get();

This will load just the zones

To load them as children of Realm1 (so they are nested)

$realm = Realm::with('zones')->find(1);

And then the zones will be listed under relationships when you do a dd

25th April, 2018

Snapey left a reply on One To Many And Inverse 'Class Not Found.' • 18 hours ago

If your models are in the same namespace (App) then you can either

remove the use and put like

    public function realm() {
        return $this->belongsTo(Realm::class);
    }

or remove the use and put like

    public function realm() {
        return $this->belongsTo('App\Realm');
    }

Snapey left a reply on Radio Button Issue • 22 hours ago

use the user->id instead of $i

Snapey left a reply on Radio Button Issue • 22 hours ago

Please format your code so that it makes sense in the forum. Put ``` before and after the code

Snapey left a reply on Unclear Documentation • 23 hours ago

replaceing one of them with lalalala and see what happens

What? Faker won't know what lalalala is? Why should it? What has that got to do with the name of your columns?

Faker's job is to create random data - what you do with it is up to you. It does not need to go in a database.

Snapey left a reply on Can't Turn An Object Into An Array. • 23 hours ago

The class would need to implement a toArray() method, but I'm guessing you cannot modify it?

Snapey left a reply on Unclear Documentation • 1 day ago

Are you sure?

The factory is injected with an instance of faker, and then you just grab the attributes;

From the github docs;

// generate data by accessing properties
echo $faker->name;
  // 'Lucy Cechtelar';
echo $faker->address;
  // "426 Jordy Lodge
  // Cartwrightshire, SC 88120-6700"

This is all I have done..

Snapey left a reply on Need Help Category Wise Post Show • 1 day ago

You already said this. Thats NOT what I asked

Snapey left a reply on Can't Turn An Object Into An Array. • 1 day ago

I need it to be an array so I can work with it

Why? Just because that is familar? PHP works very well with objects

Snapey left a reply on Strange BelongsToMany Problem • 1 day ago

The convention is the model names in alphabetical order, so your table should be category_role

You can do it without using convention but then you need to mention the table name in your relationship

Snapey left a reply on Need Help Category Wise Post Show • 1 day ago

Can one post belong to just one category, or many categories?

Snapey left a reply on Redirect Problem • 1 day ago

The problem is, you cannot have POST in a redirect.

Redirects are always GET so you need to change the way the like function works.

You can post for logged in users, but for guests the Like will need to take them to a page where they then press Like again, after it has been to the login page.

If you put the like get route inside auth group then the guard will intercept the user and they will be sent to the intended route once logged in

Snapey left a reply on Need Help Category Wise Post Show • 1 day ago

If you have a route /category/{category} and you open /category/woman

In categories controller, show method

public function show(Category $category)
{
    $posts = $category->posts()->get();

    return view('category.show')->withCategory($category)->withPosts($posts);
}

provided you have posts() method in Category model then it should be as simple as shown.

Snapey left a reply on Need Help Category Wise Post Show • 1 day ago

What does that mean? all the posts in a category?

24th April, 2018

Snapey left a reply on How To Send Mail Using Gmail Account • 1 day ago

Its also confusing if you use gmail to send email using your own account, and the recipient is also yourself then the mail ends up in your sent mail and not in your inbox.

Really, its not worth the aggro

Snapey left a reply on Cannot Update My Data From My Edit From • 1 day ago

@rin4ik Laravel magic. If you pass model as the second parameter the route helper takes what it needs

@Vilfago Laravel magic. if you only need to pass one parameter to the route then the helper accepts it as the second parameter. If you need more than one parameter then they must be posted as an array

Snapey left a reply on Cannot Update My Data From My Edit From • 1 day ago

hang on you lot, I've not proposed a different way yet...

Snapey left a reply on Url Previous - Moving Between More Pages • 1 day ago

After updating data, you redirect back to the same page or its parent.

For example, if you are on /orders and you click edit on an item, ypu might load /orders/edit/1

after posting data to that order, you finish with redirect('/orders') rather than previous

Snapey left a reply on How To Add $request Values To My Validation Request In Controller? • 1 day ago

or use the request() helper as you did earlier

Snapey left a reply on Laravel 5.4 Nested @foreach • 1 day ago

Your terminology is all messed up and is not helping.

So in the controller, you have $orders, and this is a query of OrderDetail but then you are referring to it as orders list - as if it is a list of orders? not a list of details?

It looks like you are getting all the order details and then grouping them by the order_id

You are not making it easy for yourself.

Most people would get a list of orders and then attach the order details to each order with eager loading.

Snapey left a reply on Laravel Security Issue • 1 day ago

The XSS issue with vue is most easily fixed by removing app from the <div id="app"> tag of the default layouts so that Vue cannot bind to it.

The disappointing thing about it is that it affects projects that don't know or care about Vue, and just use boilerplate layout.

In Martyyy's case, he is not seeing this in his database - just a straightforward script tag. This should be escaped by the blade {{ }} but I see too many people outputting raw data - particularly in forms

The script linked in the username, if executed, sends the user's cookies etc to a 'mothership' server. In this case its a client side javascript injection, but if you can cause tags to be rendered in user content, then why not php?

Always escape user input folks!

Snapey left a reply on Laravel Security Issue • 2 days ago

I should add that only sites BUILT after those versions are protected. Sites that are upgraded are still vulnerable to the XSS issue

Snapey left a reply on Laravel Security Issue • 2 days ago

the following versions were patched against this issue 5.6.9 and 5.5.37.

https://medium.com/@taylorotwell/js-frameworks-server-side-rendering-and-xss-722805009892

Snapey left a reply on Laravel Security Issue • 2 days ago

You say in the name field? Do you mean the name on the user model?

There was a security issue with the default auth setup that allowed someone to create a username with script embedded that would be executed unchecked by vue

It looks like this could have been used. This is bad news for the community if this is the case

Snapey left a reply on Laravel Security Issue • 2 days ago

oh dear.

You have to cleanse the data yourself before saving to the database, eg html purifier

If you are taking user input, putting it in the database as supplied, you are still protected in the main by escaping output with {{ }}

But, if your db credentials are exposed, the original attacker could have put those values there in the database directly

Snapey left a reply on My Laravel Bootstraps Does't Work • 2 days ago

please LOOK at my THREE questions

Snapey left a reply on My Laravel Bootstraps Does't Work • 2 days ago

There were three questions ?

Snapey left a reply on My Laravel Bootstraps Does't Work • 2 days ago

have you removed app.css and app.js from your layout?

Why do you load both boostrap.css and the minified version of the same thing boostrap.min.css ?

Have you put the files in public/css folder?

Snapey left a reply on What Will Be The Equivalent Query Of This Query In Laravel? • 2 days ago

$data1 = Category::where('category_name',$data)->get();

where you expecting something more complicated?

The above will return a collection of results. If you are expecting to get only one result, then use first()

$data1 = Category::where('category_name',$data)->first();

Snapey left a reply on Remembering Id When Time Is Ended • 2 days ago

do the timing in javascript?

load the view with start and stop buttons

user presses start. Have an onclick event that notes the current time.

When they click stop, get previous and current time, work out the difference an post it to the server with ajax

23rd April, 2018

Snapey left a reply on I Have Form That Adds Multiple Records With Single Field (allows Nulls). How Can I Add Additional Fields? • 2 days ago

If you get to it you will find that my approach allows you to more easily apply validation like;

'books.*.isbn' => 'required|max:20',
'books.*.title' => 'max:50',

Snapey left a reply on I Have Form That Adds Multiple Records With Single Field (allows Nulls). How Can I Add Additional Fields? • 2 days ago

Sorry, missed;

public function wanted(Request $request)
    {
        $uid = Auth::user()->id;
        foreach($request->books as $onebook) {
                if(is_null($onebook['isbn'])) continue;
                    DB::table('wantedbooks')->insert([
                       'isbn' => $onebook['isbn'],
                       'title' => $onebook['title'],
                       'user_id' => $uid]);
            }
        return view("bookswantedsubmitted");
    }

post what you have now.

Snapey left a reply on Have Multiple Users To One Account • 2 days ago

they all can login and are associated to the company (including the owner)

Then when deciding if to show the owners admin screens, you just need to check

if(Auth::user()->company->owner_id == Auth::id()) { // its their company

of course you could extract this to a method

Snapey left a reply on Have Multiple Users To One Account • 2 days ago

yes company would have many users

user that is owner can admin the account

Company model

public function owner()
{
    return $this->belongsTo(User::class, 'owner_id' , 'id');
}


Snapey left a reply on I Have Form That Adds Multiple Records With Single Field (allows Nulls). How Can I Add Additional Fields? • 2 days ago

amend each table row like

<tr>
  <td style="padding-bottom: 3px">
    <input type="text" name="books[]isbn" placeholder="enter isbn..." />
  </td>
  <td>
    <input type="text" name="books[]title" placeholder="Enter title..." />
 </tr>

then in the controller

public function wanted(Request $request)
    {
        $uid = Auth::user()->id;
        foreach($request->books as $onebook) {
                if(is_null($onebook)) continue;
                    DB::table('wantedbooks')->insert([
                       'isbn' => $onebook['isbn'],
                       'title' => $onebook['title'],
                       'user_id' => $uid]);
            }
        return view("bookswantedsubmitted");
    }

Snapey left a reply on Passing A Model From FormRequest To The Controller • 2 days ago

Im not sure you can bind more than one model, so you would probably just find it using the slug.

Snapey left a reply on Refactor Store() Method When Handling More Than One Entities While Saving Data • 2 days ago

let spatie media manager look after it for you

Edit Your Profile
Update

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