crazydan

Experience

960

0 Best Reply Awards

  • Member Since 3 Years Ago
  • 1 Lesson Completed
  • 0 Favorites

6th September, 2016

crazydan left a reply on Relation After A Value • 2 years ago

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;
    }

5th September, 2016

crazydan started a new conversation Relation After A Value • 2 years ago

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

16th February, 2016

crazydan started a new conversation User Group Custom Session Lifetime • 2 years ago

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

19th June, 2015

crazydan started a new conversation Make Relation With Condition • 3 years ago

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

21st May, 2015

crazydan started a new conversation HasOne With Multiple Keys • 3 years ago

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

5th May, 2015

crazydan started a new conversation Builder Dont Transform To Collection • 3 years ago

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?

4th May, 2015

crazydan left a reply on HasManyThrough Issue • 3 years ago

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

works perfect thank you JarekTkaczyk

Have a good day

30th April, 2015

crazydan started a new conversation HasManyThrough Issue • 3 years ago

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

29th April, 2015

crazydan left a reply on Tables Relationships • 3 years ago

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

28th April, 2015

crazydan started a new conversation Autoload Model • 3 years ago

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

17th April, 2015

crazydan left a reply on Tables Relationships • 3 years ago

Good, now is working. Thanks for helping

Have a good day

crazydan left a reply on Tables Relationships • 3 years ago

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 • 3 years ago

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 • 3 years ago

No error message there

crazydan started a new conversation Tables Relationships • 3 years ago

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

Edit Your Profile
Update

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