mironmg

mironmg

Member Since 3 Years Ago

Experience Points 21,490
Experience Level 5

3,510 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 171
Lessons
Completed
Best Reply Awards 6
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.

10 Jul
5 days ago

mironmg left a reply on 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}/']          
]);
04 Jul
1 week ago

mironmg left a reply on 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...

mironmg left a reply on 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;

}
25 Jun
2 weeks ago

mironmg left a reply on 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?

20 Jun
3 weeks ago

mironmg left a reply on Laravel

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

07 Jun
1 month ago

mironmg left a reply on 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...

mironmg left a reply on 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...

mironmg 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!

20 May
1 month ago

mironmg left a reply on Csrf Token Mismatch

maybe a piece of code would help...

10 May
2 months ago

mironmg left a reply on 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();
    }
27 Apr
2 months ago

mironmg left a reply on Method App\Http\Requests\ProductRequest::categories 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.

mironmg 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
        }
}
23 Apr
2 months ago

mironmg left a reply on 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

16 Apr
2 months ago

mironmg left a reply on 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

12 Apr
3 months ago

mironmg left a reply on 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

mironmg left a reply on 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

mironmg left a reply on 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

10 Apr
3 months ago

mironmg left a reply on 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

09 Apr
3 months ago

mironmg 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?

mironmg left a reply on 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.

08 Apr
3 months ago

mironmg left a reply on 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

05 Apr
3 months ago

mironmg left a reply on Send Email With Event/Listener, Or Job?

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

mironmg left a reply on 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

mironmg left a reply on 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.

mironmg left a reply on 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();

mironmg left a reply on 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 ?

mironmg left a reply on 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...

mironmg left a reply on 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){
               
               
            });
    }
} );

mironmg left a reply on Insert Or Update With Increments

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

04 Apr
3 months ago

mironmg left a reply on 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);

mironmg left a reply on 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.

mironmg left a reply on Prevent Laravel From Removing Trailing Zeros

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

01 Apr
3 months ago

mironmg left a reply on 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'];

mironmg left a reply on Updating Multiple Many To Many Relationships

why not using the DB facade? May be easier.

mironmg left a reply on 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');

mironmg left a reply on 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 
03 Mar
4 months ago

mironmg left a reply on 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;
}
28 Feb
4 months ago

mironmg left a reply on Collapsable Sidebar

And how can we help?

mironmg left a reply on 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.

mironmg left a reply on "Argument 1 Passed To Illuminate\Database\Grammar::parameterize() Must Be Of The Type Array, Null Given, Called In E:\LaravelProject\metrofeedback_v1\vendor\laravel\framework\src\Illuminate\Database\Query\Grammars\Grammar.php On Line 853

So...there's some things wrong in there.

public function store(Request $request)
    {
        $input = $request->all();

        $category = new AddCategory();
        $category->c_date = $input['c_date'];
        $category->c_name = $input['c_name'];
        $category->c_desc = $input['c_desc'];
    // at this point you don't have a $category stored in the database. You just have an AddCategory model in memory, ready to be saved.

        $subcategory = new AddSubCategory();
        $subcategory->sc_name = $input['sc_name'];
        $subcategory->sc_desc = $input['sc_desc'];
        $subcategory->cat_id = $category->id; // here it is trying to get a non existent property of an object ( $category, not being saved, does not have an ID field yet). Hence it returns null. 
     
        $category->save($request->all()); // why? It should be just $category->save() and it should be before you declare a subcategory
        $category->subCategory()->save($subcategory); // this is wrong too. If you do this you don't need a "cat_id" field 
}

So try it like this

public function store(Request $request)
    {
        $input = $request->all();

        $category = new AddCategory();
        $category->c_date = $input['c_date'];
        $category->c_name = $input['c_name'];
        $category->c_desc = $input['c_desc'];
    $category->save();

        $subcategory = new AddSubCategory();
        $subcategory->sc_name = $input['sc_name'];
        $subcategory->sc_desc = $input['sc_desc'];
        $subcategory->cat_id = $category->id;
    $subcategory->save();
}
16 Dec
6 months ago

mironmg left a reply on 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.

mironmg left a reply on 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")

17 Jul
11 months ago

mironmg left a reply on Custom Artisan Command

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

16 Jul
11 months ago

mironmg left a reply on Custom Artisan Command

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

mironmg left a reply on 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

mironmg left a reply on 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 ...

mironmg 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

23 Jun
1 year ago

mironmg left a reply on Phone Number " UNIQUE " For Validation

I assume you're using validation when you get the data. https://laravel.com/docs/5.6/validation give this a good read...it helps a lot on long-term. Eg:

public function store(Request $request)
{
    $validatedData = $request->validate([
        'phone' => 'required|unique:users'
    ]);

}
17 May
1 year ago

mironmg left a reply on Which Laptop To Buy?

If you're not an apple fan just go with a windows laptop. Of course macbook owners will tell you the quality is good, the keyboard is awesome etc... Just think practical and bare in mind that most of the high-end windows laptops have a very good build quality and they're less expensive than macbooks these days, compared to 5 yrs ago when apple was more than just a brand. Since you're programming, you don`t need a 4k monitor, you don't need an awesome graphic card, some could argue that you're not even gonna use the laptop's keyboard either because you're gonna have a second monitor and a separate keyboard if you have a nice office setup. So these being said the offer is sooo much wider when it comes to windows devices...you have lenovo,asus,dell,hp. You can find an aluminium laptop with SSD+HDD, i7-8550u, 16GB of ram under $1200. The resell value probably would not be the same as for an apple but you could use a device like this for 3 yrs without feeling the need to change it. So assuming you're wasting 300$ in resell value compared to a macbook, how much money do you actually lose overall considering the macbook prices start at over $2.3k ?