alihoushyaripour

Experience

730

0 Best Reply Awards

  • Member Since 1 Week Ago
  • 0 Lessons Completed
  • 0 Favorites

19th July, 2018

alihoushyaripour started a new conversation How To Save User View Log With Mysql? • 16 hours ago

Hi,

If i want to save every user view of activity in my application, for example see a post, a blog, a place, other users profile, a comment and so on.

I read that bigInt datatype in mysql save more than 2^64 rows in every table, and even I can consider uuid(v1 to v4) as primary key and in otherwise I can log all of them in text files...

But I like to know if my platform will grew very big a day, what's better for that? because at that time changes is difficult.

Thank's, best regards <3

alihoushyaripour started a new conversation What Is This Complex Eloquent Problem? • 1 day ago

Hi,

I have two model, 'User' and 'Activity' that every user has many activities.

This is my eloquent query:

return Activity::select(['*', DB::raw('sum(activities.coin) as coin')])
            ->leftJoin('users', 'users.id', '=', 'activities.user_id')
            ->where(['activities.active' => true])
            ->whereDate('activities.created_at', '>=', $date)
            ->groupBy(DB::raw('coin'))
            ->havingRaw('coin > 0')
            ->orderByRaw('coin', 'desc')
            ->skip(0)
            ->take(20)
            ->distinct()
            ->get();

I want to get all users data with sum of users coin, and show me this error:

"SQLSTATE[23000]: Integrity constraint violation: 1052 Column 'coin' in group statement is ambiguous (SQL: select distinct *, sum(user_activities.coin) as coin from `user_activities` left join `users` on `users`.`id` = `user_activities`.`user_id` where (`user_activities`.`active` = 1) and date(`user_activities`.`created_at`) >= 2017-07-19 11:56:55 group by coin having coin > 0 order by coin limit 20 offset 0)"

18th July, 2018

alihoushyaripour started a new conversation System Requirements For Laravel To Launch In A Vps? • 1 day ago

Hi,

Up to now i test my project in a shared host that is very slow and weak, now I want to publish my project in a VPS, anyone can suggest me a good but not very strong system requirements for that?!

Best regards <3

alihoushyaripour started a new conversation How To Use Select And SelectRaw Together Query In Eloquent? • 1 day ago

Hi,

I want to get all data from a model with name 'user' with a eloquent query and in this query get count of a column and sum of other column, but I won't to divide this action in 3 query...

What should I do?

16th July, 2018

alihoushyaripour started a new conversation What Is Best Way For Upload Image? • 3 days ago

Hi,

I'm coding an application similar Instagram and it's important for me to images and videos upload streamlined and optimized.

I read and search a little, the best way I found was 'intervention/image' library, but I feel there is a better way or there is a better library that is specially for uploading photos, videos and files that I do not know it.

Is there someone to help me?

Best regards <3

alihoushyaripour left a reply on How To Map A Request Json Object To An Object Model..?! • 4 days ago

Thank's @Cronix

But if a field is required in my model, but not received in json, is there any solution for that..!?

Always all required parameters not send to server...

15th July, 2018

alihoushyaripour started a new conversation How Map A Json Object In Request To Object Model..?! • 4 days ago

Hi,

Hope you're fine

Suppose this is an json object that come from the client side with a request:

{
    "user": {
        "id": "ID",
        "location": {
            "lat": "LAT",
            "lng": "LNG"
        },
        // other params
    },
    "place": {
        "name": "NAME",
        "location": {
            "lat": "LAT",
            "lng": "LNG"
        },
        // other params
    },
    "meta": {
        "link": [
            "first": "LINK",
            "last": "LINK",
            "prev": "LINK",
            "next": "LINK",
        ],
        // other params
    }
}

I have there different objects and I want to map this three objects(that exist in json) into three model classes and use them as object in code.

alihoushyaripour left a reply on How To Config And Run Plastic(Elasticsearch ODM And Mapper For Laravel) In Laravel? • 5 days ago

I don't know what the reason is, but I've done everything step by step from tutorial and I've been careful to do it right.

This is my model class:

class Business extends Model
{
    // parameters
    protected $table = "businesses";
    
    protected $primaryKey = "id";
    
    public $incrementing = true;
    
    protected $fillable = [];
    
    protected $guarded = [];
    
    protected $keyType = "integer";
    
    public $timestamps = true;

    // plastic
    use Searchable;
    
    public $searchable = ['name_fa', 'name_en'];
    
    public $documentType = "businesses";
    
    public $documentIndex = "businesses";
    
    protected $searchRules = [
        //rules
    ];
    
    public $syncDocument = true;
    
    public function buildDocument()
    {
        return [
            //parameters
        ];
    }

    // relation functions
}

And this is my mapping class:

class AppBusiness extends Mapping
{
    protected $model = App\Business::class;
    
    protected $index = "businesses";
    
    public function setModel(string $model)
    {
            $this->model = $model;
    }

    public function map()
    {
        Map::create($this->getModelType(), function (Blueprint $map)
        {
            $map->integer('id');
            $map->string('name_fa');
            $map->string('name_en');
            // other parameters
        }
    }, $this->index);
}

Then I run this code to cli:

php artisan mapping:run

And map class should be created, but not...

Anyone can help me please?!

14th July, 2018

alihoushyaripour left a reply on How To Write Relational Eloquent? • 5 days ago

