Dronax

Dronax

Member Since 1 Year Ago

Experience Points 13,120
Experience Level 3

1,880 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 94
Lessons
Completed
Best Reply Awards 0
Best Reply
Awards
  • Start Your Engines Achievement

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • First Thousand Achievement

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • One Year Member Achievement

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • Two Year Member Achievement

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • Three Year Member Achievement

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • Four Year Member Achievement

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • Five Year Member Achievement

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • School In Session Achievement

    School In Session

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

  • Welcome To The Community Achievement

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • Full Time Learner Achievement

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • Pay It Forward Achievement

    Pay It Forward

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

  • Subscriber Achievement

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • Lifer Achievement

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • Laracasts Evangelist Achievement

    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 Achievement

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • Laracasts Veteran Achievement

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • Ten Thousand Strong Achievement

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • Laracasts Master Achievement

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • Laracasts Tutor Achievement

    Laracasts Tutor

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

  • Laracasts Sensei Achievement

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • Top 50 Achievement

    Top 50

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

05 Apr
2 months ago

Dronax left a reply on Identify User Of Comment And Send Notification Laravel

I think that I need global function on models? Or 2 notifications?

04 Apr
2 months ago

Dronax started a new conversation Identify User Of Comment And Send Notification Laravel

I have a posts system. On my site users can post articles and post comments on every article. I want release: when any user (not author of post) comment post, I need send notification to author of post, that post him was commented by UserName.. I do it like this:

In CommentController I have a method for post comment on post:

public function postComment(Post $post, AddPostRequest $request)
{
    if ($request->parent_id !== null) {
        $parent = Comment::where('id', $request->parent_id)->first();
        $this->authorize('canComment', $parent);
    }

    $data = [
        'user_id' => Auth::check() ? Auth::user()->id : null,
        'post_id' => $post->id
    ];

    $comment = $post->createComment(array_merge($request->except('g-recaptcha-response'), $data));

    $post->owner->sendReviewNotification($review);

    return $review;
}

In my comment system I have nested comments. In model Post I have method createReview.

public function owner()
{
    return $this->belongsTo(User::class, 'user_id');
}

public function comments()
{
    return $this->hasMany(Comment::class);
}

public function createComment($data = [])
{
    $review = $this->comments()->create($data);

    return $review;
}

In model Comment I have:

public function post()
{
    return $this->belongsTo(Post::class);
}

public function user()
{
    return $this->belongsTo(User::class);
}

public function parent()
{
    return $this->belongsTo(static::class, 'id', 'parent_id');
}

public function children()
{
    return $this->hasMany(static::class, 'parent_id');
}

public function scopeActive($query)
{
    return $query->whereNotNull('user_id')->where('active', 1);
}

Now: when comment is created notifications is send to author of post, but when author can answer to comment of post him, then notification send again to him, but I need send notification to author of comment. How I can define this case? I don't need send always notifications to a author of post, I need notify and authors of comments, that comments them is answered by author of post.

03 Apr
2 months ago

Dronax started a new conversation Laravel Spatie/medialibrary AddToCollection Not Working

I have a post model and registered collection and conversions of images the post:

public function registerMediaCollections()
{
    $this->addMediaCollection('posts');
}

public function registerMediaConversions(Media $media = null)
{
    $this->addMediaConversion('banners')
        ->nonQueued();
    $this->addMediaConversion('covers')
        ->nonQueued();
}

When I save image in controller with:

public function store(AddEditPostRequest $request)
{
    $post = Post::create($request->except(['banner', 'cover']));
    if ($request->banner) {
        $filename = md5($request->banner) . $request->banner->getClientOriginalExtension();

        $post->addMediaFromRequest('banner')->usingFileName($filename)->toMediaCollection('shops');
    }

    if ($request->cover) {
        $filename = md5($request->cover) . $request->cover->getClientOriginalExtension();

        $post->addMediaFromRequest('cover')->usingFileName($filename)->toMediaCollection('shops');
    }

    return redirect()->route('posts.index', $post);
}

Medialibrary save images on incorrect path. I have storage folder. And he's not create new folder posts. Why? I get this structure of folder storage: enter image description here Folders: 1,2,3,5 and others.. this is folders of posts images.. How I can write this folders on one folder posts?

