mironmg

mironmg

Member Since 3 Years Ago

Experience Points
22,830
Total
Experience

2,170 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
177
Lessons
Completed
Best Reply Awards
7
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 5
22,830 XP
Oct
01
2 weeks ago
Activity icon

Started a new conversation Multilanguage Routing Prefix

Hi guys...so I have a problem that ate my last 2 hours and I still haven't figured it out. I'm starting to believe that it's impossible to achieve but still I decided to ask in here So I have a multilanguage website... for blog posts and others I am using Model<->ModelTranslation relationship to gather dynamic slugs and all. Now I also need dynamic slugs for the hardcoded pages so to speak... The routing for these looks like this

Route::group(
    [
        'prefix' => '{locale}', 
        'where' => ['locale' => '[a-zA-Z]{2}'],
        'middleware' => 'localization'
    ], function(){
    ...
        Route::get('/pricing', '[email protected]')->name('products');
    ...
     }
);

This results in The following routes:

site.com/en/pricing
site.com/fr/pricing
site.com/cn/pricing

But obviously this is not an ideal setup What I want to achieve is to gather the "locale" parameter passed in the prefix to assign a dynamic slug to that pricing string in order to have more user-friendly URLs

Creating databases is not a solution because the website is already in production and this is more of a "nice to have" feature rather than something crucial.

So if I manage to access that {locale} variable in the second part of the function it would be great because I could create a config file with different variations... and have something like

Route::get(config('routing')['services'][$lang], '[email protected]')->name('products');

Thanks a lot

Marian

Aug
04
2 months ago
Activity icon

Replied to Laravel Keyup Function Not Working

we need the html as well. What kind of element is #n_serie ?

Aug
02
2 months ago
Activity icon

Replied to Will Somebody PLEASE Explain API?

First of all, you shouldn't be embarrassed of anything you do. In this field everyone's constantly learning. I think of API like a "thing" that helps applications communicate with each other. Usually people associate these with some json/xml data involved but that doesn't have to be 100% true. You can think of packages as APIs if they help implementing a 3rd party service for example. Take Stripe, Paypal, etc... The easiest definition I can think of is a tool that helps transferring data between 2 applications.

Jul
20
2 months ago
Activity icon

Replied to How To Validate Multiple Different Fields Using Only One Request?

I'm not sure I understand exactly what you're trying to achieve but laravel has some built-in conditional validator rules like "required_if". Hope it helps. If not, maybe you can explain the issue in detail a little bit more.. https://laravel.com/docs/5.8/validation

Jul
17
3 months ago
Activity icon

Replied to Filtering Through An Array Inside An Foreach

If I understand correctly, you have 2 arrays with the same length: this.dataset and this.redirected. In that case you need to use indexes. something like

for (let i=0; i<this.dataset.length; i++) {
     this.dataset[i].label = this.redirected[i];
}
Jul
10
3 months ago
Activity icon

Replied to Problem With Validate Checkboxes And Inputs

As far as I recall the required_if accepts only 2 arguments. Can you try something like

 $request->validate([
            'data' => ['required', 'date', 'date_format:Y-m-d'],
            'method' => ['required', 'min:1'],
            'method1' => ['required_if:method,1', 'regex:/^[0-9]{2}/'],
            'method2' => ['required_if:method,2', 'regex:/^[0-9]{1}\/[0-9]{4}\/[0-9]{3}/']          
]);
Jul
04
3 months ago
Activity icon

Replied to Do You Like IViewUI

https://element.eleme.io/ I think these 2 are quite similar... both are nice and clean though. However... Am I the only one that has the feeling that something new needs to appear anytime soon? It seems that everything we have now is either based on material design or goodold bootstrap...

Activity icon

Replied to Create Or Attach

public function addTags($tags)
{
    $attributes = explode(',', $tags);

    foreach ($attributes as $name) {

        $tag = Tag::firstOrCreate(['name' => $name]) 

        $this->tags()->syncWithoutDetaching([$tag->id]);
   
    }

    return;

}

