Borisu

Experience

90,750

47 Best Reply Awards

  • Member Since 1 Year Ago
  • 596 Lessons Completed
  • 22 Favorites

20th February, 2018

Borisu left a reply on Route Has Only One Parameter • 12 hours ago

Not really. The most you could get is a route like /files/{files}/filename/{filename} and that's just wrong in your case and would also completely change the api

Borisu left a reply on How Do I Dependency Inject When Already Using Constructor Params? • 12 hours ago

Just use a trait, it's simple and easy

class SomeClass extends AbstractClass
{
    use InjectedClass;
    // other code...
}

This way you have access to the methods on InjectedClass. The other solutions are also valid, it's just preference.

Borisu left a reply on Should I Use Model Relationships Vs Query Scopes And A Simple Mysql Join? • 21 hours ago

In addition to blishmar's post, you can specify which fields you want in the end model:

$org->get(['name', 'created_at']);

As you can see you can just pass an array of values to the get function and you'll filter the fields you want.

18th February, 2018

Borisu left a reply on Should I Use Model Relationships Vs Query Scopes And A Simple Mysql Join? • 2 days ago

No the hasMany on one model does not interfere with the hasMany on another. You could do this

// on Org
public function members()
{
    return $this->hasMany(Member::class);
}

// on Member
public function org()
{
    return $this->belongsTo(Org::class);
}

public function user()
{
    return $this->belongsTo(User::class);
}

But if you have a belongsTo relationship you need the user_id and org_id in your database table for members.

17th February, 2018

Borisu left a reply on Checkboxes And Model Updating Revisited For Laravel 5.5 And Above • 3 days ago

@jgt I meant use that in your trait. @Cronix you're right hehe :) even better.

16th February, 2018

Borisu left a reply on Delete Confirmation In Modal • 4 days ago

To put it all together:

...
<div class="comment">
    <form id="form-{{ $comment->id }}" method="POST" action="/comment/delete/{{ $comment->id }}">
        ...
        <button class="btn btn-danger" data-toggle="modal" data-target="#confirm-modal">
    </form>
</div>
...

<script>
    $('#confirm-modal').on('shown.bs.modal', function (event) {
        $button = $(event.relatedTarget);
        $form = $button.parent('form');
    });
    $('#confrim-modal button.confirm').on('click', function(e) {
        e.preventDefault();
        $form.submit();
        $form = '';
    });
</script>

You might have to put a preventDefault on the form button, I'm not sure. Good luck.

Borisu left a reply on Delete Confirmation In Modal • 4 days ago

@slickness Yes there is. You show the modal with javascript. At that point you have the event.target which is the form you're trying to submit. You take that id and use it when the user clicks a generic button called "confirm" to trigger the submit action on the form.

@wilk_randall by the way I don't understand what is your problem with me? Just make your suggestions and don't try to put words in my mouth. If you disagree with something there are better ways to address them...

Borisu left a reply on Checkboxes And Model Updating Revisited For Laravel 5.5 And Above • 4 days ago

@jgt Ah yes, I understand now, silly me :D

Is the following not sufficient:

$field = $request->has('isRequired') ?? false;

This way your trait will be much simpler and easier to digest.

Borisu left a reply on Checkboxes And Model Updating Revisited For Laravel 5.5 And Above • 4 days ago

I can't understand your premise and question. Maybe it's just me, but it would be helpful to know where this problem stems from :)

Borisu left a reply on Delete Confirmation In Modal • 4 days ago

I wasn't clear enough. The form is attached to the comment, not the modal:

<comment>
    ...
<form id="comment-{{ $comment->id }} action="{{ route('comments.destroy', ['id' => $commentId]) }}" method="POST">
    {{ csrf_field() }}
    {{ method_filed("DELETE") }}
    <button type="submit" class="btn btn-danger">Löschen</button>
<form>
</comment>

He is already capturing the button click, which means he has access to the form id. It's then trivial to just wait for the confirm click and resubmit the form. An added benefit to this method is that it works even if JavaScript is disabled.

15th February, 2018

Borisu left a reply on Should I Use Model Relationships Vs Query Scopes And A Simple Mysql Join? • 5 days ago

You can make as many relationships as you want, meaning:

// on Organization
public function records()
{
    return $this->hasManyThrough(UserRecord::class, Member::class);
}

Furthermore you can use where clauses on the relationship itself to further filter your results. Don't be afraid to reuse Relationships combining them with where clauses etc. You can do whatever you need to do ;)

Borisu left a reply on Route File Showing Both Product Name And Product Id • 5 days ago

Hey @Shawdow, you don't need to put the action() in your href. Just make it

<a href="/products/{{ $product->name }}/{{ $product->id }}">...</a>

Notice the double quote, it's important.

Then since you only need the id to catch a product you can use a wildcard for the route

// in routes/web.php
Route::get('/products/*/{product}', '[email protected]')

