Buy your loved one the ultimate gift. Lifetime gift certificates are $100 off.

bart

Experience

57,990

28 Best Reply Awards

  • Member Since 3 Years Ago
  • 480 Lessons Completed
  • 48 Favorites

21st November, 2017

bart left a reply on Failed To Install With Composer • 3 weeks ago

I have the exact same issue on OSX. Any idea what the reason is?

10th November, 2017

bart left a reply on General API Auth Question For SPAs • 1 month ago

Are you sure? Okay, then I had a wrong understanding of it! I always thought that the browser makes the request and so the IP address of the user matters. I thought that for server to server requests CORS solves the problem but didn't know that it is also applicable for client to server requests. I'll try it during weekend, thank you so much!!

bart left a reply on General API Auth Question For SPAs • 1 month ago

Exactly. But I can't whitelist a domain here, because the Browser of each user calls the endpoint. It's not like an "old-days" API request, where the client calls the server that calls the backend API. I want to call the backend from the frontend (Browser) directly to save a roundtrip.

bart left a reply on General API Auth Question For SPAs • 1 month ago

How would CORS solve the problem? I mean doesn't it only allow that my domain allows access from a different domain? But it won't protect my backend from being used by another service, right?

bart started a new conversation General API Auth Question For SPAs • 1 month ago

Hey everybody,

maybe one of our next projects could be a VueJS driven SPA (no PHP) on the frontend w/ Laravel API on the backend. I'm now curious about how to allow specific parts of that website to communicate with backend but prevent 3rd party services to use the same API.

I would like to give an example: Let's say we have a chart on our homepage (no login or something, visible to anybody) that gets its data from an axios API call. How can I prevent people from using this exact same endpoint for their own website? I mean there are technologies like oath2 and JWT tokens, but for me they won't solve this specific problem.

As a potential "thief" you can open your Chrome dev tools network tab and check the requested URL. Then you could use the exact same URL to get this data.

Do you have any idea how to solve this or isn't it solvable simply by design?

Thanks a lot!

7th November, 2017

bart left a reply on Generate Query URL • 1 month ago

Okay, I found a solution. Not a very clean one but for my personal taste better than an if check.

public function buildQuery($baseUrl, array $params) {
    parsedUrl = parse_url($baseUrl);
    parse_str(array_key_exists('query', $parsedUrl) ? $parsedUrl['query'] : '', $queryParams);
    $queryParams += $params;

    return sprintf('%s://%s%s?%s', $parsedUrl['scheme'], $parsedUrl['host'], $parsedUrl['path'], http_build_query($queryParams));
}

bart started a new conversation Generate Query URL • 1 month ago

Hey everybody,

I'm searching for a method in PHP that generates a full query URL by passing a base URL (which could already include a query string) plus additional parameters.

I know that I could check if the URL contains a "?" and if so append with "&", otherwise append with "?". The question here is, if PHP has such a method on board?

I'll give you an example:

// Only works if $baseUrl not includes parameters
public function buildQuery($baseUrl, array $params) {
    return $baseUrl . '?' . http_build_query($params);
}

// But what if I do this?
$url = $this->buildQuery('https://my.endpoint.com/fetch?subject=php', ['maxlength' => 10]);

Any ideas?

Thanks a lot!!

3rd November, 2017

bart left a reply on MapWithKeys Only Return One Item • 1 month ago

Any solution here? I have the exact same issue after upgrading from 5.3 to 5.5.

$options = $users->mapWithKeys(function ($area) {
    return [['id' => $area->id, 'title' => $area->name]];
});

It only returns the last item but $users->count() is 75. Any idea?

Thanks a lot!

25th October, 2017

bart started a new conversation Handle Async Guzzle Requests • 1 month ago

Hey everybody,

I'm currently working on a project where I would like to initiate an AJAX request to my backend which should call multiple APIs in parallel and should also return each result separately back to the frontend which should process it.

I know that PHP isn't well known for multithreading so my main question is if it's possible and if yes, how would you tackle it?

I used the requestAsync() method of Guzzle which could be used to fire off multiple API requests in parallel. The problem is, that I need to wait for all responses before sending the response for the frontend. Do you have an idea if there is another way?

Alternatives I thought about could be:

  1. Fire multiple AJAX requests to my backend and pass something like an API parameter, so that the backend knows which API it should call for each request
  2. Queues could be another option to fire off multiple requests but I think I need to use pusher or something in that case to push the results of each API request into the frontend