and you can also delete the searchByName method ... You can use the whereName for it

Tag::whereName($name)->first();
Jun
25
3 months ago
Activity icon

Replied to Validation Required_unless Not Working

The code should work. Maybe the error is somewhere else? you're not referencing the correct formrequest class in the controller?

Jun
20
3 months ago
Activity icon

Replied to Laravel

You have to be a little bit more specific...

Jun
07
4 months ago
Activity icon

Replied to Easy Laravel Pre-defined Auth System

@JOHNBRAUN - I think eventually that's what I'm gonna end-up doing. I was just hoping someone else did it before me and built it based on a vuejs library...

Activity icon

Replied to Easy Laravel Pre-defined Auth System

@JOHNBRAUN - @johnbraun thanks a lot but that's not really what I meant. that creates a very basic bootstrap-based auth module. That needs to be styled and it's 2019..so it also needs to act a bit like a SPA...send the data via axios, etc...

Activity icon

Started a new conversation Easy Laravel Pre-defined Auth System

Hi guys. As I am typing this I'm in the middle of creating/styling yet another authentication module for a new project. Every time I start a new project I waste ~ 1 day re-using some of my old register / login/ components..inputs..selectboxes..etc. Then redeclaring some methods from the RegistersUsers trait, new "registered" event and so on. I was wondering how do you approach this? Do you have a package that you use? Something clean that uses either tailwindcss (not very important though). I just realized I waste so much time doing the same things over and over again for new projects. I know there are plenty of vue libraries that one can use but honestly I don't really know which one to pick. Any idea is welcome... maybe we can help each other save some time with new projects by sharing different approaches. Have a good one!

May
10
5 months ago
Activity icon

Replied to Finding Out If A Table Is Empty

empty is for collections. You are checking a address that hasn't been stored in the database yet. And if you store it, it's an eloquent model, not a collection. Try something like this

public function addPostAddress(Request $request)
    {

        $user_id = Auth::user()->id;

        $address = new Address();

        $address->user_id = Auth::user()->id;
        $address->fill($this->getSafeAddressInput($request));
    
    $all_addresses = Address::all(); //get all addresses from the db table

        if(!empty($all_addresses )) //check if it's empty
        {
            echo "not empty";
            
        }else{
            echo "empty";
          
        }

        return redirect()->back();
    }
Apr
27
5 months ago
Activity icon

Replied to Method App\Http\Requests\xxxxxxxxxxxRequest::xxxxx Does Not Exist.

@IRANKHOSRAVI - First of all, you should learn some manners. People take some minutes from their time to help you. You can't demand answers. Second.. you are trying to associate a request with some categories. Which does not make any sense. Like @snapey said, you need to remove that line but you need to replace it with something else. You just created another problem... I'm assuming you want to associate categories with the product.

Activity icon

Started a new conversation Javascript Class Constructor Fail

Hi guys

I have a js class called Property that I am using in my vue templates and a constructor Basically when I load a page, I make an ajax request to server, get the info for that model, assign it to a js object that I am using aftewards in my webapp.

So this object has a constructor class. Everything works fine except for one field which is listing_type This value assigns false, always. If I force assign it to a random string it works. If I console.log the variable it works. but when I assign the variable it does not. any ideas? Example below