// in app/Http/Controllers/ProductsController.php
public function show(Product $product)
{
    return view('products.show', compact('product'))
}

NOTE: This will work only if the product name is on the same table as the id. Otherwise you'll have to do it another way.

Borisu left a reply on Delete Confirmation In Modal • 5 days ago

@wilk_randall I have to disagree with you. Why would someone add a delete button to a resource that does not exists? Makes no sense. The route you suggest is pointless as well. It's a delete route, not a get where optional parameters are acceptable.

Borisu left a reply on End To End Testing Of A Network Service • 5 days ago

Awesome, you might post a snippet here just to help someone in the future ;)

Borisu left a reply on Custom Validation Rule Issue • 5 days ago

You have to use the bail rule to tell Laravel to stop validating after a failure.

https://laravel.com/docs/5.5/validation#quick-writing-the-validation-logic

Borisu left a reply on How Do I Dependency Inject When Already Using Constructor Params? • 5 days ago

I personally would prefer the trait approach and use it on the concrete class itself, not the abstract class. The injection method is also nice, but in my opinion not necessary when you're using just one method. If you have more complex needs then it's worth it. (by the way I wouldn't inject the target class in the abstract class, rather anywhere else you need it)

Borisu left a reply on Route File Showing Both Product Name And Product Id • 5 days ago

So what is your question?

Borisu left a reply on Delete Confirmation In Modal • 5 days ago

@slickness Do the following:

<form action="{{ route('comments.destroy', ['id' => $commentId]) }}" method="POST">
    {{ csrf_field() }}
    {{ method_filed("DELETE") }}
    <button type="submit" class="btn btn-danger">Löschen</button>
<form>

This form is on your modal, so you don't need any javascript to execute it. As soon as the user clicks on Löschen you will submit and that's it. Note: the second parameter in the route() helper is an array of the values you pass to your route. Make sure the key 'id' has the same name as in your route.

14th February, 2018

Borisu left a reply on Delete Confirmation In Modal • 6 days ago

@slickness What steps did you take this far?

Borisu left a reply on End To End Testing Of A Network Service • 6 days ago

Hehe awesome :D

13th February, 2018

Borisu left a reply on End To End Testing Of A Network Service • 1 week ago

Maybe use inotify. It's still a while loop, but a good one ;)

https://www.simplicity.be/article/watching-files-and-directories-php/

Borisu left a reply on BBP For Routes • 1 week ago

Preferably pointing to a controller. You want to keep the routes files as tidy as possible and as simple as possible

Borisu left a reply on AppServiceProvider.php • 1 week ago

Yes

Borisu left a reply on Delete Confirmation In Modal • 1 week ago

@wilk_randall Ok, you're right.

@slickness Did you have any success so far with fixing the issue?

12th February, 2018

Borisu left a reply on Delete Confirmation In Modal • 1 week ago

It's in the docs...

Borisu left a reply on Delete Confirmation In Modal • 1 week ago

Did you compile and import the necessary javascript?

Borisu left a reply on Is There A Callback Function On Successful Reset Password. • 1 week ago

There is no function, but a new Event rather. It's called PasswordReset. You can make a Listener and use it to do whatever you want ;)

Borisu left a reply on Add The Value Of Multiple Records • 1 week ago

@pickab00 No problem :)

Borisu left a reply on First Laravel Package • 1 week ago

Hi, it commendable that you want to extend Laravel, but I think you'll have a difficult time convincing people to install a package just to change the notation of rules. In any case the code is simple and looks clean. I hope it helps someone :)

Borisu left a reply on Laravel Unique Email Validation Is Not Working On Different Character Case In Mongodb • 1 week ago

It's working correctly, since the string [email protected] is different from the string [email protected] You can make a custom rule, which will transform the user input to lower string when checking

Borisu left a reply on How To Create A Custom Guard To Authenticate The API Request. • 1 week ago

Watch this: https://www.youtube.com/watch?v=iKRLrJXNN4M&t=10s It will explain how to make custom guards etc.

Borisu left a reply on Add The Value Of Multiple Records • 1 week ago

Something like this:

$records = Model::find([1, 2, 3, 4, 5])->pluck(['bottle', 'beer', 'water']);
$sum = $records->sum('bottle')  + $records->sum('beer') + $records->sum('water');
$main = Model::find(6)->pluck(['bottle', 'beer', 'water']);
$mainSum = $main->bottle + $main->beer + $main->water - $sum;

Not the absolute cleanest way, but I'm really sleepy today and it'll work :D

Borisu left a reply on AppServiceProvider.php • 1 week ago

@davy_yg It means get the database records from the advertisements table (comes from the model name) where('ad_type', 'slider') filter them so that only the ones where the column 'ad_type' = 'slider' are shown latest() order them by date created, starting with the last one get() perform the actual query to the database.

10th February, 2018

Borisu left a reply on Adding A New Package Without Automatically Adding Dev Dependencies • 1 week ago

You should only see it under "require", not "require-dev".

