crazydan

crazydan

Member Since 3 Years Ago

Experience Points 960
Experience
Level
Lessons Completed 1
Lessons
Completed
Best Reply Awards 0
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.

06 Sep
2 years ago

crazydan left a reply on Relation After A Value

I wanna do something like this:

public function _country()
    {
        if($this->isDeprecated){
            $country = AddressCountry::where('country_code','RO')->first();
        }else{
            $country = $this->_state->_country;
        }

        return $country;
    }
05 Sep
2 years ago

crazydan started a new conversation Relation After A Value

Hi,

I have a situation and i couldn't find a solution and i hope you guys could help me.

I wanna return a model but as Relation not as a Model but without a relation :) ok sound crazy but i will explain.

I have more addresses stored with different relation.

1st type of addresses are stored having country_id with a related table - This is not a problem ... public function _country() { return $this->belongsTo('App\Models\AddressCountry','country_code'); } ... 2nd type of addresses are stored without country_id (i cannot make any modification in database) sooo i need to make the relation after a value.. something like this. ... public function _country() { return $this->belongsTo('App\Models\AddressCountry','RO'); } ...

Some idea?

Thank you

16 Feb
2 years ago

crazydan started a new conversation User Group Custom Session Lifetime

Hi,

I have multiple users groups and i need to set for each group a different session lifetime for example:

  • user group admin session expire in 120 min
  • user group reseller session expire in 10 min
  • user group client session expire in 1200 min

Can someone help me with a solution?

Thank you

19 Jun
3 years ago

crazydan started a new conversation Make Relation With Condition

Hi,

I try to make the next relation

return $this->hasOne('App\Models\SupplierProduct','product')->where('suppliers',$this->_reseller_supplier);

but $this->_reseller_supplier returns me NULL

how can i resolve this issue?

thank you

21 May
3 years ago

crazydan started a new conversation HasOne With Multiple Keys

Hi,

I have a issue i need to create a relation having 2 keys

for example i have the next tabels

--Products
-id
-name
...
-supplier
--SupplierProducts
-id
-supplier
-product

i wanna make the relation with 2 keys products.id = supplier_products.product_id AND products.supplier = supplier_products.supplier

On Products model i try to make the next relation

return $this->hasOne('App\Models\SupplierProduct','product')->where('supplier',$this->supplier);

but query for relation is returning is wrong ... and the supplier field is not null have value on all the products

SELECT count(*) FROM    `supplier_products` WHERE   `supplier_products`.`product` = `products`.`id` AND `supplier` IS NULL 

Some idea?

Thank you

05 May
3 years ago

crazydan started a new conversation Builder Dont Transform To Collection

Hi,

I build a query and when i use "get()" he dont execute it.

$products = Product::where('category',$category->id)->has('_supplierProduct');

            foreach(Request::all() as $name => $value){
                if($name == 'manufacturer' && is_numeric($value)){
                    $products->where('manufacturer', $value);
                }elseif(!empty($value) && count($characteristic = CategoryCharacteristics::where("name",ucfirst(str_replace("-"," ",$name)))->where('category',$category->id)->first())){
                    $products->whereHas('_characteristics',function($query) use ($value,$characteristic){
                            $query->where('value',$value);
                            $query->where('characteristic',$characteristic->id);
                        }
                    );
                }
            }

            $products->paginate(20);

some ideea?

04 May
3 years ago

crazydan left a reply on HasManyThrough Issue

public function _manufacturers()
{
    return $this->belongsToMany('App\Models\Manufacturer', 'products', 'category', 'manufacturer');
}

works perfect thank you JarekTkaczyk

Have a good day

30 Apr
3 years ago

crazydan started a new conversation HasManyThrough Issue

Hi,

I have the next 3 tables

---Products
-id
-name
-category
-manufacturer

---Categories
-id
-name

---Manufacturers
-id
-name

In Category Model i want to make a relation to get all the manufacturers that products have in that category

i try with

return $this->hasManyThrough('App\Models\Manufacturer', 'App\Models\Product', 'category');

no success the he returns me wrong query

select `manufacturers`.*, `products`.`category` from `manufacturers` inner join `products` on `products`.`id` = `manufacturers`.`product_id` where `products`.`category` = 172

I need the next query:

select `manufacturers`.*, `products`.`category` from `manufacturers` inner join `products` on `products`.`manufacturer` = `manufacturers`.`id` where `products`.`category` = 172

Some idea?

Thank you

29 Apr
3 years ago

crazydan left a reply on Tables Relationships

I got another issue now,

I try to get the model with has condition but he makes me a wrong query.

I have this relation: $this->hasOne('App\Models\SupplierProduct','product')->where('supplier',$this->reseller_supplier); I have this condition: $products = Product::orderByRaw("RAND()")->where('status','=','active')->take(10)->has('_supplierProduct')->get(); He return this query: select * from products where status = ? and (select count(*) from supplier_products where supplier_products.product = products.id and supplier is null) >= 1 order by RAND() limit 10

The problem is he don`t get my "$this->reseller_supplier" in query and i dont know how to make it

Thanks

28 Apr
3 years ago

crazydan started a new conversation Autoload Model

HI,

How can i autoload a model in to blade?

now if i wanna have a menu on a page i must assign to blade

view('page')->with('menu',$this->menu);

Thank you

17 Apr
3 years ago

crazydan left a reply on Tables Relationships

Good, now is working. Thanks for helping

Have a good day

crazydan left a reply on Tables Relationships

I have the next models: User.php

class User extends Model implements AuthenticatableContract, CanResetPasswordContract {

use Authenticatable, CanResetPassword;

protected $table = 'customers';

public $timestamps = false;

public function permissions(){
    return $this->hasMany('App\Models\Permission', 'customer');
}

public function reseller(){
    return $this->hasOne('App\Models\Reseller','customer_id');
}

}

Reseller.php

class Reseller extends Model{

protected $table = '_resellers';
public $timestamps = false;

}

And i wanna get all Users that has reseller using User::with('reseller')->get();

crazydan left a reply on Tables Relationships

The problem is after i use User::with('reseller')->get(); the code brake but like i say early with blank page and no error log

crazydan left a reply on Tables Relationships

No error message there

crazydan started a new conversation Tables Relationships

Hi,

I have some issue when i try to get all users who has reseller

In User model i have the next function

public function reseller(){ return $this->hasOne('App\Models\Reseller','customer_id'); }

When i try to use User::with('reseller')->get(); i receive blank page.

what i do wrong?

Thank you