class Property {
    constructor(db_property) {
        for(let field in db_property){
            this[field] = db_property[field];
        //everything works fine but when field == listing_type it just assigns false instead of the string
        }
}

LE. Nevermind, I found the issue right after I posted. it was me using a '=' instead of a '==' later in that page. Unfortunately I can't delete the thread.

Apr
23
5 months ago
Activity icon

Replied to How Much Of Code Syntax You Guys Remember?

It's normal and natural... especially when you're working with multiple libraries/frameworks. As you spend more time with one framework ( eg Laravel ) you're gonna remember syntax easier for it but perhaps you're gonna have trouble remembering some "js" stuff. I still mess-up simple things like "else if" and "elseif" when I write both front-end and backend on the same project. Like @ftiersch said, don't worry about it. we're only humans after all

Apr
16
6 months ago
Activity icon

Replied to Error Using Composer To Install Bogardo/Mailgun And Php-http/guzzle6-adapter

Seems to me that nexmo needs versions 1.0 and 1.1 of php-http/guzzle6-adapter and you are trying to install version 2.0 Try installing a 1.1 version and see whether that works with your other packages

Apr
12
6 months ago
Activity icon

Replied to Treeview With ---

Relationship is differnet from schema. you already have the "parent_id" field for creating the relationship. Please refer to https://laravel.com/docs/5.8/eloquent-relationships and watch some "laravel from scratch" tutorials. May take some time now but it earns you a lot of time on the long run

Activity icon

Replied to Treeview With ---

You need a relationship between category and subcategory Then get all categories with their subcats

Pool::with('subcategories')->get();

and in view file iterate through everything