01 Apr
2 months ago

Dronax started a new conversation Replace Placeholder On View Page Laravel

I have a content of page:

{pages.advert}

And I have method show on PageController:

public function show(Page $page)
{

    if($page->body->contains('{$}')) { return view('$', compact('page'); } 

    return view('page.show', compact('page'));
}

I want replace placeholder on view name and return this view. Method contains does not work. Why? I get error: undefined method contains on string..

I need return view('pages.advert', compact('page')); dynamicly.

Dronax left a reply on Foreach Paginate Pages Laravel

@SNAPEY - please example

31 Mar
2 months ago

Dronax started a new conversation Foreach Paginate Pages Laravel

Hello. I have a code:

 $posts = Post::paginate(100);

How I can foreach pages of pagination and show results? I need in every file write a posts.

 foreach($posts as $page => $post) {
      //put on file current post with file name: file-post-$page.txt
 }

How I can do it?

27 Mar
2 months ago

Dronax started a new conversation Make Url Username With Symbol @

Hello. How I can do profile url with symbol @ how in laracasts?

I want get url: http://example.com/@Username and get user in controller with

public function profile(Request $request, User $user) {
    //do something...
}

How I can do it?

18 Mar
3 months ago

Dronax left a reply on Disable Email Notification Globally For User Laravel

@MARTINBEAN - What I need return, $user->email?

Dronax left a reply on Disable Email Notification Globally For User Laravel

@MARTINBEAN - Сan you please do a simple example?

Dronax left a reply on Disable Email Notification Globally For User Laravel

@MARTINBEAN - But if I want disable a other notification channel? How I can do it?

17 Mar
3 months ago

Dronax started a new conversation Disable Email Notification Globally For User Laravel

I have a setting:

setting('enable.userEmailNotifications', true);

How I can disable email notifications for user if:

setting('enable.userEmailNotifications') == false

I need in notification class edit method toEmail?

public function toEmail($notifiable) {
   if(!setting('enable.userEmailNotifications')) return;
}

But I don't think, that this is correctly.. Because in this cause I need in every notification add this check.

11 Mar
3 months ago

Dronax started a new conversation Bring Back Errors Images In Laravel 5.8

Hello. How I can bring back errors images in laravel 5.8 from laravel 5.7? Errors Images: 404, 500, 413 e.t.c..

Now in Laravel 5.8 I get static text of error.

28 Feb
3 months ago

Dronax left a reply on Laravel Job Check Site If Online

@SNAPEY - I need do monitor activity for sites in my database. How I can do it without queues ?

Dronax left a reply on Laravel Job Check Site If Online

@SNAPEY - I have page of post, there I show site status. How I can do it, with queues?

27 Feb
3 months ago

Dronax left a reply on Laravel Job Check Site If Online

@SNAPEY - How then is it better to do?

Dronax left a reply on Laravel Job Check Site If Online

@SNAPEY - I can with queues check it's status if online or not? If not, then I can do some actions..

This Code:

protected function schedule(Schedule $schedule)
{
     $schedule->call(function () {
        foreach(Post::all() as $post) {
    CheckIfOnline::dispatch($post);
}
})->hourly();
}

is Good?

Dronax left a reply on Laravel Job Check Site If Online

@SNAPEY - A lot of fake traffic for those sites - Yes. I need remove fake sites..

26 Feb
4 months ago

Dronax left a reply on Laravel Job Check Site If Online

@SNAPEY - I need display only if site is online :) And yes, I don't need to show user a dead link..

Dronax left a reply on Laravel Job Check Site If Online

@SNAPEY - You're right. How I can do this correctly? I need recheck every site if he's online, or maximum in a day..

25 Feb
4 months ago

Dronax left a reply on Laravel Job Check Site If Online

@RICARDO - /** * Define the application's command schedule. * * @param \Illuminate\Console\Scheduling\Schedule $schedule * @return void */ protected function schedule(Schedule $schedule) { $schedule->call(function () { foreach(Post::all() as $post) { CheckIfOnline::dispatch($post); } })->hourly(); }

