vladshoob

Experience

31,430

2 Best Reply Awards

  • Member Since 2 Years Ago
  • 299 Lessons Completed
  • 0 Favorites

22nd September, 2018

vladshoob left a reply on How To Calculate And Update Users Rank Fast In This Case? • 3 weeks ago

So, your $coin is basically $coin++ for every activity.

Remove $rank entirely.

And then search for positions instead. Like in this stackoverflow thread.

https://stackoverflow.com/questions/3614666/mysql-get-row-position-in-order-by

30th May, 2018

vladshoob left a reply on Install Laravel On Digitalocean By LAMP • 4 months ago

Thanks for an awesome tutorial. It worked like a charm for my first website on server.

But now I am trying to add another application, in addition to first one, but to use 8080 port.

I created app2.conf file in sites-available directory. with content

Listen 8080

# Listen for virtual host requests on all IP addresses
NameVirtualHost *:80

<VirtualHost *:8080>
    ServerName app2.test
    ServerAlias Xxx.ZxZ.1X7.XxX #server ip, I need it to be same as app1

    #same, but pointed to app2 directory
</VirtualHost>

And after restart server.ip:8080 is still not available, sadly.

Maybe some hints? Thanks in advance.

7th February, 2018

vladshoob left a reply on Query Builder "addGroupBy()" Function Doesnt Works. • 8 months ago

I beleive you don't need array in select statement. If sessions has display_name column then it suppose to show up. If it is not then it is hidden in model.

vladshoob left a reply on Query Builder "addGroupBy()" Function Doesnt Works. • 8 months ago

You may use just like here:

// given we have a query
$query->groupBy('sites.name', 'programs.name' );

vladshoob left a reply on With() And Leftjoin() In Laravel • 8 months ago

@afoysal , @bashy ment this.

$applicants = Applicant::leftJoin()->with('applicant_skill')->paginate();

2nd February, 2018

vladshoob left a reply on Routing Url To Controller/action • 8 months ago

And then maybe use defined names for routes.

Route::get('/explanation', '[email protected]')->name('en.explanation');
Route::get('/erklarung', '[email protected]')->name('fr.explanation');
Route::get('/explication', '[email protected]')->name('sp.explanation');

So later it will be possible to create urls in blade.

{{ route(App::getLocale() . '.explanation') }}

And my redirect function actually does not suppose to redirect. It was just a bad naming. It supposes to use another function in some controller. And that function will deal with rendering.

vladshoob left a reply on Where Are You All From? • 8 months ago

Kyiv, Ukraine

vladshoob left a reply on Basic Introduction • 8 months ago

It depends on preferences what to use. Probably you will end up using both to some extent, as bootstrap.js using jquery

jQuery is kind of "old fish" and there are a lot of useful things written already.

Vue.js is kind of new cool thing. A lot of tasks are just so easier with it than without.

vladshoob left a reply on Routing Url To Controller/action • 8 months ago

You may set locale on .env file for each website. Make custom config('app.locale') for this. I assume each domain will require separate codebase.

1st February, 2018

vladshoob left a reply on Escaping {{ Env('VAL1') }} When Rendering From Database • 8 months ago

It is not good idea. I've tried several ideas;

1 - using call_user_func('config', 'app.url') function, but faced escapind problem as well

Nest will work, but it will be kind of ugly.

/// Given we have string
$string = "<p>{{ config('app.url') }}</p>"

// find elements before {{
echo $before;

// escape echo
// find parts of functions with regex
echo call_user_func('config', 'app.url')

// find elements after
echo $after;

I think there is no easy solution for partially escaping string by blade.

Please post if you will be successful with this later. I will be glad to see solution.

vladshoob left a reply on Routing Url To Controller/action • 8 months ago

I made something similar recently. I needed very nice product urls (site.com/product_alias).

In the very end of your routes you may do something like this.

Route::get({controller}{action}, '[email protected]');