What do you think about it?

Thanks a lot!!

16th October, 2017

bart left a reply on A/B Testing With Laravel 5.4 • 1 month ago

Exactly, that's why we searched for a package. In the end we created our own you can find here: https://github.com/bart/ab

We are not able to use providers like Optimizely and Google A/B because we don't just want to change one button but instead about 70% of the page including logical stuff (which needs changes in our core Vue components). For sure, there maybe is some way to handle it with those tools but in the end in my opinion this will take more effort than coding it into the project itself. For us this was the best solution.

1st August, 2017

bart started a new conversation Pretty Weird ES6 Issue • 4 months ago

Hey guys,

a colleague of mine found a pretty interesting ES6 issue that is very easy to reproduce. You can add the following lines of code somewhere in a script tag.

const data = [{title: 'a'}, {title: 'b'}, {title: 'c'}];
console.log(data);
data.forEach((d, index)=> {
    d.title = 'd';
});

What I expected as a result of console.log() was an array of three objects having titles of "a", "b" and "c". But what we actually got was an array of three objects with a title of "d". Why? Do you have any explanation for it? Why does console.log() gets called after the foreach loop?

Thanks and kind regards!

17th July, 2017

bart started a new conversation A/B Testing With Laravel 5.4 • 4 months ago

Hey everybody,

we want to add some A/B tests to our new website. Because it's not only changing a button color from green to red, using tools like optimizely isn't the right approach imo. Furthermore we should do this server-side. Unfortunately the AB testing package from Jens Segers (https://github.com/jenssegers/laravel-ab) isn't compatible with Laravel 5.4

So my question is: Do you guys have any alternative? Or maybe another better approach? How are you doing complex A/B testing?

Really looking forward your ideas. Thanks!!

bart left a reply on Spark Pay Per Use System • 4 months ago

Same question here! Did you find any solution for this?

20th June, 2017

bart left a reply on SEO Issue • 5 months ago

Thanks @martinbean but unfortunately this doesn't answer my question ;) The question that I had was about SEO and how I can prerender or something only for crawlers but prevent them from getting into cloaking issues.

bart started a new conversation SEO Issue • 5 months ago

Hey everybody,

we developed our new dynamic website with a lot of Vue components. The issue we came across with was the page source that gets rendered by the Google crawler for example.

<breadcrumb class="is-hidden-mobile" :items="[{ THIS IS AN OBJECT FROM TH BACKEND }]"></breadcrumb>

That's how the breadcrumb in our source code looks like. When I inspect the element in Chrome everything is fine and I see the rendered result. But that's not what Google crawls. I read a lot of articles about server-side rendering but for using this we need to change our entire infrastructure so that's not an option for now. Another way is prerendering but this only works for non-dynamic content so my question here is: Do you came across with this issue? And if so, what was your solution?

Thanks a lot and kind regards!

12th June, 2017

bart left a reply on Tricky SQL Problem • 6 months ago

Thanks a lot @jlrdw but I need to handle this in the database. I found an okay way to pre calculate everything and store it in the database. This created another tricky task but I'll try to solve it first by myself.

11th June, 2017

bart started a new conversation Tricky SQL Problem • 6 months ago

Hey guys,

I have two tables that contain spatial geo data. For example I have one table pois that has columns latitude and longitude and a second table cities that also has two columns latitude and longitude.

What I want to create a list of all cities in relation to all pois where the distance is not more than 100km.

Is that possible via mysql? Lets say we have about 500k cities and 1k POIs. I didn't find a way to do that in one live query but maybe you have a solution for that. Would be amazing!!

Thanks a lot.

31st May, 2017

bart left a reply on How To Turn Laravel Web App Into Iphone App? • 6 months ago

You can't convert a server-side application into a mobile app. The mobile part could only be the frontend part so to speak. If you want to start with as least work as possible I would suggest to use Ionic Creator (https://creator.ionic.io). But you always need a backend (Laravel) component for mobile application if you want to share data, store data in a database etc. It's possible to do this without a server for example using AWS Lambda functions etc. but I think that's a bit too much depth here.

bart started a new conversation Implementing Query Scope Selects • 6 months ago

Hey guys,

I want to add a select query scope like you can find here: https://theokouzelis.com/php/laravel-eloquent-calculated-fields.html

It would like to select the distance between my model and a passed geo location like this:

public function scopeWithDistanceToPoint($query, $latitude, $longitude)
    {
        return $query->selectRaw("ST_Distance_Sphere(POINT({$longitude}, {$latitude}), POINT(longitude, latitude)) as distanceToPoint");
    }

To get all fields in return I also need to override the newQuery() method of my model:

public function newQuery() {
        return parent::newQuery()->select('objects.*');
    }

What I can do now is:

return Object::take(10)->withDistanceToPoint(0, 0)->get();

I want to add specific fields I want to get back from the Eloquent collection like this:

return Object::take(10)->withDistanceToPoint(0, 0)->get(['id', "title->{$this->locale} as title"]);

But the problem is, that I don't get the title in the given locale back. Instead it returns the entire title JSON object. This is because of the newQuery() method override. Do you have an idea what's wrong here and how to resolve this issue?

Thanks a lot!!

2nd May, 2017

bart left a reply on Weird Collections Issue With Objects • 7 months ago

Pretty funny. I'm working with PHP since version 3 but didn't know about the reference topic. Shame on me ;)

