mkbat

mkbat

Member Since 6 Months Ago

Houston

Experience Points
16,620
Total
Experience

3,380 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
135
Lessons
Completed
Best Reply Awards
5
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 4
16,620 XP
Apr
26
5 months ago
Activity icon

Replied to Laravel Automatically Number Formatting Decimal Column

@KAYLAKAZE-FE - That is weird. Do you have any Mutator on you Transaction model? something like

public function getPromotionalCreditAttribute($value)
{
    # your mutation
}

Let me know, this is getting interesting.

Activity icon

Replied to Laravel Automatically Number Formatting Decimal Column

@KAYLAKAZE-FE - Is in your model this field set to decimal(10,2)? I work with this type of data and never got a problem like this.You can always cast the value

$c->promotional_credit = (float) "1,500.00"

and even set the format if you need it

$c->promotional_credit = number_format((float) "1,500.00", 2)

https://www.php.net/manual/en/function.number-format.php

Apr
25
5 months ago
Activity icon

Replied to Search Function Laravel 5.8 Add Detail To Search Logic

Never have implemented this but I have heard about this a lot. Basically what you need is a "word similarity check algorithm" levenshtein(), similar_text(), soundex(), metaphone() or somethig similar. There is even implementations of "levenshtein" as MySQL function (https://www.lucidar.me/en/web-dev/levenshtein-distance-in-mysql/).

I would be very insterested to hear other opinions/recomendations about this.

Activity icon

Replied to Scheduling SQL Backups With Laravel Outside Storage Path

I agree with @snapey. I have done this using Laravel-backup

https://docs.spatie.be/laravel-backup/v4/introduction

and Drive on linux

https://medium.com/the-sysadmin/back-up-your-google-drive-files-from-linux-fcb68b234607

To upload the result zip file to Google Drive. You will need to setup two cron jobs.

  1. On laravel to backup your project and DB
  2. On your VPS (as a script) to upload to Google Drive the result laravel-backup zip file.
Activity icon

Replied to "SQLSTATE[23000]: Integrity Constraint Violation: 1452 Cannot Add Or Update A Child Row

You are changing an existent field. You need to add change(). Without this, your migration is adding a new field that already exists.

public function up()
    {
        Schema::table('data_text', function (Blueprint $table) {
            $table->foreign('chapter')->references('id')->on('module_data')->onDelete('cascade')->change();
        });

    }
Activity icon

Replied to Laravel Automatically Number Formatting Decimal Column

Let me understand. You are assigning 1500 and the value shows 1,500.00. For me this looks good.

Your format is decimal(10,2) 1500 would be [1,500].[00] as your value shows. Now you are saving the value and you get [1].[00], this is more decimal(1,2). I will recommend you to check your migrations to see if by mistake you used decimal(1,2) instead decimal(10,2)

Activity icon

Replied to Where Are You All From?

Houston, TX. US

Activity icon

Replied to Retrieve Data With Eloquent Relationships

This 'departement_id' => Faculty::find($facultyId)->departements()->where('name', $request['departementName'])->get() will return a collection an not an object or a value.

You should do

'departement' => Faculty::find($facultyId)->departements()->where('name', $request['departementName'])->firstOrFail(); // You can use first() but you need to check for null returns if nothing is found.

$department_id = $department->id;
Apr
24
5 months ago
Activity icon

Replied to Missing Argument 2 For App\Http\Controllers\PaieController::B_paie()

Your URL should looks in this way

http://<yourserver>/paie/8

Where 8 is the ID that you want to use. Are you passing the ID on the URL?

To be sure add dd($id) at the beginning of your method before salaries::findOrFail($id); , this will dump the value of $id.

Apr
23
5 months ago
Activity icon

Replied to Migrations: Adding Foreign_key When Table Is Yet To Be Created?

You can add a new migration to change these columns.

php artisan make:migration update_foreign_key --table=conversations_table

Schema::table('conversations_table', function (Blueprint $table) {
    
    // Updating relationships
    $table->foreign('last_message_id')->references('id')->on('messages')->onDelete('cascade')->change();
});

Run php artisan migarte

Activity icon

Replied to Multiple Polymorphic Relationship On One Model

@OLIVERBUSK - As I told you

Your problem is related with the “default values” on the columns “typeable_type” and “fieldable_type”. This means that those values can not be null. You must insert a value when creating the record for these columns.

This was an option if your fields were not mandatory

If “fieldable_type” and “typeable_type” are not mandatory for you app/DB you could add to your migration ->nullable() in the lines that create these columns.

Glad you fixed the problem.

Activity icon

Replied to Missing Argument 2 For App\Http\Controllers\PaieController::B_paie()

@MOUZAK - That is the return of salaries::findOrFail($id). The given $id is not valid. Check you DB and be sure you are passing a valid ID.

Apr
22
5 months ago
Activity icon

Replied to Storing Issue

Check ./storage/logs/laravel.logs to get details about the error. Also I think you need to add the proper headers to axios to post/put/delete including token/bearer and the expected type response.

Activity icon

Replied to Multiple Polymorphic Relationship On One Model

Your problem is related with the "default values" on the columns "typeable_type" and "fieldable_type". This means that those values can not be null. You must insert a value when creating the record for these columns. If "fieldable_type" and "typeable_type" are not mandatory for you app/DB you could add to your migration ->nullable() in the lines that create these columns.

Activity icon

Replied to Missing Argument 2 For App\Http\Controllers\PaieController::B_paie()

In your controller function you have two parameters. $request that is passed by the system and $id that is passed on the URL

public function B_paie( Request $request, $id) // Check you have $id here
{
    // your code
}

The problem is your Route is not including this last parameter "$id".

You should fix your route

Route::get('/paie/{id}','[email protected]_paie')->name('paie');

Then pass the "id" value on the call.

Activity icon

Replied to How To Add A Foreign Key To A Table After Migration Done Laravel

@SAFEMOOD - To create a foreign key relationship you need to be sure that the column on the reference is using "unsignedInteger" as type. Another thing that you need to know is that if you already ran a migration the only way to reverse it is running "rollback" command or editing the migration table on your DB. Migrations need be planned and heavenly tested on development environment.

php artisan make:migration add_foreign_key --table=products

Add Column

Schema::table('products', function (Blueprint $table) {

    // To Create column
    $table->unsignedInteger('product_category_id')->nullable()->references('id')->on('categories');
});

Updating Column

Schema::table('products', function (Blueprint $table) {
   
    // Change to UnsignedInteger
    $table->unsignedInteger('product_category_id')->change();
    
    // Updating relationships
    $table->foreign('product_category_id')->references('id')->on('categories')->change();
});

This changes will not remove any data from your DB. But anyways TEST IT before do anything on your production DB. Let me know if you have any questions.

Apr
19
5 months ago
Activity icon

Replied to Trouble With Defining Relationships

Great that you solved it!

Apr
18
5 months ago
Activity icon

Replied to How Do I Output A JSON Variable?

From where are you getting this data? It's a eloquent query result? this does not looks to be in JSON format. Looks more like echoing "dd()" result.

Activity icon

Replied to Trouble With Defining Relationships

@TIMGAVIN - From where is coming the "tag" column? Can I see the original eloquent query?

Activity icon

Replied to Trouble With Defining Relationships

OK I think I understand. You want Posts ordered by creation date (DESC) with tags.

Post::with('tags')->orderBy('created_at', 'desc')->get();

Activity icon

Replied to Trouble With Defining Relationships

What do you want to get?

Activity icon

Replied to How To Sort By A Related Table's Column?

Try

$users = User::with('status')
        ->join('status', 'status.id', '=', 'users.status_id')
        ->orderBy('status.description')
        ->get();

https://stackoverflow.com/questions/18143061/laravel-orderby-on-a-relationship

Let me know if this or any variation of this works. I can't test this right now.

Activity icon

Replied to Trouble With Defining Relationships

You are using a pivot table to connect your Posts and Tags tables.

"posts" table ---> "tags_posts" table (pivot) <--- "tags" table

Post Model

public function tags()
{
    return $this->belongsToMany('App\Tag', 'tags_posts');
}

Tag Model

public function posts()
{
    return $this->belongsToMany('App\Post', 'tags_posts');
}

You should be able to access to ordered by name "tags" from a "post" object in this way

$tags = Post::find(1)->tags()->orderBy('name')->get();

To access to ordered by created date "posts" from a "tag" object

$posts = Tag::find(1)->posts()->orderBy('created_at')->get();

More info : Laravel Many to Many Relationship

Activity icon

Replied to Attaching Many To Many Relations While Still Binding To Created Event

@CHRISPAGE1 - You are right, you should create your own event in this case.

Apr
17
6 months ago
Activity icon

Replied to Get All Through Pivot Table

@ZFDEVELOPER - I did some modifications to make this work properly.

Activity icon

Replied to Attaching Many To Many Relations While Still Binding To Created Event

A solution could be make a local scope "create" method in the Order model that can be used like this.

$order = Order::makeOrder($request->validated(), [1,2,3,4...,n]);

public function scopeMakeOrder($query, $order, $products)
{
    $order = $query->create($order);
    $order->products()->attach($products);
    
    return $order;
}

You must to have an already created Order to be able to attach any (already created) product. Do you can change the Order Created listeners to makeOrder?

Activity icon

Replied to How To Create 3 Array Marge?

I will assume that you are using API resources. But you need to provide details about the eloquent query that you are using. I will recommend instead put all the data as an array, create some json response that is self explanatory.

{
    "users":[{<user>},{<user>}],
    "songs":[{<song>,{<song>}}],
    "albums":[{<album>},{<album>}]
}

This can be done using the data from the eloquent query and API resources.

Activity icon

Replied to Get All Through Pivot Table

belongsToMany relationship does the job. Creating a pivot table you don't need to add anything to the user table.

Plans Table id | name | price, User Table id | username | email | ... | password

Plan Model

public function users()
{
    return $this->belongsToMany('App\User');
}

User Model

public function plan()
{
    return $this->belongsToMany('App\Plan');
}

Getting users from a specific plan. Plan Model

public function scopeGetUsers($query, string $plan_name)
{
    $plan = $query->ofName($plan_name)->first();
    if($plan)
    {
        return $plan->users;
    }
}

Then you can use it in this way.

$plan_users = Plan::getUsers('vip');

Apr
11
6 months ago
Activity icon

Replied to Get All Through Pivot Table

You should be able to call Plan::ofName('vip')->users; without any problem if you have a Plan belongsToMany User relationship.

Plan Model

public function users()
{
    return $this->belongsToMany('App\User');
}