nekooee

nekooee

Member Since 6 Months Ago

Experience Points
220
Total
Experience

4,780 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
0
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 1
220 XP
Oct
11
1 week ago
Oct
10
1 week ago
Activity icon

Started a new Conversation How To Define A Convenient Shortcut For Accessing Distant Relations, Between “OneToMany” And “manyToMany Polymorphic”?

I have three models: "Article", "ArticleTranslation", Tag".

Article translations in different languages are stored in the ArticleTranslation.

The "Article" model has a one-to-many relationship with the "ArticleTranslation" model and the "ArticleTranslation" model has a many-to-many polymorphic relationship with the "Tag" model. I need to define a convenient shortcut to easily gather all article tags for a given article and I need to define a convenient shortcut to easily gather all the articles that have the given tag.

Relations

for translate article I use laravel-translatable package.

tables of this relationships: articles:

id - integer
article_translations:
id - integer
article_id - integer
locale - string
title - string
slug - string
tags:
id - integer
slug - string
taggables:
tag_id - integer
taggable_id - integer
taggable_type - string

Article Model:

class Article extends Model
{
    use Translatable;
    public $translatedAttributes = ['title', 'slug', 'description', 'body'];
}

ArticleTranslation Model:

class ArticleTranslation extends Model
{
    use Sluggable;
    public $timestamps = false;
    protected $fillable = ['title', 'slug', 'description', 'body'];

    public function sluggable()
    {
        return [
            'slug' => [
                'source' => 'title',
            ],
        ];
    }
   
    public function tags()
    {
        return $this->morphToMany(Tag::class, 'taggable');
    }
}

Tag Model:

lass Tag extends Model
{
    use Sluggable;
    protected $fillable = ['name'];
    public function sluggable()
    {
        return [
            'slug' => [
                'source' => 'name',
            ],
        ];
    }

    public function articleTranslate()
    {
        return $this->morphedByMany(ArticleTranslation::class, 'taggable');
    }
}
Sep
28
3 weeks ago
Sep
21
4 weeks ago
Activity icon

Replied to How To Check Titles To Be Unique In Its Locale And In Its Category?

@snapey no no, On the front there are several inputs for the title. like this:


 <div v-if="languages.length > 0" v-for="lang in languages" v-bind:key="lang.locale">
<input type="text" v-model="formContent.title[lang.locale]" >
</div>

after submitting this form server get this request:

array:3 [
  "title" => array:3 [
    "fa" => "دسته جدید"
    "en" => "new category"
    "ar" => "فئة جديدة"
  ]
  "status" => true
  "parent_id" => 2
]

titles to be unique in its locale. (per input one locale)

Activity icon

Replied to How To Check Titles To Be Unique In Its Locale And In Its Category?

thanks @snapey If I use Rule, it checks in all locale, because in my code I use 'title.*' and the language fields are dynamic. But I need titles to be unique in its locale. If I use "where", how can I select locale for each title?

for sample in this code only check 'en' locale for all language!

  $request->validate([
            'title.*' => ['required', 
Rule::unique('article_category_translations')->where('locale', 'en'),
        ]
Sep
20
4 weeks ago
Activity icon

Started a new Conversation How To Check Titles To Be Unique In Its Locale And In Its Category?

I have a category table that relates to itself for nested. And it has a relation with the translations table (article_category_translations). sample ajax request has:

array:3 [
  "title" => array:3 [
    "fa" => "دسته جدید"
    "en" => "new category"
    "ar" => "فئة جديدة"
  ]
  "status" => true
  "parent_id" => 2
]

I use this code for validation now:

$request->validate([
            'title.*' => ['max:30', 'required', 'unique:article_category_translations,title']
        ], [
            'title.*.max' => 'Title may not exceed 30 characters.',
            'title.*.required' => 'title required',
            'title.*.unique' => 'Title cannot be a duplicate.',
        ]);

This code checks titles to be unique in all categories and all languages. But I need titles to be unique in its locale and in its category. translate table (article_category_translations)

May
28
4 months ago
Activity icon

Replied to How To Write My Own Code For Each Field Validation?

@NOMGUY - in this way you only return message, But I do not want to return a message. and I need to insert error message in my object. in front I used vue. and this object bind to form. if each field have error in object, Easily show it. On the other hand, the number of fields is dynamic and based on the number of languages that should be raised in the loop. Because we do not know how many fields we have! Also, if I use the star for the field name, it is not recognizable at the front which error is for which field! Of course, I might do something else than return an error in the object. So, I need to be able to execute the code for each error, except for returning a message.

example:

{  
   "id":1,
   "mediaFullName":"10032-simple-business-card-moc.jpg",
   "mediaType":"image/jpeg",
   "mediaUrl":"/storage/2019/05/10032-simple-business-card-moc.jpg",
   "user":{  
      "id":1,
      "name":"Armin Nekooee"
   },
   "translations":[  
      {  
         "id":1,
         "media_id":1,
         "locale":"en",
         "mediaTitle":"",
         "mediaAlT":"",
         "errors":{  
            "mediaTitle":{  
               "0":"Title is Required",
               "1":"The number of characters allowed is 32 characters."
            }
         },
            "mediaAlt":{  
               "0":"Alt is Required",
               "1":"The number of characters allowed is 32 characters."
            }
         }
      }     
   ]
}
if ($validator->fails()) {
     $returnedFormContent['translations'][$key]['errors']['mediaTitle'][$i] = 'The number of characters allowed is 32 characters.';
     $errors = true;
  }

 if ($errors) {
            return response()->json([
                'success' => false,
                'returnedFormContent' => $returnedFormContent,
            ], 400);
        }

if I simple return custom message in front I can't find each error for whats feild and language.

Activity icon

Replied to How To Write My Own Code For Each Field Validation?

Does anybody can help me?

May
27
4 months ago
Activity icon

Started a new Conversation How To Write My Own Code For Each Field Validation?

my field name is dynamic and for each language, the fields are repeated with a suffix. I need to insert a value into custom my code for any field if validation failed ! for example:

 foreach ($languages as $key=>$language) {
         $validator = Validator::make($request->all(), [
                       'somthing1'  => 'required'
                    ]);
                    if ($validator->fails()) {
                      //my own code 1
                    }

  $validator = Validator::make($request->all(), [
                     $validator = Validator::make($request->all(), [
                       'somthing1'  => 'max:32'
                    ]);
                    if ($validator->fails()) {
                      //my own code 2
                    }
}


  $validator = Validator::make($request->all(), [
                       $validator = Validator::make($request->all(), [
                       'somthing2'  => 'required'
                    ]);
                    if ($validator->fails()) {
                      //my own code 3
                    }
}

this way work fine but the validation are repeated many times!! How can this code be optimized?

Apr
05
6 months ago
Activity icon

Replied to How Do I Use Vue Router And Normal Laravel Route Together

@topvillas I used this Route for all: Route::get('/{any?}', '[email protected]')->where('any', '.*');

But with this route, I can not do get userslist, updates, store, and delete operations. So I had to write another route before this route:

Route::resource('/users', 'UserController');
Route::resource('/articles', 'ArticleController');
Route::get('/{any?}', '[email protected]')->where('any', '.*');

Is this the right way? Or another solution?