Dosmukhanbet

Dosmukhanbet

Member Since 7 Years Ago

Aktobe

Experience Points
104,160
Total
Experience

840 experience to go until the next level!

In case you were wondering, you earn Laracasts experience when you:

  • Complete a lesson — 100pts
  • Create a forum thread — 50pts
  • Reply to a thread — 10pts
  • Leave a reply that is liked — 50pts
  • Receive a "Best Reply" award — 500pts
Lessons Completed
1289
Lessons
Completed
Best Reply Awards
1
Best Reply
Awards
  • start your engines Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-in-session Created with Sketch.

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • subscriber Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • evangelist Created with Sketch.

    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 Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

Level 21
104,160 XP
Sep
04
1 month ago
Activity icon

Started a new Conversation Get Belongstomany If Contains Only Given Ids

Hello, Please kindly assist me with making query that will return instance Route model if contains only both given ids.

I have Route and Point model, they are linked with 'point_route' table - Many to Many Relationship.

Goal is take route that contain given both 2 point ids.

For example given ids 1 and 2, the query should return Route that has both given ids , considering below table example it should return Route with id 1.


point_id	route_id	
1	           1	
2	           1	
2	           2	
3	           2
4		   2

class Route extends Model
{

    public function points()
    {
        return $this->belongsToMany(Point::class)->withPivot('point_order');
    }
    
    public function pointsIds()
    {
        return $this->points()->pluck('point_id');
    }

}

//
web.php
use App\Route as Routes;

Route::get('test', function () {

    $pointIds = [1, 2];

    $route = Routes::find(1);

    dd($route->pointsIds()->has($pointIds));

});

Aug
26
2 months ago
Activity icon

Replied to Get Nested Subquery With Eloguent

@geordiejackson i' want avoid extra queries to database but i think i have to accept this approach Order::with('point.country') if i could not find solution to get orders, point:name, country:name in one query

Activity icon

Replied to Get Nested Subquery With Eloguent

@marco unfortunately hasOneThrough relationship does not work, because foreign key is not typical, as you can see above code to get order->a_point I use 'point_A_id' foreign key $this->belongsTo(Point::class, 'point_A_id'); When i try use this foreign key in hasOneThrough relationship it return error

public function a_point_country()
 {
        return $this->hasOneThrough('App\Country', 'App\Point', 'point_A_id', 'country_id');
 }

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'points.point_A_id' in 'field list' (SQL: select countries.*, points.point_A_id as laravel_through_key from countries inner join points on points.id = countries.country_id where points.point_A_id in (1, 2, 3, 4, 5, 6, 7, 8, 9)) (View: /Users/dos/Desktop/Sites/cargo/resources/views/welcome.blade.php)

Activity icon

Started a new Conversation Get Nested Subquery With Eloguent

Hello, There are following relationships model Order belongsTo -> Point, Point belongsTo -> Country. I would like get in one query Orders with Point name, also Country name.

with below scope in Order model i get point name

public function scopeWithAPoint($query)
{
      $query->addSelect(['a_point_name' => Point::select('name')
                    ->whereColumn('id', 'orders.point_A_id')
                    ->limit(1)]);
  }

 Order::withAPoint() ->orderBy('created_at', 'desc')
                                    ->take(15)
                                    ->get();

but having trouble to get Country name, could somebody help me implement this

models 

class Order extends Model
{
   
    public function a_point()
    {
        return $this->belongsTo(Point::class, 'point_A_id');
    }

    public function scopeWithAPoint($query)
    {
      $query->addSelect(['a_point_name' => Point::select('name')
                    ->whereColumn('id', 'orders.point_A_id')
                    ->limit(1)]);
      }

}

class Point extends Model
{
    public function country()
    {
        return $this->belongsTo(Country::class);
    }
}

