SNaRe

Experience

10,035

6 Best Reply Awards

  • Member Since 3 Years Ago
  • 49 Lessons Completed
  • 2 Favorites

25th May, 2018

SNaRe started a new conversation Dealing With Poor Api • 1 day ago

Hi, I'm working with a very poor api. It's uptime is approximately %50 and in worst cases it decreases even more. I'm trying to get 100.000 api requests per day. The way api works is first I get the page then I get all items in page.

My question is what is the best way to deal with this this situation.

The solution I have reached so far is I have separated all api calls to different jobs to the queue. So if a job fails it retries again for 9 times but with this %5 of the jobs fails.

9th May, 2018

SNaRe started a new conversation Retrieving Old Input Even If Visitor Leaves The Page • 2 weeks ago

We can retrieve the old input with

But if I leave the page, the old "username" disappears.

I would like to show the "old" even user visits another page or comes back in the same session until the form is successfully posted.

The use case: Our website is dependent to 3rd party services and sometimes they crash. Our users type a long text and submit. But when it crashes it may take sometime(30 mins), they have to leave the page. But in this case the text disappears.

I don't want to save as draft or something for now. I would like to solve it on the fly like sessions maybe redis.

Please advise.

3rd May, 2018

SNaRe started a new conversation Getting Last Inserted ID With Laravel Ask Question • 3 weeks ago

I am trying to get the last inserted id when I create a new entry

I don't use ID as primary key, I use something called "notification_template_id" which is defined as protected $primaryKey ='notification_template_id'; in my model.

$create = [ 'subject' => isset($new_subject) ? $new_subject : '', 'body' => $new_body, 'is_active' => intval($new_status), 'default_notification_template_id' => (int)$default_info->default_notification_template_id, 'notification_type_id' => (int)$requested_info["notification_type_id"], 'company_id' => (int)$company_id, ];

$notification_template = NotificationTemplate::create($create); id = $notification_template->notification_template_id; When I try to get the last id it returns NULL,

I tried another way around,

$data = new NotificationTemplate;

$data->subject = isset($new_subject) ? $new_subject : '';
$data->body = $new_body;
$data->is_active = intval($new_status);
$data->default_notification_template_id = (int)$default_info->default_notification_template_id;
$data->notification_type_id = (int)$requested_info["notification_type_id"];
$data->company_id = (int)$company_id;
$data->save();

$id = $data->notification_template_id;

It returns NULL again

How can I solve this issue

SNaRe started a new conversation Advice For Poor Api Services • 3 weeks ago

I get information from an api services that crashes approximately every 5 minustes. And the amounth of data is very huge about 5gb per day. Could you give any advice from your experiexces? Thanks in advance.

MS7G.png

2nd May, 2018

SNaRe left a reply on Horizon Doesn't Show Failed Jobs On Forge • 3 weeks ago

Also I couldn't monitor tags. When I click "Monitor Tag" and wrote the tag name clicked "Monitor" nothing happens? Not: Horizon processes 8000 jobs per hour could the reason be related with this ?

SNaRe left a reply on Horizon Doesn't Show Failed Jobs On Forge • 3 weeks ago

Any thoughts what could be the reason?

30th April, 2018

SNaRe left a reply on Creating Public Url With Hashed Slug Parameter • 3 weeks ago

@Cronix the url is for customers and the page should be accessed without auth so with clicking url they could accessed the page

SNaRe started a new conversation Horizon Doesn't Show Failed Jobs On Forge • 3 weeks ago

In my local, horizon works perfectly and shows failed jobs.

Unfortunately, when I push on github and then forge. I couldn't see failed jobs on horizon dashboard.

When I look chrome developer tools I can see the failed jobs are coming but doesn't shown on the page. What could be the problem? Thanks in advance

I tried "composer dump-autoload -o" but nothing changed.

and my version: Laravel Framework 5.6.7

MoUg.png

28th April, 2018

SNaRe started a new conversation Creating Public Url With Hashed Slug Parameter • 4 weeks ago

I would like to have a page that can be reached by public but depending on the parameter on the URL, the access should be verified. Let me make it clear with an example.

compname.url.com/orderid/23424/{someHashedKey}