I right?

Dronax left a reply on Laravel Job Check Site If Online

@RICARDO - Where I need do this:

foreach(Post::all() as $post) { CheckIfOnline::dispatch($post); }

in controller?

24 Feb
4 months ago

Dronax started a new conversation Laravel Job Check Site If Online

Hello. On every post I have url a website. I need get status and check every hour if this site is online. How I can do it with queues Laravel? I have a job CheckPostSite:

public function handle()
{
    $allposts = Post::all();

    foreach($allposts as $post) {
         if($this->checkOnline($post->site_url) {
              $post->website_online = true;
              $post->save();
         }
    }
}

private function checkOnline($domain) { $curlInit = curl_init($domain); curl_setopt($curlInit,CURLOPT_CONNECTTIMEOUT,10); curl_setopt($curlInit,CURLOPT_HEADER,true); curl_setopt($curlInit,CURLOPT_NOBODY,true); curl_setopt($curlInit,CURLOPT_RETURNTRANSFER,true);

    //get answer
    $response = curl_exec($curlInit);

    curl_close($curlInit);
    if ($response) return true;
    return false;
}

I'm doing everything right? Or not? I have 10000+ posts in database.

13 Feb
4 months ago

Dronax left a reply on Get Position In Rating By Scope

@REALRANDYALLEN - How then I can do? I need INNER JOIN? Or sub query? Can you please help?

Dronax left a reply on Get Position In Rating By Scope

@REALRANDYALLEN - Sorry, I need help now :) Now I need put on order a reviews_count, I have relation in shop model:

 protected $withCount = ['reviews']

 public function reviews() {
        return $this->hasMany(Review::class);
 }

In your method I try put a reviews_count:

public static function updateRanks()
{
    DB::statement("update shops set position = (SELECT FIND_IN_SET( CONCAT(points, '_', reviews_count, '_', created_at), (SELECT GROUP_CONCAT( CONCAT(points, '_', reviews_count, '_', created_at) ORDER BY points desc, reviews_count desc, created_at desc ) FROM (select * from shops) as shop_rankings)))");
}

But me get error:

SQLSTATE[42000]: Syntax error or access violation: 1583 Incorrect parameters in the call to native function 
'concat...

Can you please help?

Dronax left a reply on Get Position In Rating By Scope

Sorry, I need help now :) Now I need put on order a reviews_count, I have relation in shop model:

 protected $withCount = ['reviews']

 public function reviews() {
        return $this->hasMany(Review::class);
 }

In your method I try put a reviews_count:

public static function updateRanks()
{
    DB::statement("update shops set position = (SELECT FIND_IN_SET( CONCAT(points, '_', reviews_count, '_', created_at), (SELECT GROUP_CONCAT( CONCAT(points, '_', reviews_count, '_', created_at) ORDER BY points desc, reviews_count desc, created_at desc ) FROM (select * from shops) as shop_rankings)))");
}

But me get error:

SQLSTATE[42000]: Syntax error or access violation: 1583 Incorrect parameters in the call to native function 
'concat...

Can you please help?

12 Feb
4 months ago
11 Feb
4 months ago

Dronax left a reply on Use Accesor GetAttribute In Query Model Laravel

@MO7SIN - I try your method. I get error unknown column reviews..

Dronax started a new conversation Use Accesor GetAttribute In Query Model Laravel

I have model Post, and I have:

protected $appends = ['reviews_count'];

public static function boot()
{
    parent::boot();

    static::saved(function () {
        static::updateRanks();
    });
}

public function reviews() {
   return $this->hasMany(Review:class);
}

public static function updateRanks()
{
    DB::statement("UPDATE posts set `rank` = (SELECT FIND_IN_SET( CONCAT(points, '_', created_at), (SELECT GROUP_CONCAT( CONCAT(points, '_', created_at) ORDER BY points desc, created_at asc ) FROM (select * from posts) as posts_rankings)))");
}

public function getReviewsCountAttribute()
{
    return $this->reviews()->active()->count();
}

I need in CONCAT(points, '_', created_at) add a reviews_count and next do ORDER BY points desc, reviews_count desc, created_at asc. How I can do this? If I add, I get error: unknown column reviews_count...