bart left a reply on Weird Collections Issue With Objects • 7 months ago

I have seen that I can use clone() on objects but in this case I have an array of objects. The funny thing here is, that it creates a copy of the array but not if its (object) items. I'll try the hacky (object) (array) type selection,

bart left a reply on Weird Collections Issue With Objects • 7 months ago

Yes @nikazooz that's right. It seems like PHP always generates references when using object. I created another simple example, that demonstrates the issue without any Laravel specific method:

$link = (object) [
    'title' => 'Home',
    'url' => '/',
];

$link2 = $link;

$link->url = '#';

dd($link, $link2);

The url property is "#" for both now. Any idea how to "disable" the reference here when creating a new variable from it?

bart left a reply on Weird Collections Issue With Objects • 7 months ago

No idea?

bart started a new conversation Weird Collections Map Method • 7 months ago

Hey everybody,

I'm currently having some trouble wit the map() method of collection because it looks like it uses the source data as a reference. I will try to explain it by example:

$images = collect($this->dataFromExternal->images);

$images->map(function($image) {
            $image->filename = '#' . $image->filename;

            return $image;
        });

I would expect that the filename property of each $this->dataFromExternal->images element does not change but a dd($this->dataFromExternal->images) shows a hash as first character for each filename property here. Why? It looks like collection() creates a reference to the original array, doesn't it?! Any idea how to solve this?

Thanks a lot!

18th April, 2017

bart left a reply on Wait For External Resources • 7 months ago

OMG the answer is so simple, shame on me! You just have to load the external scripts before the bundled app.js file - that does the trick. Found this in a comment by Evan You.

bart left a reply on Wait For External Resources • 7 months ago

You're absolutely correct. I load an external Javascript file from inside the layout file and its not loading before the vue component. It should be possible to watch for a global variable named "flowplayer". How would I do that?

bart started a new conversation Wait For External Resources • 7 months ago

Hey guys,

I want to build a Vue component that handles flowplayer videos. Sounds pretty simple and I'm sure it is, but I don't know how to solve the "DOM ready" stuff in Vue.

I currently have the following (example):

<template>
    <div id="video"></div>
</template>

<script>
    export default {
        mounted() {
            flowplayer('#video');
        }
    }
</script>

When I do this I'm getting something like flowplayer is not defined. How can I wait for the external JS script to be ready? I already tried this.$nextTick() {} but it didn't work, too. Maybe I can try window.onload = function () {}; but that does not feel right to me. What do you think? What's the best solution here?

Thanks and best regards.

14th March, 2017

bart left a reply on OOP Question • 8 months ago

Okay, just for your information: it is possible accessing private values by using the setAccessible() method of the reflected property before. That does the trick here.

bart left a reply on OOP Question • 8 months ago

Hey @revati,

thanks for the answer. Well, creating an array and setting all keys and values manually using the corresponding getter is possible. But I hope that there is a more elegant way to solve this.

I already played around with ReflectionClass but is it possible to get the private values from the original class using this way? That would do the trick!

bart started a new conversation OOP Question • 9 months ago

Hey guys,

I'm using the Affilinet PHP SDK that returns product data for a given shop. The data I get in return is an object with private properties and lots of getters.