It's province name, this is not important...

See, this is my code:

public function similarByNameAndProvince($name, $province)
{
    return User::select([
                'users.name as name',
                'users.avatar as avatar',
                ...
                'provinces.name as province',
                'addresses.street as street',
                'addresses.alley as alley',
                ...
            ])
                ->leftJoin('addresses', '...', '=', '...')
                ->leftJoin('provinces', '...', '=', '...')
                ->leftJoin('cities', '...', '=', '...')
                ->where('users.name', 'like', "%$name%")
                ->where(['provinces.name' => $province])
                ->get();
}

But this is very dirty and non-standard...

How I write query like this with 'with', 'where' and other good eloquent functions..?!

alihoushyaripour left a reply on How To Write Relational Eloquent? • 5 days ago

@staudenmeir

My migration is clearly, every user have an address and every address have a province, exactly like migration classes and those foreign keys.

alihoushyaripour started a new conversation Problem With Column With The Same Name In Relational Eloquent • 5 days ago

Hi,

When I want to write eloquent query according to model relationships, the value of columns of models that have the same name, fill with last model column value... and I have to get the values using the select...

What should I do?

How to write eloquent query to get all columns(with same names) of all models that exist in eloquent query?(get with different names)

alihoushyaripour started a new conversation How To Write Relational Eloquent? • 5 days ago

Hi,

I have three model with name 'User', 'Address', 'Province', now I want to write a query to check is there exist any user with same name in same province?

These are my model migration classes:

// user migration
Schema::create('users', function (Blueprint $table) {
    $table->increments('id');
    $table->string('name', 100);
        $table->unsignedInteger('address_id');
    ...
}

// address migration
Schema::create('addresses', function (Blueprint $table) {
    $table->increments('id');
    $table->unsignedInteger('province_id');
    ...
}

// province migration
Schema::create('provinces', function (Blueprint $table) {
    $table->increments('id');
    $table->string('name', 64);
    ...
}

And this is my repository function:

public function similarByNameAndProvince($name, $province)
{
    // how should code be written here?
}

alihoushyaripour left a reply on How To Config And Run Plastic(Elasticsearch ODM And Mapper For Laravel) In Laravel? • 6 days ago

Thank you bobby <3

I have other questions that if it's okay for you to ask them one by one? After I create my mapping class and fill it with model mapping, I run this and show me this error:

command : php artisan mapping:run

error : In StaticNoPingConnectionPool.php line 51: No alive nodes found in your cluster

Is there any problem in my model class, or mapping class or in other place?

alihoushyaripour left a reply on How To Config And Run Plastic(Elasticsearch ODM And Mapper For Laravel) In Laravel? • 6 days ago

Yes, I did all the tutorial, but for example in section 2 that named with "Providing a buildDocument method" it doesn't say how I word when I want to have a parameter that fill with a relation function:

public function buildDocument()
{
    return [
        'id' => $this->id,
        ...
    'products' => $this->products(), // products() function in model
        'categories' => $this->categories(), // categories() function in model
        'tags' => $this->tags(), // tags() function in model
        'features' => $this->features(), // features() function in model
        'hours' => $this->hours(), // hours() function in model
        'phone_numbers' => $this->phones(), // phones() function in model
        'images' => $this->images(), // images() function in model
    ...
    ];
}

Do you know what should I do here?

alihoushyaripour started a new conversation How To Config And Run Plastic(Elasticsearch ODM And Mapper For Laravel) In Laravel? • 6 days ago

Hi, I read this official tutorial of plastic, but in this tutorial there is no talk about all challenges and problems that may occur...

Link: https://github.com/sleimanx2/plastic

Is there anyone that work with plastic to answer my question?

12th July, 2018

alihoushyaripour started a new conversation How Must Define Relationships Between Models? • 1 week ago

alihoushyaripour started a new conversation What Is Best Way To Store Spatial Or Point Data In Database? • 1 week ago

Hi, I worked with postgresql for a while and every time I define my spatial data as 'point' datatype to insert, get and use it easily and fast, for calculate distance and use other postgresql geo functions. Now I define point data like before, but when i want to get point data with eloquent or want to export my table that has point datatype column, show me a lot of incorrect values like this : :�m½�[email protected])��[email protected]

but when i define latitude and longitude as decimal(11, 8) everything is fine and work properly. But which way is correct? which is best and optimized? I'm working on an enterprise project and it's important for me to write the best code.

alihoushyaripour started a new conversation How To Define Object Class For Making Objective Json Response? • 1 week ago

Hi I have a big project with many routes and controllers and each controller has several functions, in response of every function i make json with an array that make manually, it's too bad for me, because I can't extend my project in this way... I saw one android professional code that it defines objects and fill requests body with those objects... it's very nice. What should I do in laravel if I want to do this?

alihoushyaripour left a reply on How Call A Middleware Out Of Controller's Constructor? • 1 week ago

Thank's @Cronix My problem solved ?

11th July, 2018

alihoushyaripour started a new conversation How Call A Middleware Out Of Controller's Constructor? • 1 week ago

I have a controller with five functions, and i have five routes that every route call a function of my controller, and now i need to run a custom middleware for three of them, but because middlewares should call from controller's constructor, i don't know what should i do? Is there any solution my friends?

Edit Your Profile
Update

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