stefan7

stefan7

Member Since 1 Year Ago

Experience Points
5,640
Total
Experience

4,360 experience to go until the next level!

In case you were wondering, you earn Laracasts experience when you:

  • Complete a lesson — 100pts
  • Create a forum thread — 50pts
  • Reply to a thread — 10pts
  • Leave a reply that is liked — 50pts
  • Receive a "Best Reply" award — 500pts
Lessons Completed
49
Lessons
Completed
Best Reply Awards
0
Best Reply
Awards
  • start-engines Created with Sketch.

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • first-thousand Created with Sketch.

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • 1-year Created with Sketch.

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • 2-years Created with Sketch.

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • 3-years Created with Sketch.

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • 4-years Created with Sketch.

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • 5-years Created with Sketch.

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • school-session Created with Sketch.

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • welcome-newcomer Created with Sketch.

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • full-time-student Created with Sketch.

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • pay-it-forward Created with Sketch.

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • subscriber-token Created with Sketch.

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • lifer-token Created with Sketch.

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • lara-evanghelist Created with Sketch.

    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 Created with Sketch.

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • lara-veteran Created with Sketch.

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • 10k-strong Created with Sketch.

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • lara-master Created with Sketch.

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • laracasts-tutor Created with Sketch.

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • laracasts-sensei Created with Sketch.

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • top-50 Created with Sketch.

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

Level 2
5,640 XP
Nov
09
1 week ago
Activity icon

Replied to Vue Axios Request Not Working In Chrome (iframe)

Thank you Jaytee, working now.

For others who have same trouble, in detail:

In app/Http/Middleware/VerifyCsrfToken.php

Add your route(s) of ajax request(s) in the $except array (which is already included in the file), example with wildcard for all routes that starts with "iframe/..."

    protected $except = [
        'iframe/*'
    ];
Nov
08
1 week ago
Activity icon

Started a new Conversation Vue Axios Request Not Working In Chrome (iframe)

I have a component that is loading content via axios. In general the component and the axios request is working fine. But the website is meant to be running in an iframe on other websites ( i know... customers request...)

When website is embedded in an iframe, it is working with Firefox and IE, but no Chrome. Only error i get is 419. CRSF is set.

POST https://www.content.com/iframe/show 419

Additionally another error in chrome: the website has a search-form included. When I use the search form in the iframe, it shows as well a "Page expired 419" message, but in this case the message is directly shown in the browser, whereas the other show-route only shows the 419 console. Both get the contents with axios request.

I am stuck with this, any idea how to solve it?

Nov
02
2 weeks ago
Activity icon

Replied to Query With WhereHas

Thank you, did not know about the resolve-helper.

Activity icon

Started a new Conversation Query With WhereHas

Hi, I need a query where I can insert the table-name in a flexible way and query should return all products that are connected with exporter (many to many). I was wondering why this is not working

        $products = DB::table('products')->whereHas('exporters', function (Builder $query) use($exporterId) {
            $query->where('exporter_id', '=', 1);
        })->get();

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'has' in 'where clause' (SQL: select * from products where has = exporters)

Whereas this works:

        $products = Product::whereHas('exporters', function (Builder $query) use($exporterId) {
            $query->where('exporter_id', '=', 1);
        })->get();

How can I get the first query to work? Thank you

Oct
15
1 month ago
Activity icon

Replied to Hidden Field Value Not In Request Parameters

Can you give a an example please? I tried to wrap the code of formSubmit() into a nextTick(), but did not work. Thank you

this.$nextTick(() => {
//location field checks
}):
Activity icon

Replied to Hidden Field Value Not In Request Parameters

Sure:

   formSubmit() {
                let place = this.autocomplete.getPlace();
                if(place !== undefined && place.geometry !== undefined) {
                    this.latResult = place.geometry.location.lat();
                    this.lngResult = place.geometry.location.lng();
                } 
                
                //check if given location is a postal code with 5 digits
                if (/^\d{5}$/g.test(this.locationResult)) {
                    let geocoder = new google.maps.Geocoder();

                    let that = this; 
                    geocoder.geocode({'address': this.locationResult + ", Deutschland"}, function(results, status) {
                        if (status == google.maps.GeocoderStatus.OK) {
                            that.locationResult = results[0].formatted_address;
                            that.latResult = results[0].geometry.location.lat();
                            that.lngResult = results[0].geometry.location.lng();
                        }
                    });
                }
            }