migrations:
Schema::create('points', function (Blueprint $table) {
            $table->id();
            $table->string('name')->unique();
            $table->unsignedBigInteger('country_id');
        });
    }

 Schema::create('orders', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('point_A_id');
            $table->timestamps();
        });

 Schema::create('countries', function (Blueprint $table) {
            $table->id();
            $table->string('name')->unique();
            $table->string('shortname');
            $table->string('language');
        });
Aug
23
2 months ago
Activity icon

Replied to Join With Subquery With Laravel

@automica i know how to make it in blade of course, but problem is that it make additional query to database, I'd like to reduce number of queries to database, make one query with left join subquery. I run above query in Sequel pro terminal and it works fine, but I don't now how to make with laravel.

Activity icon

Replied to Join With Subquery With Laravel

Any thoughts?

Activity icon

Replied to Join With Subquery With Laravel

@automica hi, thank you for reply

relationship 

class Order extends Model
{
   
    public function a_point()
    {
        return $this->belongsTo(Point::class, 'point_A_id');
    }

}

class Point extends Model
{
    public function country()
    {
        return $this->belongsTo(Country::class);
    }
}

migrations:
Schema::create('points', function (Blueprint $table) {
            $table->id();
            $table->string('name')->unique();
            $table->unsignedBigInteger('country_id');
        });
    }

 Schema::create('orders', function (Blueprint $table) {
            $table->id();
            $table->unsignedBigInteger('point_A_id');
            $table->timestamps();
        });

 Schema::create('countries', function (Blueprint $table) {
            $table->id();
            $table->string('name')->unique();
            $table->string('shortname');
            $table->string('language');
        });
Activity icon

Started a new Conversation Join With Subquery With Laravel

Hello, I want to below mysql query run with laravel, can anybody help with it

select 
orders.*,
countries.shortname as a_point_country 
from orders
left join countries
on countries.id = (
	select country_id from points where id  =  orders.point_A_id
)

Aug
12
2 months ago
Activity icon

Replied to Where Query Column If Column Has Value

@michaloravec i want to make query where $date greater than date_from and lower than date_to, but date_to sometimes null, in this case query should return only $date greater than date_from

Activity icon

Replied to Where Query Column If Column Has Value

@sinnbeck nope $date will come from request, I mean make query depending upon date_to column value in the table. Is it possible?

Activity icon

Started a new Conversation Where Query Column If Column Has Value

Hi everyone, please help to solve below issue There is table with column date_from and date_to. date_to column is optional, so it might be null. I want to make query this column if it has value, if it is null no need to run query at all. Is there way to make query conditionally depending column value? I have tries as below but it does not work as expected.

trips()->with('user', 'a_point', 'b_point')
                                    ->where('date_from', '>=' , Carbon::today())
                                    ->where('date_from', '>=' , Carbon::parse($date)->format('Y-m-d'))
                                    ->where( function ( $query ) use ( $date ) {
                                        $query->whereNotNull( 'date_to' )
                                              ->orWhere('date_to', '<=' , Carbon::parse($date)->format('Y-m-d'));
                                    });
Activity icon

Replied to Query Model When Column Not Null

