priverop

priverop

Member Since 1 Year Ago

Experience Points
180
Total
Experience

4,820 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
180 XP
Mar
20
1 year ago
Activity icon

Replied to Delete A Row WITHOUT Cascade

The app is way bigger but in this relationship there are just this key...

I can't understand why it deletes the "prespuesto"!

If I delete it via PHPMYADMIN it works fine (the presupuesto is still there), but from Laravel it deletes the presupuesto.

EDIT: I just found the issue. In my AJAX request I wasn't getting the URL:

var form_action = $(element).next().val();
  console.log(form_action); // THIS WAS EMPTY
  $.ajax({
      dataType: 'json',
      type: 'DELETE',
      url: form_action
  }).done(function(data){
      location.reload();
  });

So it seems like the ajax was requesting a DELETE in the current url of the app (presupuesto/1), and it deletes the presupuesto and the part.

Thanks!!!

@gregrobson

Activity icon

Replied to Delete A Row WITHOUT Cascade

@gregrobson Thanks!

But what I want is DELETE PART and keep my Presupuesto.

I don't want to delete a Presupuesto.

And right now if I delete a Part (with onDelete(cascade)) it deletes the Presupuesto!! Shouldn't be like that

Mar
19
1 year ago
Activity icon

Started a new conversation Delete A Row WITHOUT Cascade

Hello,

I have a simple one to many relationships between Part and Presupuesto. A Presupuesto can have many Parts.

When I deleted a Part I also got the Presupuesto deleted, which I don't want. I removed the ->onDelete('cascade') but I have a Integrity constraint violation:

 local.ERROR: SQLSTATE[23000]: Integrity constraint violation: 1451 Cannot delete or update a parent row: a foreign key constraint fails (`bbdd`.`parts`, CONSTRAINT `parts_presupuesto_id_foreign` FOREIGN KEY (`presupuesto_id`) REFERENCES `presupuestos` (`id`)) (SQL: delete from `presupuestos` where `id` = 2) {"exception":"[object] (Illuminate\Database\QueryException(code: 23000): SQLSTATE[23000]: Integrity constraint violation: 1451 Cannot delete or update a parent row: a foreign key constraint fails (`bbdd`.`parts`, CONSTRAINT `parts_presupuesto_id_foreign` FOREIGN KEY (`presupuesto_id`) REFERENCES `presupuestos` (`id`)) (SQL: delete from `presupuestos` where `id` = 2) at /Applications/XAMPP/xamppfiles/htdocs/modifase-v2/vendor/laravel/framework/src/Illuminate/Database/Connection.php:664, PDOException(code: 23000): SQLSTATE[23000]: Integrity constraint violation: 1451 Cannot delete or update a parent row: a foreign key constraint fails (`bbdd`.`parts`, CONSTRAINT `parts_presupuesto_id_foreign` FOREIGN KEY (`presupuesto_id`) REFERENCES `presupuestos` (`id`)) at /.../vendor/laravel/framework/src/Illuminate/Database/Connection.php:483)

PART MIGRATION

public function up()
    {
        Schema::create('parts', function (Blueprint $table) {
            $table->increments('id')->unsigned()->unique();
            $table->string('name');
            $table->integer('presupuesto_id')->unsigned();
            $table->foreign('presupuesto_id')->references('id')->on('presupuestos');
            $table->timestamps();
        });
    }

PART CONTROLLER

public function destroy($id)
    {
      
      $part = Part::find($id)->delete();

      return response()->json($part);
    }

PART MODEL

public function presupuesto(){
    return $this->belongsTo('App\Presupuesto');
  }
protected $fillable = [

        'name', 'presupuesto_id'

    ];

What should I do?

Thanks!

EDIT: I just found the issue. In my AJAX request I wasn't getting the URL:

var form_action = $(element).next().val();
  console.log(form_action); // THIS WAS EMPTY
  $.ajax({
      dataType: 'json',
      type: 'DELETE',
      url: form_action
  }).done(function(data){
      location.reload();
  });

So it seems like the ajax was requesting a DELETE in the current url of the app (presupuesto/1), and it deletes the presupuesto and the part.

Mar
09
1 year ago
Activity icon

Replied to Get Property From Pivot Table Extra Attribute

I just got it:

public function materials(){
    return $this->belongsToMany('App\Material', 'material_part')
                ->withPivot('part_id', 'provider_id')
                ->join('providers', 'material_part.provider_id', '=', 'providers.id')
                ->select('providers.name as pivot_providers_name', 'materials.*');

                //SELECT * FROM `material_part` INNER JOIN providers ON material_part.provider_id = providers.id
  }
Activity icon

Started a new conversation Get Property From Pivot Table Extra Attribute

I have a many-to-many relationship between Part and Material models. It's working perfectly with a pivot table.

Now I just added another column to the pivot table 'provider_id', so when I do:

@foreach($parts as $key => $value)
 @foreach($value->materials as $mkey => $mvalue)
  {{ $mvalue->provider_id }}
 @endforeach
@endforeach

I get the provider ID, thats ok. But I want to get it's name instead. Something like $mvalue->provider->name. How can I do it?

Here are my pivot table migration:

Schema::create('material_part', function (Blueprint $table) {

    $table->integer('part_id')->unsigned();
    $table->foreign('part_id')->references('id')
        ->on('parts')->onDelete('cascade');

    $table->integer('material_id')->unsigned();
    $table->foreign('material_id')->references('id')
        ->on('materials')->onDelete('cascade');

    $table->integer('provider_id')->unsigned();
    $table->foreign('provider_id')->references('id')
        ->on('providers')->onDelete('cascade');

    $table->timestamps();
  });

Part Model:

class Part extends Model
{
  public function materiales(){
   return $this->belongsToMany('App\Material', 'material_part')->withPivot('part_id', 'provider_id');
  }
}

I also have the same relationship in Material model, but nothing in Provider model.

Thanks!