Activity icon

Replied to Hidden Field Value Not In Request Parameters

Keyup makes in this context no sense, as the location field should be completely written. Moving method of checkLocationInput() directly to formSubmit() did not work either. The weird thing is, that i added .stop.prevent to the button.

When I console.log at the end of formSubmit(), the variables latResult and lngResult were updated. But if I dd($request) it still shows the the old values.

  <button @click.stop.prevent="formSubmit()" type="submit" class="btn btn-primary form-submit"> <i class="material-icons align-middle">search</i> Suchen </button>

Activity icon

Started a new Conversation Hidden Field Value Not In Request Parameters

Hi, I have a form with a location field. After user enters location, a function is doing some checks and then calculating the lat/lon values. The function updates two hidden fields for the lat/long values (which are binded with v-model).

The problem is, when a user is typing a location and hits immediately enter. Then form is submitted right away and the request parameters does not contain the lat/lon values. (Although that I can see the value was updated in browser dev tools. )

It is working if the user changes the same location field, clicks then somewhere outside of the field (blur) and after that the submit button.

How can I make this work?

  <input v-model="latResult" type="hidden" name="lat" value="">
  <input v-model="lngResult" type="hidden" name="lng" value="">


  <input ref="autocomplete"
                       v-model="locationResult"
                       name="location"
                       placeholder="Example: London"
                       class="form-control "
                       onfocus="value = ''"
                       v-on:blur="checkLocationInput()"
                       type="text" />
Aug
14
3 months ago
Activity icon

Started a new Conversation Add Variable For All Views In AppServiceProvider

Hi, store in a cookie some values to add them to the search-form on each page (in order to prefill the search-form) :

  • used search-term
  • location name + lat/lon

I use the boot() function in AppServiceProvider to make a variable with the cookie values available in each blade file.

The problem is, if a user uses the search-form, it updates the cookie values. But on view this "global" variable of AppServiceProvider does not deliver the newest value. Then if i reload the page, the updated values appear. How can I get immediately the current cookie values?

In SearchController:

Cookie::queue(Cookie::make('search', json_encode($newCookieData), 60 * 24 * 365));

Within boot() in AppServiceProvider:

try {
    if (Cookie::has('search')) {
        $cookieValues = json_decode(
            Crypt::decrypt(
                Cookie::get('search'),
                false) //unserialize = false prevents errors
        );
    } else {
        $data = [
            'search_term' => '...',
            'location' => '...',
            'lat' => '...',
            'lng' => '...'
        ];
        Cookie::queue(Cookie::make('search', json_encode($data), 60 * 24 * 365));
    }

    view()->share('searchCookie',
        isset($cookieValues) ? $cookieValues : NULL
    );
} catch (\Exception $e) {
    //
}     
Jul
10
4 months ago
Activity icon

Started a new Conversation Elasticsearch Prepare Data For Indexing

Hi, i have mysql tables with companies and products. Now i want to create a Elasticsearch index of all products that contains the company data as well.

I use https://github.com/babenkoivan/scout-elasticsearch-driver

The following function seemed to work in first place but it indexes for all products the same company data. Why and how can i solve this??

    public function toSearchableArray()
    {
        $product = $this->with('branch')->first();
        $array = $product->toArray();
        //prepare data for geo field
        $array['geo_data'] = $array['branch']['address_latitude'] .','. $array['branch']['address_longitude'] ;

        return $array;
    }

I tried it as well with something like

$product = Product::where('id', $this->id)->with('branch')->first();