In your RoutesController you will need something like this:

public function redirect($controller, $action) {
\App\Http\Controllers\{$main}Controller::{action};

// I don't really know how to make this line work, but I think it is possible
}

As for me, I may turn it around if multilanguage is required. In routes file

Route::get('/{language}/contact', '[email protected]');
Route::resource('/{language}/products', 'ProductsController');

And in your controller store language in user session and present information in required languages.

10th January, 2018

vladshoob started a new conversation Install Mailparser Extension On Laravel Homestead • 9 months ago

I've tried everything. Really...

How to install this beautiful thing?

https://packages.debian.org/source/stretch/php-mailparse - i beleive here is the latest

and all commands from here make mistakes, such as 'missing mbstring' when it is in place http://wiki.cerbweb.com/Installing_PHP_Mailparse

Thanks in advance.

1st December, 2017

vladshoob started a new conversation How To Validate .docx File? • 10 months ago

I'm trying to upload .docx file with this code:

        $validated = $request->validate([
            'file' => 'mimes:application/vnd.openxmlformats-officedocument.wordprocessingml.document'
        ]);

dd($request) shows me this mime for a file, but for some reason it is not validated. I tried to add zip, app.../msword, docx mimes to validation rules, but not successfully.

Thanks in advance.

29th November, 2017

vladshoob left a reply on Filter Products By HasMany Relation • 10 months ago

SOLVED using crossjoin.

$query = $this->builder->Join('subproduct_attributes AS first', 'first.subproduct_id', '=', 'subproducts.id')
                                ->select('subproducts.*',
                                        DB::raw('first.subproduct_id AS sub_id'),
                                        DB::raw('first.property_id AS prop_id'));

        $previous_table = 'first';
        $i = 1;
        foreach ($array as $slug => $attribute) {
            $keys = [];

            foreach ($attribute as $property_key => $value) {
                                // Quick check for property existence
                if (AttributeProperty::find($property_key)) {
                    $keys[] = $property_key;
                }
            }

            // if it is first iteration do not crossjoin
            if ($i == 1) {
                $query->whereIn('first.property_id', $keys);
            } else {
                $query->crossJoin("subproduct_attributes AS $slug", function ($join) use ($keys, $slug, $previous_table) {
                    $join->on("$slug.subproduct_id", '=', "$previous_table.subproduct_id")
                            ->whereIn("$slug.property_id", $keys);
                });;

                $previous_table = $slug;
            }

            $i++;
        }

vladshoob left a reply on Filter Products By HasMany Relation • 10 months ago

Some idea came at night

SELECT t1.id, t1.subproduct_id, t1.property_id as pr_id1, t2.property_id as pr_id2 
FROM
        (SELECT * FROM subproduct_attributes WHERE (property_id = 25 OR property_id = 39)) t1
CROSS JOIN
        (SELECT * FROM subproduct_attributes WHERE (property_id = 29)) t2
ON t1.subproduct_id = t2.subproduct_id

28th November, 2017

vladshoob left a reply on Filter Products By HasMany Relation • 10 months ago

Nope. It was not rights solution. This one works for 1 property per attribute, but not if 2 properties are there.

Please help, 2 days spent on basic filtering products.

vladshoob left a reply on Filter Products By HasMany Relation • 10 months ago

Guys, I figured it out. I help it will help somebody.

$query = $this->builder->Join('subproduct_attributes', 'subproduct_attributes.subproduct_id', '=', 'subproducts.id')
                                ->select('subproducts.*', 'subproduct_attributes.subproduct_id', DB::raw('COUNT(subproduct_attributes.subproduct_id)'))
                                ->groupBy('subproducts.id')
                                ->whereIn('subproduct_attributes.property_id', $keys)
                                ->havingRaw("COUNT(subproduct_attributes.subproduct_id) = $keys_count");

vladshoob left a reply on CRUD Help • 10 months ago