    @foreach($categories as $cat)
    <option>{{ $cat->name }} </option>
        @if($cat->subcategories->count())
            @foreach($cat->subcategories as $sc)
                <option>{{ $sc->name }} </option>
            @endforeach
        @endif
    @endforeach
Activity icon

Replied to Get All Through Pivot Table

in Plan.php you need to have a relationship

public function users()
{
    return $this->belongsToMany(User::class, 'subscriptions'); //second parameter is name of the subscriptions table
}

Then in plan model you can just call the ->users() method

Apr
10
6 months ago
Activity icon

Replied to How/where To Adapt Email Verification?

@GEERIZZLE - You can track down the listener for Registered event and see what it does, then replicate that in a controller by yourself and do it whenever you want

Apr
09
6 months ago
Activity icon

Started a new conversation Good RAM VPS

Hi guys. I am looking for an alternative to OVH CloudRam VPS on the market but I can't seem to find anything close to those prices. I really like OVH but although the specs are rather good, I've seen on several tests that their connectivity is not that great. For some instances they have response times over 2x higher than digitalocean. What VPS providers are you using?

Activity icon

Replied to How/where To Adapt Email Verification?

You need to edit the Registered event that is being triggered by the register()method within RegistersUsers trait file. Basically you can extract the register method in the RegistrationController and comment out that event.

Apr
08
6 months ago
Activity icon

Replied to My Server Is Not Loading The Latest Files.

maybe you had some compiled view files... try running view:clear as well when you clear the cache. This would most likely fix it

Apr
05
6 months ago
Activity icon

Replied to Send Email With Event/Listener, Or Job?

Event/Listener. User submits a post -> event has happened (postSubmitted) -> listener sends email

Think of job like something the app has to do for you without any input. like sending a "happy birthday" email. It needs to happen without an action on behalf of user's part. You just need to check daily and see who's birthday is that day.

Activity icon

Replied to Make Sure To Provide The "name" Option.

@HJORTUR17 - Did you try to import the replies component in the app.js file and it failed? It should work if you do it like that

Activity icon

Replied to Cannot Use A Scalar Value As An Array

@VANDAN - Like @ftiersch mentioned above, the approach is completely messed-up. You have to get a better grasp of what DB::table('table')->update() does. You can't use it in a loop. Also, you don't need to use DB where you can use eloquent...otherwise you're not taking advantage of laravel's features. I have explained in your other post how this should have been achieved.

Activity icon

Replied to Array To String Conversion

@vandan You can't just post your error and code in here and wait for people to build your project. Try learning something..try explaining what you wanna achieve. You have to appreciate replies and understand that people who reply here are taking a piece of their time to help..make their "task" easier...

$all_imports = Import::all();

foreach($all_imports as $import){
    $half = $import->Amount_Grand_Total / 2;
    $import->update(['Half_Amount' => $half]);
}

return Import::pluck('Half_Amount')->all();
Activity icon

Replied to Cannot Use A Scalar Value As An Array

I just tried to redo your code but then I realized I have no idea what you're trying to achieve... We need more info..maybe post the whole method ?

Activity icon

Replied to Make Sure To Provide The "name" Option.

I may be wrong here cause I usually don't use the templates in-line but don't you wanna declare the replies component inside the app.js file? Basically you're not using the component in the Thread file, you're using it in the master layout, which means it does not make much sense to import it in that file...

Activity icon

Replied to Re-use Section Code $.ajax With Jquery Validator

I hope I didn't mistunderstood this but can't you just have a method parameter? something like

$.validator.setDefaults( {
    submitHandler: function () {
        $.ajax({
            // method: "POST", 
            method: methodType, // where methodType is either 'PUT' or 'POST' and declared outside the function? 
            url: urlAction,
            data: $("#myform").serialize()
        })
            .done(function(data, textStatus, jqXHR){
                
            })
            .fail(function( jqXHR, textStatus, errorThrown){
               
               
            });
    }
} );
Activity icon

Replied to Insert Or Update With Increments

@TIMGAVIN - You can default clicks to 0. Once you create the database entry it's already been visited once so it makes more sense.

Apr
04
6 months ago
Activity icon

Replied to Insert Or Update With Increments

$search = Search::updateOrCreate(['term' => $request->username]);
$search->increment('clicks', 1);

Also I would extract this into the Search.php model file

public static function incrementOrCreateSearchTerm(Request $request)
{
    $term= self::updateOrCreate(['term' => $request->username]);
    $term->increment('clicks', 1);
}

and in controller just do something like

Search::incrementOrCreateSearchTerm($request);
Activity icon

Replied to Laravel, Vue.js And Checkboxes: How To Check Only One?

Did you consider that maybe you don't need to run vue just for a checkbox? If you still want to stick to your idea, you should use v-model and v-if.

There are weeks of tutorials on this website. Subscribe and give them a shot.

Activity icon

Replied to Prevent Laravel From Removing Trailing Zeros

You need to change the database field to float. MySQL is "removing" it not laravel.

Apr
01
6 months ago
Activity icon

Replied to Returning String Data From A Relationship Only

Hi there

I suggest spending a bit more time on naming relationships. In the extension's model file add a method like this

public function getTypePathAttribute()
{
    return $this->hasType->path // This relationship should be renamed to ->type instead of ->hasType.
}

and then use it in code like this

$extension->type_path;

If you think you're gonna use it a lot in your code you can append it to the model using $appends https://laravel.com/docs/5.8/eloquent-serialization

protected $appends = ['type_path'];
Activity icon

Replied to Updating Multiple Many To Many Relationships

why not using the DB facade? May be easier.

DB::table('code_job')->where('job_id', $job_id)->update['approved',1]);
Activity icon

Replied to Array Sum

if the collections have the same Class(model) instance you can use eloquent's sum() method

$items = Stock::where('foo','bar')->get();
$total_kg = $items->sum('kg');
Activity icon

Replied to How To Catch A "Trying To Get Property Of Non-object Error" In Laravel

@ZASTER - Maybe try something like

$po_item = Item::where('foo','bar')->firstOrFail();
// It returns a 404 automatically if there's no item

If you don't want a 404 try something like

foreach($po_items as $item){
    if(is_null($item->vendor_company)){ 
        continue 
    }
    // do what you want with the vendor & vat_no.
}

A third option would be to query only the items that have a vendor company, assuming that there is a relationship involved in there. and judging by the code, there is.

$items = Item::whereHas('vendor_company')->with('vendor_company')->get();
//gathers all items that have a vendor company attached and also loads the vendor company in the results so you don't stress the database after that to load it with each iteration 
Mar
03
7 months ago
Activity icon

