lanatel

lanatel

Lviv

Member Since 8 Months Ago

Experience Points 4,780
Experience
Level
Lessons Completed 10
Lessons
Completed
Best Reply Awards 6
Best Answer
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.

04 Jan
2 weeks ago

lanatel left a reply on Policy Not Being Called

Make sure you use 'auth' middleware. Otherwise, you will always get false.

09 Nov
2 months ago

lanatel left a reply on Laravel Method Delete Ajax Request

instead of Booking::where('id','=',$id)->get(); use Booking::where('id','=',$id)->first();

02 Aug
5 months ago

lanatel left a reply on Laravel Updating Relationship Column In WhereHas

If I got you right you want to update your salesdetails table. In this case your query cant be used because now you are trying to update Sales table.

You can try smth like that:

salesdetailsModel::whereHas('sale',  function ($query) use ($now) {
            $query->where(DB::raw("(DATE_FORMAT(transaction_date,'%Y-%m-%d'))"), '<', $now)
    ->where('product_id', '<=', 24)
    ->where('switch', 1)
    ->update(['switch' => 0]);

Or if you already have sale instance and want to update its details you can do

$sale->salesdetails()
    ->where('switch', 1)
    ->update(['switch' => 0])

20 Jun
7 months ago

lanatel started a new conversation Laravel Mix: Fonts Path

Hi, Laravel-Mix copies my fonts from assets/dashboard/fonts/fontName to public/fonts/fontName. Is there any way to change it? I need to have in public/dashboard/fonts/fontName.

04 Jun
7 months ago

lanatel left a reply on Sum Over Multiple Column In HasMany Relation Table

@floflo where do you want to call it? If you need to use it with your sum result than you can do it in the same query

Number::leftJoin(DB::raw('(SELECT number_id, SUM(total_bids) as binds_sum, SUM(total_calls) as calls_sum FROM AggregateStatisticTableName GROUP BY number_id) AS statistics'), function ($join) {
            $join->on('statistics.number_id', '=', 'numbers.id');
        })
    ->select('binds_sum', 'calls_sum ', DB::raw('calls_sum / binds_sum as percent'), 'numbers.id')
    ->get();
01 Jun
7 months ago

lanatel left a reply on Routing Active

when you want to check your route name you can use Route::currentRouteName() . But it will give you a full name so you have to check it on every link or use extra functions.

I think in your case it is better to use Request::is($path). Cause here you can pass part of url (for ex. mylink/* ) and apply it to group of routes.

31 May
7 months ago

lanatel left a reply on Sum Over Multiple Column In HasMany Relation Table

Than you can do something like that:

Number::leftJoin(DB::raw('(SELECT number_id, SUM(total_bids) as binds_sum, SUM(total_calls) as calls_sum FROM AggregateStatisticTableName GROUP BY number_id) AS statistics'), function ($join) {
            $join->on('statistics.number_id', '=', 'numbers.id');
        })->get();

It does not use your relationship but make just one query

lanatel left a reply on Sum Over Multiple Column In HasMany Relation Table

Which column is a foreign key on the AggregateStatistic model?

18 May
8 months ago

lanatel left a reply on Looping Through Collection And Summing Values With Same Parent_id

Model::groupBy('parent_id')
            ->select('parent_id', DB::raw('SUM(value) as sum'))
            ->get();
17 May
8 months ago

lanatel left a reply on Laravel Queues

@Borisu I understand. But I need it because site moderators will create templates for mass mailing and it is possible that sometimes they will do it bad (for example send it to wrong type of users or just type a bad text). So in this case I want to be able to stop execution jobs that responsible for this emails

lanatel left a reply on Laravel Queues

@Borisu thanks for reply. But my question is, what if I have for example 1000 jobs in one queue. Half of them have been executed and other half is still in the queue. Can I just stop executing and delete that jobs?

lanatel left a reply on How To Use The Correct UpdateOrcreate In Laravel?

It is not the best idea to use updateOrCreate() in this case. First of all, your job_educations table doesn't need id column. Secondly, you can define a many to many relation https://laravel.com/docs/5.6/eloquent-relationships#many-to-many between your jobs and educations tables. Thus, you don't a JobEducation model at all. And then, with this relation you can use sync() or if you don't want to delete existing records syncWithoutDetaching() method. https://laravel.com/docs/5.6/eloquent-relationships#updating-many-to-many-relationships

16 May
8 months ago

lanatel left a reply on Get Count In Joining Multiple Table

You can do it another way. If user can belong to many groups and group can have a lot of users you can define a many to many relationship https://laravel.com/docs/5.6/eloquent-relationships#many-to-many and then just call withCount() method

$group = Group::withCount('users')->first();
$count = $group->users_count;

lanatel started a new conversation Laravel Queues

Hello guys. On my site, users will receive different types of emails. Some of them are related to registration on the site; others will be sent when the user asks questions, and so on. One type of emails is mass mailing. All of them will be queued with a different priority.

The queue worker will be running on a separate server (is it appropriate?), where the queues will be processed according to the priority. Bulk mailing will be in the same queue, but it should have some extra parameter that I can separate them later (for example, one day I have to send to all users a notification about the promotion on the site and these messages should be in one group, and after some time I will send messages on a completely different topic and they also should be separated). I need this to be able to delete all jobs that have not been executed yet and which handle sending emails from specific group or pause the job executions and continue it after a certain time.

So the main question if it is possible to implement. I have read about Laravel Horizon (I use Redis) and know about the tag existence. Can I use them to achieve my goal or they are used only for monitoring jobs?

I will be glad to hear any thoughts, ideas and advices. Thank you

11 May
8 months ago

lanatel left a reply on Attributes For Products In Given Category

@GoldeNx3 maybe smth like this

Product::whereHas('attributes', function ($query) {
            $query->where('attribute_id', $idOfAttributeYouInterestedIn)
            ->where('value', $specificValue);
        })->get());

lanatel left a reply on SetAttribute In Model

@tykus yes, you are right. Why didn't I think of it? Thanks

lanatel left a reply on SetAttribute In Model

You can do it when you a create migration:

$table->string('school_code')->default(str_random(8));

or in your Model

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

        static::creating(function ($model) {
            $model->school_code= str_random(8);
        });
    }

lanatel left a reply on Class Doesn't Exist

Did you add a namespace in your Vivense class?

10 May
8 months ago

lanatel left a reply on Select JSON Data From DB And Display

@trihead in this case $value is your json from db.

But m-rk's way is better and easier. Just try to work with arrays and you will see how easy it is.

lanatel left a reply on Select JSON Data From DB And Display

You can have accessor in your model class

public function getMetaAttribute($value)
{
    return json_decode($value);
}

Than you can use it like a regular array

lanatel left a reply on Route [login] Not Defined.

return view('auth.login');

lanatel left a reply on WhereIn Only Matching Values With Two Units, Not Three

If it works with your test array it should work

$first = Users::select('id')->where('column', condition1)->where('column2', condition2)->pluck('id')->toArray();

lanatel left a reply on Query Result From Database

first of all rename you classrooms relation to classroom. And maybe try just get $student->classroom. Are there any results?

lanatel left a reply on Query Result From Database

@bincy123 if you don't get any errors, be sure to fill your db tables with data. Maybe yo just get empty result

lanatel left a reply on Query Result From Database

@bincy123 can you dump your result? You should get results from both tables by using $student->galleries and $student->classroom->galleries.

lanatel left a reply on Query Result From Database

@bincy123

Student::where('id', $student_id)->with(['galeries', 'classroom.galleries'])->get();

lanatel left a reply on Attributes For Products In Given Category

Products, Categories and Attributes table can have everything you need. Then attribute_category table should have 2 columns attribute_id and category_id. And attribute_product should have 3 columns: attribute_id, product_id, value

https://laravel.com/docs/5.6/eloquent-relationships#many-to-many here is a great explanation of Many To Many relation

lanatel left a reply on Query Result From Database

In your Student model

public function galleries()
    {
        return $this->hasMany(Gallery::class);
    }

    public function classroom()
    {
        return $this->belongsTo(Classroom::class);
    }

In Classroom model:

public function galleries()
    {
        return $this->hasMany(SharedGallery::class);
    }

And than you can do:

Student::with(['galeries', 'classroom.galleries'])->get();

lanatel left a reply on Attributes For Products In Given Category

For example, you can have the folowing db structure: - products table (with category_id column) - categories table - attributes table (with all possible attributes) - attribute_category table (with belongsToMany relation) - attribute_product (also with belongsToMany relation, but beside of attribute_id and product_id you can have there value column where you can store attribute value of a given product)

So when you want to add new product, you select a category, then you get all attributes that have to be presented for a given category and just insert it to attribute_product table.

I don't know if it is a good solution but it should work :)

08 May
8 months ago

lanatel left a reply on Search Method Which Queries By Nested Relationship Fields

If I got you right, you can try something like that

$investors = User::with([
    'investments',
     'investor' => function ($query) use ($request) {
        $query->when($request->firstname, function($query) use ($request){
                return $query->where('investor.firstname', 'like', "%{$request->firstname}%");
                return $query->where('investor.firstname', 'LIKE', "%$request->firstname%");
            })      
            ->when($request->lastname, function($query) use ($request){
                return $query->where('investor.lastname', 'like', "%{$request->lastname}%");
                return $query->where('investor.lastname', 'LIKE', "%$request->lastname%");
            })
       ->when($request->phone, function($query) use ($request){
                return $query->where('investor.phone', 'like', "%{$request->phone}%");
                return $query->where('investor.phone', 'LIKE', "%$request->phone%");
            })             
}])
->get()

Here you can get all users with filtered investors relation

07 May
8 months ago

lanatel left a reply on Group By

you can do something like that

$qualityClaims = QualityClaim::SelectRaw(
            'defect,
            MONTHNAME(plm.quality_claims.created_on) month,
            COUNT(*) as count'
        )
        ->join('plm.defects', 'plm.quality_claims.defect_id', '=', 'plm.defects.id')
        ->where('plm.quality_claims.created_on', '>=', Carbon::now()->subMonth(12))
        ->where('plm.quality_claims.organization_id', '=', $id)
    ->get();

$result = $qualityClaims->groupBy('defect')->transform(function($item, $k) {
            return $item->groupBy('month');
        });

lanatel started a new conversation ShouldBeSearchable() Seems To Not Be Working

Hello! I am using ElasticSearch in my project and I want to index conditionally, so I have the following method in my model class

public function shouldBeSearchable()
{
      return $this->paid;
}

When it return true everything works as expected, but if result is false I get this error

{"_index":"question","_type":"questions","_id":"72","_version":1,"result":"not_found","_shards":{"total":2,"successful":1,"failed":0},"_seq_no":5,"_primary_term":1}

And that's obvious because I found method, which handles the saved event for the model. Here it is

public function saved($model)
{
        if (static::syncingDisabledFor($model)) {
            return;
        }

        if (! $model->shouldBeSearchable()) {
            $model->unsearchable();
            return;
        }

        $model->searchable();
    }

So, here it call unsearchable() method for model which doesnt exist in the search index and maybe because of that I have this not found error?