10 Feb
4 months ago

Dronax started a new conversation Remove Key Cache Laravel By Pattern

Hello. How I can forget cache, if I known only one part of key? My key can be: post-page-1, post-page-2, post-page-3...

How I can forget these keys ?

I tried:

Cache::forget('post-*');

But this is not working..

I know, that I can use tags, but I use file driver for cache. And I need solution for file driver. Thanks.

Dronax started a new conversation Get URL Changed By Pushstate

When I change url by:

history.pushState(null, null, '#/' + $(this).attr('href').substring(1));

And when I want to change this pushstate with:

  function updateUrl() {
    history.pushState(null, null, `${location.href}/?page=` + this.page);
  }

And when I click to pagination buttons. I get link like this: http://example.com/foo/bar/#revs/?page=1/?page=2/?page3

<button onclick="updateUrl(1)">1</button>
<button onclick="updateUrl(2)">2</button>

But I need change only param page.

09 Feb
4 months ago

Dronax left a reply on Laravel Do Slug Correctly

@SNAPEY - Yea, but in controller?)

Dronax started a new conversation Laravel Do Slug Correctly

Hello. In my post model I have this:

public function getRouteKeyName()
{
    return 'slug';
}

When I go to page post my link is: http://example.com/post/there-a-slug

How I can do link like this: http://example.com/post/idofpost/there-a-slug

In my routes:

`Route::get('/post/{post}', '[email protected]')->name('showpost');

Dronax left a reply on Check If User Is Not Owner Of Post, And If User Owner Of Comment Parent In Custom Request

@TYKUS - I have nested comments on page post. In table comments I have parent_id. In model comment I have relation with post. I need prevent comment a comment if user is not owner of parent comment.

Dronax started a new conversation Preloader V-cloak Is Not Working

Hello. I have in css:

[v-cloak]::before { content: "loading…"; display: block; text-align: center; width: 300px; height: 600px; margin: 0 auto; font-size: 60px; }

When page loading, I don't get loading... Why? I get white background.. I need do preloader v-cloak, show on user, that page is loading..

Dronax started a new conversation Check If User Is Not Owner Of Post, And If User Owner Of Comment Parent In Custom Request

I have a custom request with authorize method:

public function authorize()
{
    return Auth::user() ? $this->post->user_id !== Auth::user()->id && ! $this->parent_id && $this->user_id == Auth::user()->id : true;
}

I need prevent adding comment: (if user is owner of post, if user not owner of comment parent). How I can do it? My condition is not work. I get 403..

In table comments I have: post_id, user_id, parent_id, body. In model comment and post I have relations.

Dronax started a new conversation Vuejs Can't Store Child Comment

I have a problem, I have component CommentsManager with:

        <div v-for="(comment, index) in comments" :key="comment.id">
            <comment @createdChild="addChildren" :data="comment" @deleted="remove(index)"></comment>
        </div>

I use mixin:

 export default {
  data() {
    return {
      items: [],
      children: [],
   }
},

methods: {
add(item) {
  this.items.unshift(item);

  this.$emit('added');
},

addChildren(children) {
  this.children.push(children);

  this.$emit('addedChildren');
},

remove(index) {
  this.items.splice(index, 1);

  this.$emit('removed');
},

removeChildren(children) {
  this.children.splice(children, 1);

  this.$emit('removedChildren');
},
}
} 

And I have a component child-comment in component Comment:

        <div v-for="(comment, index) in children" :key="comment.id">
          <child-comment :data="comment" @deleted="removeChildren(index)"></child-comment>
        </div>
       
        exports default {
             data() {
               return { children: [] } 
             } 
        }

When child comment is created, I call: this.$emit('createdChild', response.data);. Why @createdChild not working and not pass new data in children in Comment component? @removedChildren is working.. but @createdChild doesn't work.. Errors I don't get

08 Feb
4 months ago

Dronax started a new conversation Prevent Create A Record If Error In Observer Laravel

How I can block create a record on model if function give me error?

I have Observer:

public function created(Post $post)
{
    Auth::guest() ? $post->sendEmailNotification($post->guest_token) : '';
}

I need: if sendEmailNotification get a exception, then not create record. Now, if I get exception, post whatever creating..

07 Feb
4 months ago

Dronax left a reply on Belongs To Many Not Attaching Data Laravel

@TYKUS - Simply no record. $guest = data => ['guest_name' => value, 'guest_email' => value, 'guest_token' => value]; Yes, all columns can be nullable in pivot excepting: review_id.

Dronax started a new conversation Belongs To Many Not Attaching Data Laravel

I have two tables: reviews and guest_reviews. In table reviews I have columns: id, post_id, user_id, body,parent_id. In table reviews_guests (is pivot table) I have columns: review_id, guest_name, guest_email, guest_token.

In model review I have this relation pivot:

public function guest()
{
    return $this->belongsToMany(static::class, 'reviews_guests');
}

When I create review with guest, method attach not working:

public function createReview($data = [], $guest = [])
{
    if ($guest) {
        $review = $this->reviews()->create($data);
        $review->guest()->attach($guest);
        $review->save();

        return $review;
    } else {
        $review = $this->reviews()->create($data);
        return $review;
    }

}

Why attach not working? On array guest and data I have data. In table reviews review is created, but in reviews_guests - not.

Dronax started a new conversation Pass Variable In Message

Hello. I have rule:

<?php

namespace App\Rules;

use Illuminate\Contracts\Validation\Rule;

class Uppercase implements Rule
{
    /**
     * Determine if the validation rule passes.
     *
     * @param  string  $attribute
     * @param  mixed  $value
     * @return bool
     */
    public function passes($attribute, $value)
    {
        $err = $value == 24 ? now()->subDays(24) : '';
        return strtoupper($value) === $value;
    }

    /**
     * Get the validation error message.
     *
     * @return string
     */
    public function message()
    {
        return 'The :attribute must be uppercase. End expired: $err';
    }
}

I need pass $err variable on message method. How I can do this? I need display hours on expired data. Please help me resolve this problem.

Dronax left a reply on Display Validation And Custom Errors Laravel In Vuejs

@BORISU - this only working if I write a email on form comment, but if I user? I don't have field email, how then I can call this rule and check user_id?

Dronax left a reply on Display Validation And Custom Errors Laravel In Vuejs

@BORISU - See please code:

  $lastComment = $this->reviews()
        ->where('created_at', '>', now()->subHours(24))
        ->where('shop_id', $this->id)
        ->where('email', $data['email'])
        ->orWhere('user_id', $data['user_id'])
        ->latest()
        ->first(); 

    if ($lastComment) {
        return response()->json(['errors' => 'Please wait 24h'], 422);
    }

Dronax left a reply on Display Validation And Custom Errors Laravel In Vuejs

@BORISU - No. I check if last Comment exists in database, if yes, then I write error.

Dronax left a reply on Display Validation And Custom Errors Laravel In Vuejs

@BORISU - How then display errors of validation? :)

06 Feb
4 months ago

Dronax started a new conversation Filter Comments By Type Vuejs

I have a component form with select filter:

 <template>
     <div class="form-group">
                    <select name="" v-model="filterRev" @change="filterReviews(filterRev)" class="form-control" id="">
                      <option value="0">All comments</option>
                      <option value="1">Good Comments</option>
                      <option value="2">Standard Comments</option>
                      <option value="3">Badd comment</option>
                    </select>
     </div>
 </template>

 <script>
 export default {
     data() {
        filterRev: 0
     },
     methods: {
        filterReviews(type) {
            if(Number.isInteger(parseInt(type))) {
                 this.$emit('filter', type);
            }
        },
     }
 }
 </script>

On component comments I have this:

        <div @filter="..." v-for="(comment, index) in items" :key="comment.id">
            <comment :data="comment"></comment>
        </div>

How I can check comment.type with filter type? I need sort comments, when user select certain filter. In v-for I have comment.type.

Dronax left a reply on Display Validation And Custom Errors Laravel In Vuejs

@BORISU - On this:

return response()->json(['errors' => 'Please try after 24 hours..'], 422);

I get this result:

P l e a s e

t r y ...

Why?