Replied to Cannot Save Avg Using UpdateOrCreate Method.

I think the problem is here

$rateUser = DB::table('rating')
                ->where('user_id', $id)
                                ->avg('rating')
                                ->first();

When you're getting the average you don't get a collection but a number. so first() doesn't make much sense. Also, you have some other issues in the code. By using updateOrCreate, you're assuming that the user may not exist in the database.. and you're trying to update their ID... that shouldn't be a fillable field.

$rate = new Rating();
        $rate->user_id = $id; // if the user_id may be non-existent this would end-up in an error.
        $rate->rating = $request->rating;
        $rate->save();

maybe try something like this

 public function changeRate(Request $request, $id){
    $user = User::find($id);
    if(is_null($user)){
        return abort(403);
    }

    $rate = new Rating();
    $rate->user_id = $user->id;
    $rate->rating = $request->rating;
    $rate->save();

    $userRating = DB::table('rating')->where('user_id', $user->id)->avg('rating');
    $user->update(['rate' => $userRating]);

    return $user;
}
Feb
28
7 months ago
Activity icon

Replied to Collapsable Sidebar

And how can we help?

Activity icon

Replied to How To Insert Multiple Records In Child Table

@akmahato ... Can you show us how $request looks like? I'm assuming the $request->input('sc_name') is an array ? If yes you should do something like this

for($i=0; $i<$n; $i++){
    $data=[
        'sc_name' => $sc_name[$i],
        'sc_desc' => $sc_desc[$i],
        'cat_id' => $category->id 
    ];
    AddSubCategory::create($data);
}

Also, You need to rename your category and subcategory models...why are they called AddCategory? They should be just Category and SubCategory.. it's very confusing.

Dec
16
10 months ago
Activity icon

Replied to Check If The User Own The File Before Show It

Do you store the image paths in the database? If not, maybe you should consider storing them under a /images/USER_ID/ folder. And check whether the user_id from the path matches the auth()->user()->id

Otherwise, if the images are stored in the DB and there's a relationship between the image & user, add a policy.

Activity icon

Replied to Submitting Post Request From Vue Throwing MethodNotAllowedException

Check web.php (route file) and confirm whether /login is in fact a "post" route. That message is usually displayed when you're using the wrong method. (eg. "POST" instead of "PUT")

Jul
17
1 year ago
Activity icon

Replied to Custom Artisan Command

@36864, it doesn't even dump anything if I put a test dump the first line within handle()...

Later Edit:

Nevermind, I fixed it. It was the queue_driver within .env file. When I changed the drivers I switched everything to 'redis' and QUEUE_DRIVER was in the same "batch" as the session, broadcast, etc..so it ended up with 'REDIS' value instead of 'SYNC'.

Thanks a lot!

Jul
16
1 year ago
Activity icon

Replied to Custom Artisan Command

I've checked all the logs. No errors..

Activity icon

Replied to Custom Artisan Command

Yep it returns a 0 but the Log::info() within the function are still not logged into the laravel.log file.

>>> Artisan::call(App\Console\Commands\SendDailyFollowupEmails::class)
=> 0
Activity icon

Replied to Custom Artisan Command

@36864 Yep I did. And yes it does work on dev env. also tried to clear the cache, artisan down/up, aritsan clear-compiled ...

Activity icon

Started a new conversation Custom Artisan Command

Hi guys... I have a small issue which made me pull my hair today so although I'm pretty sure it's just a basic thing I'm missing, I simply can't find it. I have a custom artisan command. It's registered, listed in artisan:list, works on localhost. Once I run it on production server it doesn't show any errors but it doesn't process any of the handle() function either because I have some Log::info() events in there to keep track of the actions and nothing shows up in laravel.log file. Anyone who had this issue before? Any idea what could it be? Other artisan commands are working ok on production server. Thanks