Borisu left a reply on Simple Multistep Form • 1 week ago

Well the problem is that you're trying to set a property on form-3 while in form-2. You'll either need to warp all three forms in a form-master and handle passing variables from there or I think that with this level of complexity it's useful to take a look at Vuex (https://vuex.vuejs.org/en/). But in any case the solution I suggested would look like this:

// in FormMaster.vue
<template>
<div>
    <form-1 @finished='completeForm1' v-if='show1 == true'></form-1>
    <form-2 @finished='completeForm2' v-if='show2 == true'></form-2>
    <form-3 @finished='completeForm3' v-if='show3 == true'></form-3>
</div>
</template>

<script>
export default {
    data() {
        return {
            show1: true;
            show2: false;
            show3: false;
        }
    },
    methods: {
        comleteForm1() {
            this.show1 = false;
            this.show2 = true;
        },
        ...
    }
}
</script>

So there are better ways to do this (for example just have a var next and prev and increase their value so your users can scroll between forms), but to get a general idea this should be enough.

Borisu left a reply on How To Cross-reference User's, Product's Locations • 1 week ago

Well you could just use the relationship "hasManyThrough" to connect the user to a location. Then your code would be

if ($user->locations->contains('location', '90210') { // do stuff; }

where 'location' is a key name, where you'll look for 90210. The relationship looks like this:

// on User
public function locations() {
    $this->hasManyThrough(Location::class, Product::class);
}

Check the docs for more info ;)

Borisu left a reply on Validating 2 Dropdown • 1 week ago

Yes, but it would be best to make a custom validation rule. Check the docs: https://laravel.com/docs/5.6/validation#custom-validation-rules

Then you use it as follows:

request()->validate([
    'room' => [
        CustomValidationRule($params),
        'some-other-rule',
    ]
]);

Borisu left a reply on Display A One Time Popover Message When Date Selected • 1 week ago

Well something along the lines of:

let displayed = false;
document.querySelector('select#special').addEventListener('click', function(event) {
    if (displayed === false) {
        // display your message...  
    }
});

I've written it in vanilla js, but it would be much easier to use some kind of framework. And for the message you could use this library which is pretty cool: https://sweetalert2.github.io/

Borisu left a reply on Adding A New Package Without Automatically Adding Dev Dependencies • 1 week ago

Are you sure it's actually in your dev dependencies? Check your composer.json file. If it's there just delete it from require-dev.

Borisu left a reply on AppServiceProvider.php • 1 week ago

It's fairly simple. Usually the user requests a page, the settings in your routes file points to a controller and a method on the controller that handles that request. In the method your collect the data for the page and then pass it to a view (just a php template with html). When you use a view composer you can add variables to certain views.

In this example you are assigning a slides variable the result of the getSlides() method on a Advertisements class. \App\Advertisements::getSlides() returns some kind of data, then you can use it in your view:

<div>{{ $slides }}</div>

When the application runs it will compile the curly braces and return the value of the method. At the end it's something like this (but grossly oversimplified):

<div>
<?php
    echo \App\Advertisements::getSlides();
?>
</div>

Hope this helps.

9th February, 2018

Borisu left a reply on Where To Store A Json Configuration File In The Codebase? • 1 week ago

Well spatie for example keeps them in the storage/app/ folder and I dare say he has his fair share of packages. There's not right or wrong way tho... Just what feels good to you ;)

Borisu left a reply on Simple Multistep Form • 1 week ago

You can have this:

<body>
    <form-component-1></form-component-1>
    <form-component-2></form-component-2>
    <form-component-3></form-component-3>
</body>

Each form component has it's own structure. For the form handling you can have a Form class (check out the Vue courses on laracasts).

Borisu left a reply on Simple Multistep Form • 1 week ago

Ok you're on the right way. You are returning a response with the user_id. In your JavaScript you can accept the response in your

axios.post('', {})
    .then(response => {
        this.user_id = response.data.id;
});

callback and assign it to a data variable. After that just continue as usual. I would suggest that you do everything in one component until it works and afterwards extract components for each separate form (part of the multi-form).

Borisu left a reply on Desktop Notifications • 1 week ago

@Ebenezer The only way I know is through the Console Kernel schedule function. (Don't forget to include the cronjob on your server ;))

Borisu left a reply on JQuery In Vue Method • 1 week ago

I notice two thing, first you don't need this line:

 $('.custom-dropdown ul li').click(function()

The two jQuery calls can live outside of it. Instead of $(this) you can use $(event.target). Second your ul doesn't have the 'opened' class per default, that's why it's not opened on page load.

Borisu left a reply on Simple Multistep Form • 1 week ago

Try editing your post

Borisu left a reply on Waiting For Jeffrey Way's What's New In Laravel 5.6 • 1 week ago

hehe you too huh?

8th February, 2018

Borisu left a reply on Rename Table Using Migration • 1 week ago

Mark as resolved..

Edit Your Profile
Update

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