What I want to store this raw object in my database for further manipulation later on. But using json_encode() does not work here, due to the private scope of the properties. I can't add the implementation of \JsonSerializable because it's a third party class.

Do you have any idea how to store the plain object JSON? Thanks a lot!

22nd February, 2017

bart started a new conversation Mixing Collections • 9 months ago

Hey guys,

I have a collection of items that have two different priorities. I want to sort the items inside of this collection using the priority value but not simply sorting in ascending order. I want to take 3 of priority 1 and then 1 of priority 2, 3 of priority 1 and 1 of priority 2 and so far.

I expect the following result:

Before:

[
    'name' => 'John',
    'priority' => 2,
],
[
    'name' => 'Jack',
    'priority' => 1,
],
[
    'name' => 'Jane',
    'priority' => 1,
],
[
    'name' => 'Leo',
    'priority' => 1,
],
[
    'name' => 'Mike',
    'priority' => 1,
],
[
    'name' => 'Sarah',
    'priority' => 2,
],
[
    'name' => 'Jody',
    'priority' => 1,
],
[
    'name' => 'Lena',
    'priority' => 2,
],

After:

[
    'name' => 'Jack',
    'priority' => 1,
],
[
    'name' => 'Jane',
    'priority' => 1,
],
[
    'name' => 'John',
    'priority' => 2,
],
[
    'name' => 'Leo',
    'priority' => 1,
],
[
    'name' => 'Mike',
    'priority' => 1,
],
[
    'name' => 'Sarah',
    'priority' => 2,
],
[
    'name' => 'Jody',
    'priority' => 1,
],
[
    'name' => 'Lena',
    'priority' => 2,
],

Do you have any idea how to achieve this? Thank you very much!

23rd January, 2017

bart started a new conversation Pass Javascript Variable As Property • 10 months ago

Hey guys,

sometimes you stuck like I currently do. I created a vue component and want to pass an object as property. I don't know how to do that :(

<script>
let my_prop = {firstname: 'Jack', lastname: 'Bauer'}
</script>

<my-component user="my_prop"></my-component>

I tried everything from :user="my_prop" until user="{{ my_prop }}".

Do you have any idea what's wrong here? Thanks!

17th January, 2017

bart left a reply on [Flexbox] How To Use Full Width • 10 months ago

Solved it... omg sorry. Simply use flex:1 on that darker grey box,

bart started a new conversation [Flexbox] How To Use Full Width • 10 months ago

Hey guys,

I'm playing around with flexbox and asking myself how use the full width in a navbar. I created a simple fiddle here: https://jsfiddle.net/egvcw7cx/

I want to achieve that the darker box on the right side fills the whole space between the lighter grey box. Do you have any idea how to solve this?

Thanks a lot!!

3rd October, 2016

bart left a reply on Pass Data From Listener To Event • 1 year ago

Well, thank you so much @belisar. That will solve the problem imho. I will give it a further read but I think that's exactly what I've looked for. I'm a bit confused, that I never heard of the pipeline design pattern. But hey, we never stop learning.

bart left a reply on Pass Data From Listener To Event • 1 year ago

Hey @belisar and thanks a lot for your detailed explanation. As I wrote above I'm trying to manipulate data from listener to listener and want to remember something I called "rejects". In the and (in the last listener) I like to send one email that contains all rejects from all listeners.

bart left a reply on Pass Data From Listener To Event • 1 year ago

Well I thought about it but in my case it does make sense. I do different steps (different listeners for one event) and collect rejects during this process. In the end I want to send one email with collected information about the rejects. That is not possible if I would fire a single event from each listener.

bart started a new conversation Pass Data From Listener To Event • 1 year ago

Hey everybody,

I'm using events on my current project and like to pass data from one listener to another by pushing it to the event. But it won't work. Maybe because the listeners are queued. Do you have any idea? Here I go with some code:

// Event service provider
protected $listen = [
        'App\Events\HasBeenUpdated' => [
            'App\Listeners\Action1',
            'App\Listeners\Action2',
        ],
    ];

// HasBeenUpdated.php
public $rejects;

public function __construct()
{
        $this->rejects = 0;
}

// Action1.php
public function handle(HasBeenUpdated $event)
{
        $event->rejects = 1;
}

// Action2.php
public function handle(AreaUpdated $event)
{
        dd($event->rejects); // Result is 0 but I expected it to be 1
}