But then i get an error

 {"error":{"root_cause":[{"type":"illegal_argument_exception","reason"
:"Limit of total fields [1000] in index [product_index] has been exceeded"}]
Jul
07
4 months ago
Activity icon

Replied to Remove Entry Of Collection

For anybody might having the same problem: Adding ->values() solved the problem, it is now working with easyAutocomplete as well.

So it would be something like

        $result = $categories->filter(function (Category $category) {
            $parentCategory = Category::find($category->parent_id);
            return $parentCategory->parent_id != 0;
        })->values();
Jun
18
5 months ago
Activity icon

Replied to How To Create URL Slugs In Laravel

str_slug($title) is deprecated, use:

Str::slug($title)


$slug = Str::slug('Laravel 5 Framework', '-');

https://laravel.com/docs/5.8/helpers#method-str-slug

Jun
10
5 months ago
Activity icon

Started a new Conversation Get All Parent Categories

Hi,

I have a category model with parent_id attribute. I am trying to write a function that gives me all the parents. dd($parent) returns only string: "parent_id" What am I missing? And what is here the difference between $parent = $this->parent(); and$parent = $this->parent; ??

    public function parent()
    {
        return $this->belongsTo('App\Models\Category', 'parent_id', 'id');
    }

    public function getAllParents()
    {
        $parents = collect([]);
        $parent = $this->parent;

        while(!is_null($parent)) {
            $parents->push($parent);
            $parent = $parent->parent;
        }

        return $parents;
    }

dd($this) returns object

Category {#399 ▼
  #parent: "parent_id"
  #appends: array:1 [▶]
  +fillable: array:3 [▶]
  #connection: "mysql"
  #table: null
  #primaryKey: "id"
  #keyType: "int"
  +incrementing: true
  #with: []
  #withCount: []
  #perPage: 15
  +exists: true
  +wasRecentlyCreated: false
  #attributes: array:7 [▼
    "id" => 7
    "parent_id" => 3
    "en_name" => "Category 7"
    "de_name" => "Kategorie 7"
    "slug" => "category7"
    "created_at" => "2019-06-03 11:27:37"
    "updated_at" => "2019-06-03 11:27:37"
  ]

I tried also this

$parent = $this->parent();

Which returns me, but is not accessible

BelongsTo {#419 ▼
  #child: Category {#399 ▶}
  #foreignKey: "parent_id"
  #ownerKey: "id"
  #relation: "parent"
  #query: Builder {#402 ▶}
  #parent: Category {#399 ▶}
  #related: Category {#418 ▶}
  #withDefault: null
}
May
30
5 months ago
Activity icon

Replied to Remove Entry Of Collection

I tried my original function with Typeahead and it is working. Seems to be an issue with easyAutocomplete.

Activity icon

Replied to Remove Entry Of Collection

Thank you already for your hints! dd() before return leads to good results. I still don't understand why it does not appear in the autocomplete. Without removing items from the collection, the autocomplete is working.

 Illuminate\Database\Eloquent\Collection Object
(
    [items:protected] => Array
        (
            [3] => App\Models\Category Object
                (
                    [parent:protected] => parent_id
                    [fillable] => Array
                        (
                            [0] => en_name
                            [1] => de_name
                            [2] => parent_id
                        )

                    [connection:protected] => mysql
                    [table:protected] => 
                    [primaryKey:protected] => id
                    [keyType:protected] => int
                    [incrementing] => 1
                    [with:protected] => Array
                        (
                        )

                    [withCount:protected] => Array
                        (
                        )

                    [perPage:protected] => 15
                    [exists] => 1
                    [wasRecentlyCreated] => 
                    [attributes:protected] => Array
                        (
                            [id] => 6
                            [parent_id] => 3
                            [en_name] => Category 1
                            [de_name] => Kategorie 1
                            [slug] => category-1
                            [created_at] => 2019-04-26 10:56:22
                            [updated_at] => 2019-04-26 10:56:22
                        )


Activity icon

Started a new Conversation Remove Entry Of Collection

Hi,

I have a 3-level tree. The function should return json with only 3rd-level catgories for autocomplete field. Autocomplete has no results with $data->forget($key), but why? I tried the code without the return, just printing with dd() and the collection showed 3 items. If I do the same request with the following function i get no results.

I use easyAutocomplete for this.

 public function autocompleteSearch(Request $request)
    {
        $searchquery = $request->searchquery;
        $data = Category::where('parent_id','!=',0)
                          ->where('de_name','like','%'.$searchquery.'%')
                          ->get();
        
        foreach($data as $key => $cat) {
            $category = Category::find($cat->parent_id);
            if($category->parent_id == 0) {
                $data->forget($key);
            }
        }
        return response()->json($data);
    }
May
23
5 months ago
Activity icon

Replied to @php In Foreach

Yes, but why? And how can i solve this? My editor shows my $url as undefined variable, but why can i not access it there within the loop?

Activity icon

Started a new Conversation @php In Foreach

Hi, any idea why the $url-variable in between of @php is not working?

Exception: Trying to get property 'content' of non-object

               @foreach($position->url as $url)
                    @php
                        $content = $url->content;
                    @endphp
                @endforeach