So orderid = 23424 is my DB primary key, compname is the unique name of order's company.

My plan is to create a hashed key with orderid and compname with some kind of salted hash.

So that when someone reaches to the page, I will create a hash(md5) from orderid,compname, and a salted hash and match with 'SomehashedKey'

Is this the best way or how should I do this?

25th April, 2018

SNaRe left a reply on Horizon Doesn't Retry Again • 1 month ago

Any help? Thanks in advance

22nd April, 2018

SNaRe left a reply on How To Dynamically Generate Queues In Laravel Horizon • 1 month ago

Thanks you all for your kind responses but if I set balance to auto user-2 can have 30 processes but it shouldnt be more than 1.

Do you have a solution for this?

And can I add dynamically queues array like the solution in middleware method?

Thanks a lot

SNaRe left a reply on How To Dynamically Generate Queues In Laravel Horizon • 1 month ago

Thanks for your reply :) You said that "I'm not a big fan of this" what could be other solutions ? In my case I have thousands of jobs for every user and these jobs should be processed one by one for every user

SNaRe started a new conversation How To Dynamically Generate Queues In Laravel Horizon • 1 month ago

My application requires to have dynamically generated queues with some prefix like

"process_user_1", "process_user_2", "process_user_n" The main idea is to separate execution of some jobs depends on model ID.

Because the api that I connect allows only 1 connection for a user

Normally I can configure in horizon.php but it should be dynamic e.g. I can have 1000 users so I must have 1000 different queues

What could be the solution?

This is my configuration