Thanks for ya help!

22nd September, 2016

bart left a reply on How To Install CKeditor On Laravel 5.2 • 1 year ago

Hey everybody,

I want to use CKEditor for a content project, but I don't get it working using elixir. Sure, I can use composer, copy the files via mix.copy to a public directory and include the JS and CSS files into my template but that's not what I want. I'm using lots of different components like jQuery plugins, leaflet.js etc. everything included and bundled into one single bundle.js via elixir.

What I want now is to add CKEditor the same way. I know there is an npm package out here, but it's not possible for me to use it because you have to copy the files into a public directory again.

Any idea how to solve this?

8th September, 2016

bart left a reply on Pass Config Array As Prop To A Component • 1 year ago

Hehe maybe it works on Vues side, but not on the Laravel side. When I try to pass an array I'm getting the htmlentities() error message in the blade template. Or should I try {{{ }}} instead of {{ }} ?

7th September, 2016

bart left a reply on Pass Config Array As Prop To A Component • 1 year ago

I think it won't work without braces, right? And when I use them I'm getting the htmlentities() error again.

6th September, 2016

bart started a new conversation VueJS Select2 Input Model Binding • 1 year ago

Hey everybody,

I have something like this:

''' ...

new Vue({ el: '#app',

data: {
    selection: ''
},

methods: {
    checkMe() {
         console.log(this.selection)
    }
}

} '''

I expected an array of selected items here but I'm getting the empty string logged to console. Do you have any idea what I can do here? I think the problem is, that selectize won't update the "ghost" element, but some child elements it creates on the fly, right?

Thanks a lot!

bart left a reply on Pass Config Array As Prop To A Component • 1 year ago

Okay I think I can answer this question on my own. You NEED to pass the data by json_encode() them. It's a simple HTML field so nothing else makes any sense here.

bart left a reply on Clear Log File Using Laravel Method ? • 1 year ago

Do you mean an artisan command?

bart started a new conversation Pass Config Array As Prop To A Component • 1 year ago

Hey everybody,

I want to implement a scope selection using VueJS components via Vueify. We have some basic configuration in a config/acme.php file stored as an array like 'available_scopes' => ['foo', 'bar']. I do want to show these available scope in a dropdown using a VueJS component but I don't know how to pass an array to the component props. Is this possible without JSON encode and decode?

// template.blade.php
<scope-selector scopes="{{ config('wave.content_api.destinations') }}"></scope-selector>

// component.vue
<script>
    export default {
        props: [scopes'],
        ready() {
            console.log(this.scopes);
        }
    }
</script>

When doing this I'm getting "htmlentities() expects parameter 1 to be string, array given", sure. I could json_encode() the config array but it feels bad to me encoding this into JSON and decode it in the component. Do you have any suggestions what I could do here?

Thanks a lot!

7th July, 2016

bart left a reply on Can't Run Composer Command Because Of An Error • 1 year ago

Did you check file and folder permissions?

bart started a new conversation [Issue] Caching With Array Driver • 1 year ago

Hey everybody,

I'm using the entrust package to handle roles and permissions. This package forced me to switch the cache driver to something else than file or database. In most threads I read about using array as cache driver.

When using this driver I'm not able to cache data anymore. Simple example in my routes.php:

Route::get('test', function() {
    $data = Cache::remember('foo', 5, function() {
        return 'bar';
    });

    return $data;
});

When I hit the route, change return 'bar'; to return 'foo'; "foo" gets returned. But imo "bar" should be stored in the cache for 5 minutes instead. When changing the cache driver to file it works like expected. Do you have any idea what causes the issue here?

Thanks a lot.

30th June, 2016

bart left a reply on Envoyer.io And Elixir? • 1 year ago

I'm currently having the same problem here. Your solution sounds good, but what if I add additional node modules to the package.json file? So with that in mind I do have to run npm install on every deploy when I want to compile everything on the server, right?

24th June, 2016

bart left a reply on Composer: Command Not Found • 1 year ago

Okay, it seems like I have to install all the dependencies on my own like some php extensions, composer itself and so far. But then it works.

bart left a reply on Composer: Command Not Found • 1 year ago

Well what I don't understand is, that I deployed the server using forge as well. So it's not a custom one. So imho when I create a new server via forge it should all required dependencies, shouldn't it?

Edit Your Profile
Update

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