@michaloravec this query does not work as well, in this case previous query where('date_from', '>=' , Carbon::parse($date)->format('Y-m-d') ignores, and return all datas that match latest query.

Activity icon

Replied to Query Model When Column Not Null

@michaloravec I've hurried up with reply, code does not work as I expect. Let me explain what is problem. There is table with column date_from and date_to, date_to column is optional, so it might be null. I want to query this column if it has value, if it is null not need to run query at all. Is there way to query conditionally depending column value?

trips()->with('user', 'a_point', 'b_point')
                                    ->where('date_from', '>=' , Carbon::today())
                                    ->where('date_from', '>=' , Carbon::parse($date)->format('Y-m-d'))
                                    ->where( function ( $query ) use ( $date ) {
                                        $query->whereNotNull( 'date_to' )
                                              ->orWhere('date_to', '<=' , Carbon::parse($date)->format('Y-m-d'));
                                    });
Aug
11
2 months ago
Activity icon

Replied to Query Model When Column Not Null

Hi, thank you for reply, your offered solution works fine👍

Activity icon

Started a new Conversation Query Model When Column Not Null

hello, Please could somebody help. I have date_to column, it can be null and I wanna add where query when this column not null but following code does not work

 $this->trips()->where( function ( $query ) use ( $date ) {
                                        $query->whereNull( 'date_to' )
                                              ->orWhere('date_to', '<=' , Carbon::parse($date)->format('Y-m-d'));
                                    });
Jul
22
3 months ago
Activity icon

Started a new Conversation Laravel Livewire: How To Bind Checkbox Selected Values To Component Array

Hello, Could anybody help me to solve following issue, I am trying to bind only selected checkbox values to array in my livewire component as below, but it does not work

Component

use Livewire\Component;
use App\Point;

class AddNewTrip extends Component
{
   
    public $selectedtypes;

    public $initial_cargo_types;;


    public function mount($cargoTypes)
    {
        $this->initial_cargo_types = $cargoTypes;
    }

}

Blade

@foreach($initial_cargo_types as $type)
       <div class="mt-1">
              <label class="inline-flex items-center">
		      <input type="checkbox" value="{{ $type->id }}" wire.model="selectedtypes"  class="form-checkbox h-6 w-6 text-green-500">
                   <span class="ml-3 text-sm">{{ $type->name }}</span>
               </label>
          </div>
 @endforeach
Jul
20
3 months ago
Jul
19
3 months ago
Activity icon

Replied to Get BelongsToMany With Condition

@michaloravec I'd like take route that has both ids, in this example there is only one route with point_id 2,7 but query return 2 routes because second route has point_id 2

Activity icon

Replied to Get BelongsToMany With Condition

@michaloravec thank you for reply, but it does not work, still return routes that match one of provided item, I 'd like to take only routes that have both provided items of array. $pointIds = [2, 7]. In this example query should return only the one route

Activity icon

Replied to Get BelongsToMany With Condition

this is how looks point_route table

point_id	route_id	point_order
9	1	9.00
8	1	8.00
7	1	7.00
6	1	6.00
5	1	5.00
4	2	3.00
4	1	4.00
3	1	3.00
2	2	2.00
2	1	2.00
1	2	1.00
1	1	1.00
Activity icon

Started a new Conversation Get BelongsToMany With Condition

Hello, Please could anybody help me solve following issue. I have relation belongsToMany between Routes and Points table and I'd like take only that route which match provided array of ids. The below code return routes if one item of array match

class Routes extends Model
{

    public function points()
    {
        return $this->belongsToMany(Point::class)->withPivot('point_order');
    }

}


$routes = Routes::whereHas('points', function ($query) {
    return $query->whereIn('point_id', [2,7] );
})->get();

May
08
5 months ago
Activity icon

Awarded Best Reply on Livewire Wire:click Doesn't Trigger Action Inside Of Foreach

Thanks a lot, it helped me

Activity icon

Started a new Conversation Livewire Wire:click Doesn't Trigger Action Inside Of Foreach

hello! Please help me with following issue, Livewire wire:click doesn't trigger action inside of foreach, it just submit form despite that i prevent submit form but outside of foreach works fine.

the livewire view code:

    <div>
        <input type="text" wire:model="search"  placeholder="Start typing materials name"
        class="border border-gray-400 hover:border-gray-500 px-4 py-2 pr-8 rounded shadow leading-tight "
        >
    </div>
    
    @foreach ($searchResults as $material)
        <div>
            {{ $material['name'] }} <button wire:click="addMaterialToRequest({{ $material['name'] }})">Add to request</button>
        </div>
    @endforeach


    <a href="#" wire:click="addMaterialToRequest('hello')">Add to request</a>
    <button type="submit" wire:click="submit">Submit Requisition</button>
</form>