'User-1' => [ 'connection' => 'redis', 'queue' => ['User-1'], 'balance' => 'simple', 'processes' => 1, 'tries' => 10, ], 'User-2' => [ 'connection' => 'redis', 'queue' => ['User-2'], 'balance' => 'simple', 'processes' => 1, 'tries' => 10,

SNaRe started a new conversation Horizon Doesn't Retry Again • 1 month ago

Hi, I was trying to restart a failed job 2 days ago and it successfully completed the job. On the other hand now I try and doesn't retry the job only the circle turns around and nothing happens what could be the reason? Thanks in advance

19th April, 2018

SNaRe left a reply on Redirect With Session Doesn't Send Success Or Error • 1 month ago

Unfortunately this didn't work. I am wondering why this problem persists.

12th April, 2018

SNaRe left a reply on Passing A Model From A Function To Another • 1 month ago

Since the 1st one had return, I thought I don't need to return anything in the 2nd function. However, it seems that I am mistaken. @Joucke thank you

SNaRe started a new conversation Passing A Model From A Function To Another • 1 month ago

I have this Laravel snippet. I cal the function(1) from another function.

It gives me a "blank" page. I think it is something about model binding in here. Since the (1) function requires Request I have to send it inside the (2) But I think I am doing something wrong

function messages_without_product(Request $request,$message_type=0){ ...

}

function messages_without_product_answered(Request $request){ $this->messages_without_product($request,1); }

11th April, 2018

SNaRe started a new conversation Redirect With Session Doesn't Send Success Or Error • 1 month ago

I am on Laravel 5.6

I try to send success with session to show some success messages.

return redirect('templates')->with('success','Template added successfully'); It used to work perfectly. However, it stopped working now and I couldn't find the reasons why.

When I dd(redirect('templates')->with('success','Template added successfully');) I see success message inside it.

RedirectResponse {#438 ▼ #request: Request {#43 ▶} #session: Store {#279 ▼ #id: "9Qcvbynta2B3yrDPDGGj2UhPTjDsCgn1857UlQM0" #name: "laravel_session" #attributes: array:5 [▼ "_token" => "ngzN7cWaJIlYrQsCmfSdapbT1UnCJ7jxuld3VCeP" "_previous" => array:1 [▶] "_flash" => array:2 [▶] "login_web_59ba36addc2b2f9401580f014c7f58ea4e30989d" => 6 "success" => "Template Added Successfully" ] #handler: FileSessionHandler {#280 ▶} #started: true } But I try to read it in blade it doesn't show anything at all. As I said it used to work perfectly.

@if (\Session::has('success')) sdfsdf

<script>
    window.onload = function () {
        toastr.success("{{ \Session::get('success') }}");
    }
</script>

@endif I am thinking of my recent changes I put this 3 to middleware in kernel

    \App\Http\Middleware\EncryptCookies::class,
    \Illuminate\Session\Middleware\StartSession::class,
    \App\Http\Middleware\LimitDemoUser::class,

This is my full Kernel.php

9th April, 2018

SNaRe left a reply on UpdateOrCreate Always Create, Never Updates - Laravel Query Builder • 1 month ago

I found the problem. I didn't add default_notification_template_id to "insert" part of the query. So that it couldn't find any values. @m-rk thanks for investigating the problem with me.

SNaRe left a reply on UpdateOrCreate Always Create, Never Updates - Laravel Query Builder • 1 month ago

Yes notification_template_id is the primary key, default_notification_template_id is totally different something like a FK, but not.

SNaRe started a new conversation UpdateOrCreate Always Create, Never Updates - Laravel Query Builder • 1 month ago

I am trying to use updateOrCreate. However, although I don't change contents of my condition, it only creates, never updates an existing row.

  foreach($default_info as $default){
        $name = $default['notification_toggle_id'];

        $res = NotificationTemplate::updateOrCreate(
            [
                'notification_type_id' => (int)$requested_info["notification_type_id"],
                'company_id' => (int)$company_id,
                'default_notification_template_id' => (int)$default['default_notification_template_id']
            ],
            [
                'title' => 'foo',
                'body' => $requested_info[$name.'_description'],
                'is_active' => intval($requested_info[$name."_check"])
            ]
        );
    }

I even tried doing this to make sure nothing changes. But it doesn't update even this.

            'notification_type_id' => 66,
            'company_id' => 66,
            'default_notification_template_id' => 66

I tried this as well

public $incrementing = false; I dd() the result if it may give a hint. I couldn't find a trace to find the problem. It always create rather than updating the existing one with the condition in the first array

NotificationTemplate {#704 ▼ #dates: array:1 [▼ 0 => "deleted_at" ] #primaryKey: "notification_template_id" #fillable: array:5 [▼ 0 => "title" 1 => "body" 2 => "notification_type_id" 3 => "company_id" 4 => "is_active" ] #connection: "pgsql" #table: null #keyType: "int" +incrementing: true #with: [] #withCount: [] #perPage: 15 +exists: true +wasRecentlyCreated: true #attributes: array:8 [▼ "notification_type_id" => 1 "company_id" => 6 "title" => "foo" "body" => "bondy_content" "is_active" => 0 "updated_at" => "2018-04-09 18:59:34" "created_at" => "2018-04-09 18:59:34" "notification_template_id" => 42 ] #original: array:8 [▼ "notification_type_id" => 1 "company_id" => 6 "title" => "foo" "body" => "body_content" "is_active" => 0 "updated_at" => "2018-04-09 18:59:34" "created_at" => "2018-04-09 18:59:34" "notification_template_id" => 42 ] #changes: [] #casts: [] #dateFormat: null #appends: [] #dispatchesEvents: [] #observables: [] #relations: [] #touches: [] +timestamps: true #hidden: [] #visible: [] #guarded: array:1 [▼ 0 => "*" ] #forceDeleting: false }

SNaRe left a reply on Current User In Middleware • 1 month ago

It has been a year and still we have the same problem. I had to spend 3 hours to solve this issue @kennyS you rock!

8th April, 2018

SNaRe started a new conversation Restricting Access Of An User Based On A User Attribute Ask Question • 1 month ago

I have users table. These users table has company_id attribute.

I have some generic pages with ids for ex.

https://www.test.com/customer_question/p/4701/c/40960

This url needs to be access only if the logged in user has specific company_id. Otherwise some other people can just access to link by just incrementing IDS

So that in each controller ( index,store,update etc. ) I have to check with something like this

$company_id = Auth::user()->company_id;
$verify_seller = DB::table('sellers')
    ->select('*')
    ->where('company_id', '=', $company_id)
    ->get();

if ($verify_seller->isEmpty())
    return "This product neither belongs to your seller account nor another seller's product";

I think I can handle this by putting the code above to _construct function for each customer.

What is the best way to handle this kind of situation with Laravel?

Laravel version 5.6

6th April, 2018

SNaRe started a new conversation Laravel Builder Conditional Clauses That Can Return More Than 1 Condition Ask Question • 1 month ago

I want to add some extra clauses to my query only when I get a specific request

I can do it with https://laravel.com/docs/5.6/queries#conditional-clauses

->when($markeplace_id !=0, function ($query) use ($marketplace_id){
   return $query->join('seller b', 'a.seller_id', '=', 'b.seller_id')
});

->when($markeplace_id !=0, function ($query) use ($marketplace_id){
   return $query->join('marketplaces as c', 'c.marketplace_id', '=', 'b.marketplace_id')
});
->when($markeplace_id !=0, function ($query) use ($marketplace_id){
   return $query->where('c.marketplace_id','=',$marketplace_id)
});

Conditional-clauses only returns 1 clause. But I have 3. Should I use when 3 times or can I just bundle them in to 1 when ?

->join('sellers as b', 'a.seller_id', '=', 'b.seller_id')
->join('marketplaces as c', 'c.marketplace_id', '=', 'b.marketplace_id')
->where('c.marketplace_id','=',$marketplace_id)

3rd April, 2018

SNaRe started a new conversation Writing Better Query That Has WhereRaw • 1 month ago

I wrote a query like this. I thing whereRaw part could be written far better and eventually be more performant but I couldn't succeed.

DB::table('messages')
            ->select('*')
            ->where('message_type', '=', $message_type)
            ->whereIn('seller_id', $seller_id->pluck('seller_id'))
            ->whereNull('answer_id')
            ->whereRaw('market_place_id IN ( SELECT MAX(market_place_id) FROM messages GROUP BY product_id )', [], 'AND')
            ->orderBy('market_place_id', 'DESC')
            ->paginate(10);

30th March, 2018

SNaRe started a new conversation Best Practice To POST From Custom Route • 1 month ago

I have a custom route like this

questions/p/{product}/c/{customer}

The route is defined as

Route::get('questions/p/{product}/c/{customer}', '[email protected]');

In my page ( details ) questions/p/10/c/20 have an input box that I would like to post INSERT to DB by using variables {product} and {customer}

What is the best practice to deal with it? Adding PUT,PATCH,POST to Middleware or any other best practices? I don't want to do this in dirty way.

Thank you

27th March, 2018

SNaRe left a reply on How To Change Domain Name? • 1 month ago

I own a domain that I created on Forge. From now on I will be using another domain for my server. This is my case and I don't want to do it by redeploying :) I would have been great if I could just rename in forge, change NS in my Vultr account and ready to go

SNaRe left a reply on Search And Skip To Next Item In Collection • 1 month ago

@rin4ik it just find but doesn't find the next one.

@mdeorue What I couldn't understand about it is how does "current" knows the item that I set as current. Let's say for me 2 is the current one. But in your snippet it doesn't have a place?

BTW I solved like this but it doesn't seem to be the best way.

        $current_key =  $unanswered_messages_list->where('product_id',$product)->where('customer_id',$customer)->keys()->first();
        $next_key = $current_key +1;
        $next_page = $unanswered_messages_list->only($next_key)->first();

SNaRe started a new conversation Search And Skip To Next Item In Collection • 1 month ago

I have a collection below, which I would like to search and get the contents of the next items https://laravel.com/docs/5.6/collections#method-where

where() function would find for example. But I have 2 conditions.

$collection->where('product_id', '342')->toArray(); $collection->where('customer_id', '62')->toArray();

Let's say I figured out having 2 conditions inside collection

How can I get the contents of the next one? which is in this case +"product_id": 456 +"customer_id": 933

Collection {#630 ▼
  #items: array:14 [▼
    0 => {#638 ▼
      +"product_id": 378
      +"customer_id": 936
    }
    1 => {#635 ▼
      +"product_id": 342
      +"customer_id": 62
    }
    2 => {#597 ▼
      +"product_id": 456
      +"customer_id": 933
    }
    3 => {#632 ▼
      +"product_id": 450
      +"customer_id": 935
    }
    4 => {#633 ▼
      +"product_id": 435
      +"customer_id": 934
    }
  ]
}

26th March, 2018

SNaRe started a new conversation How To Change Domain Name? • 2 months ago

I want to change my domain name in forge.

I come up with a tweet of Taylor that Forge supports renaming servers.

https://twitter.com/taylorotwell/status/499656382417608706

Does that mean that it also changes the root domain name so that I can just enter my NS info to my new domain and change the domain name in Forge so ready to go?

The link in Taylor's tweet doesn't work so that I couldn't try renaming.

Can you please advise?

25th March, 2018

SNaRe left a reply on "prepareBindings() Must Be Of The Type Array, String Given" Problem • 2 months ago

Converting it to this solved my problem

        $unanswered_messages = DB::table('messages as yt')
            ->select('*')
            ->where('message_type', '=', 0)
            ->where('seller_id', '=', $seller_id)
            ->whereRaw('message_id = ( SELECT max(message_id) FROM messages st WHERE yt.customer_id = st.customer_id )', [], 'AND')
            ->get();

SNaRe started a new conversation "prepareBindings() Must Be Of The Type Array, String Given" Problem • 2 months ago

I have this query works like charm with raw select


SELECT
                              *,yt.customer_id,
                              yt.message_id
                            FROM messages yt
                            WHERE message_type = 0  
                            AND seller_id=$seller_id 
                            AND message_id =(
                                            SELECT max(message_id)
                                            FROM messages st
                                            WHERE yt.customer_id = st.customer_id
                                            ) 
                                            ;

I regenerated it with query builder through http://www.midnightcowboycoder.com/

I got this


DB::select(`*`,`yt.customer_id`,`yt.message_id`)
        ->from(`messages as yt`)
        ->where(`message_type`, `=`, 0)
        ->where(`seller_id`, `=`, `$seller_id`)
        ->whereRaw(`message_id = ( SELECT max(message_id) FROM messages st WHERE yt.customer_id = st.customer_id )`, [], `AND`)
        ->get();

However I got this error

Type error: Argument 1 passed to Illuminate\Database\Connection::prepareBindings() must be of the type array, string given, called in /Users/xxx/Sites/xxx/vendor/laravel/framework/src/Illuminate/Database/Connection.php on line 328

How can I solve this?

SNaRe left a reply on Auth::user() Long Response Time (8 Times Slower) • 2 months ago

@Snapey prod DB just to make sure about to problem. Codebase in local.

SNaRe left a reply on Auth::user() Long Response Time (8 Times Slower) • 2 months ago

I tried these and now it is 1 s, rather than 4,65s But still it is a simple query.

composer dump-autoload
php artisan clear-compiled
php artisan config:cache
php artisan route:cache
php artisan optimize --force

SNaRe left a reply on Auth::user() Long Response Time (8 Times Slower) • 2 months ago

@Snapey only 3 for now. There are only 3 additional columns to standart users table.

SNaRe left a reply on Auth::user() Long Response Time (8 Times Slower) • 2 months ago

@rin4ik in product server ( Forge ) it is slow as well.

Can anyone recommend a more reliable tools to get the response time of each query?

SNaRe left a reply on Auth::user() Long Response Time (8 Times Slower) • 2 months ago

@ejdelmonico Valet , php 7.2 postgres 10.1 @rin4ik I will try if it helps.

SNaRe started a new conversation Auth::user() Long Response Time (8 Times Slower) • 2 months ago

In my controller I execute this

$company_d = Auth::user()->company_id

I use laravel debugbar and I get these response times

select * from "users" where "id" = '3' and "users"."deleted_at" is null limit 1 - 4.65s select * from "sellers" where "company_id" = '3' - 675ms

The first query is pretty simple however it take 4,65s to load. I execute this query via datagrip and I got 505ms response time. This is 8 times faster than what debugbar gives me

Also my page loads pretty slow because of this.

What may be the problem?

5th March, 2016

SNaRe started a new conversation Why XLSX Validation Works, XLS Is Not? • 2 years ago

I am creating an upload form. The form should only accept XLS and XLSX.

I use this validation rule $rules = array( 'file' => 'required|mimes:xlsx,xls', ); XLSX validation work fine, but XLS is not. vendor/swiftmailer/swiftmailer/lib/mime_types.php

I checked mime_types and it is there 'xls' => 'application/vnd.ms-excel',

How can I make Laravel validation work with XLS as well?

SNaRe started a new conversation How To Disable Password Activation On Registeration? • 2 years ago

I am trying to figure out how I can successfully disable password activation after registeration.

I don't want to bother users with activation but they may be able to reset their email whenever they want.

I think it has something to do with here but I couldn't figure it out

Auth\PasswordController@sendResetLinkEmail

4th March, 2016

SNaRe left a reply on Is There A Way To Pull Commits That Awaiting To Be Merged Without Waiting The Release? • 2 years ago

But would it pull 5.2.22 already? If I do these can I get all those 107 commits as well?

SNaRe left a reply on Is There A Way To Pull Commits That Awaiting To Be Merged Without Waiting The Release? • 2 years ago

@ohffs It only pulls the ones that Taylor merged 6 days ago, which is 5.2.22

Those 94 commits are waiting Taylor to get merged and have a new tag.

@taylorotwell taylorotwell tagged this 6 days ago · 94 commits to 5.2 since this tag

SNaRe started a new conversation Is There A Way To Pull Commits That Awaiting To Be Merged Without Waiting The Release? • 2 years ago

As it is shown in here https://github.com/laravel/framework/compare/v5.2.22...5.2 There are new 94 commits have been made until the latest version tagging. However I want to pull these commits without waiting @Taylor's action. I know that I can pull it with something like this composer create-project laravel/laravel your-project-name dev-develop But this gives me Laravel 5.3.0-Dev, which I am not sure if it is the version that has these 94 commits or the very very new features that we will be seeing in next version. The bottom line, is there a way to pull these 94 commits without waiting @Taylor?

1st March, 2016

SNaRe left a reply on Commercial CMS Built With Laravel • 2 years ago

It is open-source but plugins and themes are commercial.

I think this is even better than any CMSs in the world.

http://octobercms.com

29th February, 2016

SNaRe started a new conversation Migration Without Losing Data • 2 years ago

This is the scenerio I created a migration table and inserted some values for test purposes. Afterwards, I realized that I need to add another column. Now I have to rollback migration and php artisan migrate again. But my inserted values are deleted as well. Is there a way to add new column or change behavior of a row through migration files without losing data?

16th February, 2016

SNaRe started a new conversation What Is The Best Practice To Apply Minor Updates? • 2 years ago

I started developing my app with 5.2.15.

https://github.com/laravel/framework/releases/tag/v5.2.15

But today 5.2.16 is released

https://github.com/laravel/framework/releases/tag/v5.2.16

What is the best practice to apply this update from 5.2.15 -> 5.2.16 ?

17th January, 2016

SNaRe left a reply on Choosing Between Angular And React For My Project • 2 years ago

There are 100's of articles, posts about this topic. But if you want to read only 1 and least "biased" check the first post on this quora comments of Vue.Js creator

https://www.quora.com/Which-should-I-learn-Mithril-Vue-or-Angular

it couldn't have been explained better.

10th January, 2016

SNaRe left a reply on Multitenant Tutorial; Following L5.2 & Sparks? • 2 years ago

@JeffreyWay said that he would start Laravel 5.2 from Scratch series in the midst of January. I think he has been waiting for Laravel 5.2 to be more stable, which makes sense

3rd January, 2016

SNaRe left a reply on PHP7 & Digitalocean Problem • 2 years ago

My real problem was

apache2: Syntax error on line 140 of /etc/apache2/apache2.conf: Could not open configuration file /etc/apache2/mods-enabled/php5.load: No such file or directory
Action 'configtest' failed.
The Apache error log may have more information.

Solved it by running

$ cd /etc/apache2/mods-enabled
$ a2dismod php5
$ service apache2 restart

SNaRe left a reply on What Happen Now To Laracast! :D • 2 years ago

@jeffreyWay is it on PHP7 as well or are you skeptical about upgrading to PHP7?

Edit Your Profile
Update

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