First of all, you will need a form's input to reasch ::delete route with:

<input type='hidden' _method='DELETE'>

Secondly you may use boot method on your user model like this:

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

        static::deleting(function ($product) {
            $product->productPhotos->each->delete();
        });
    }

Modificate per your needs.

vladshoob started a new conversation Filter Products By HasMany Relation • 10 months ago

Good time of yours, guys. Just can't figure it out.

Have Products, Attributes, Properties(attribute_id), Matches(attribute_id, 'property_id') models. (Names are for example.)

Attributes are: 'size', 'type'..

Properties are 'S', 'M'... 'type 1', 'type 2'...

I have filters like in Jeffrey Way's "Let's build a forum' series.

What I'm trying to accomplish is crossroad filters. In common language: get products that have size S of both types / get products that have S and M sizes of type 1...

// $keys = [1, 2, 3]; // ids of properties: 1 - S, 2 - M, 3 - type 1, 4 - type 2

$query = $this->builder->whereHas('attributes', function ($query) use ($keys) {
      $query->where('matches.property_id', $keys);
});

$query = $this
    ->builder
    ->join('matches', 'matches.product_id', '=', 'products.id')
    ->select('matches.property_id', 'products.*');

foreach ($keys as $key) {
    $query = $query->where('subproduct_attributes.property_id', $key);
}

With both examples above I have save result, it is giving me all products with given sizes and with given types, without crossroading them.

Thanks in advance, you are awesome community.

vladshoob left a reply on Query: Search Products Where Subproducts Has A Value • 10 months ago

I think I found solution.

$value = '00-100';
$products = Product::join('subproducts', 'products.id', '=', 'subproducts.product_id')
                ->where(('subproducts.article_code', 'like', "%$value%")
        ->select('products.*');

22nd November, 2017

vladshoob left a reply on Query: Search Products Where Subproducts Has A Value • 10 months ago

@RamjithAp

this way I will find only subproducts, but I need to return $products eloquent collection.

vladshoob started a new conversation Query: Search Products Where Subproducts Has A Value • 10 months ago

Hello everyone, hope for little hint how to do next.

I have $products and related $subproducts, relationship (product has many subproducts) is in place.

What is correct way to find products where subproducts has some value.

$value = '00-100';
$products = Product::join('subproducts', 'products.id', '=', 'subproducts.product_id')
                ->where(('subproducts.article_code', 'like', "%$value%");

The problem is the correct value is found. But I loose all my with relations in process of this query. Let me explain: product has 10 subproducts, I make described query, and then I don't have access to $product->subproducts.

Thanks in advance.

17th November, 2017

vladshoob left a reply on Order By Own Key • 11 months ago

I beleive it is the answer. But I'm not strong in queries.

https://laracasts.com/discuss/channels/eloquent/custom-orderby-in-laravel-query-builder

vladshoob left a reply on Order By Own Key • 11 months ago

Update.

$user_unit = Unit::first();

$units = Units::all();
$units = collect($units);

$key = $units->search($user_unit);
$units->pull($key);

$units->prepend($user_unit);
dd($units); // you will have in $units all your Units with prepended $user_unit

Ahh.. you have pagination...

vladshoob left a reply on Order By Own Key • 11 months ago

Maybe, you can sort collection.

// get units of user
// delete them from $units collection
// prepend user's units to $units collection

vladshoob left a reply on Order By Own Key • 11 months ago

You may do relationship and attach it to Unit.

Unit.php

protected $with = ['user'];

public function user()
{
    return $this->hasOne( ... ); // specific user
}

Then when you call

@foreach ($units as $unit) {
    // some stuff
        {{ $unit->user->name }}
    // some stuff
@endforeach 

Hope it will be helpfull.

vladshoob left a reply on Get URI From Route Name • 11 months ago

Neigher of methods worked for me. I was able to find URI by this:


uri_for(route('ua.index'))->getPath();

Edit Your Profile
Update

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