priverop

priverop

Member Since 9 Months Ago

Experience Points 180
Experience
Level
Lessons Completed 0
Lessons
Completed
Best Reply Awards 0
Best Answer
Awards
  • Start Your Engines Achievement

    Start Your Engines

    Earned once you have completed your first Laracasts lesson.

  • First Thousand Achievement

    First Thousand

    Earned once you have earned your first 1000 experience points.

  • One Year Member Achievement

    One Year Member

    Earned when you have been with Laracasts for 1 year.

  • Two Year Member Achievement

    Two Year Member

    Earned when you have been with Laracasts for 2 years.

  • Three Year Member Achievement

    Three Year Member

    Earned when you have been with Laracasts for 3 years.

  • Four Year Member Achievement

    Four Year Member

    Earned when you have been with Laracasts for 4 years.

  • Five Year Member Achievement

    Five Year Member

    Earned when you have been with Laracasts for 5 years.

  • School In Session Achievement

    School In Session

    Earned when at least one Laracasts series has been fully completed.

  • Welcome To The Community Achievement

    Welcome To The Community

    Earned after your first post on the Laracasts forum.

  • Full Time Learner Achievement

    Full Time Learner

    Earned once 100 Laracasts lessons have been completed.

  • Pay It Forward Achievement

    Pay It Forward

    Earned once you receive your first "Best Reply" award on the Laracasts forum.

  • Subscriber Achievement

    Subscriber

    Earned if you are a paying Laracasts subscriber.

  • Lifer Achievement

    Lifer

    Earned if you have a lifetime subscription to Laracasts.

  • Laracasts Evangelist Achievement

    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 Achievement

    Chatty Cathy

    Earned once you have achieved 500 forum replies.

  • Laracasts Veteran Achievement

    Laracasts Veteran

    Earned once your experience points passes 100,000.

  • Ten Thousand Strong Achievement

    Ten Thousand Strong

    Earned once your experience points hits 10,000.

  • Laracasts Master Achievement

    Laracasts Master

    Earned once 1000 Laracasts lessons have been completed.

  • Laracasts Tutor Achievement

    Laracasts Tutor

    Earned once your "Best Reply" award count is 100 or more.

  • Laracasts Sensei Achievement

    Laracasts Sensei

    Earned once your experience points passes 1 million.

  • Top 50 Achievement

    Top 50

    Earned once your experience points ranks in the top 50 of all Laracasts users.

20 Mar
8 months ago

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

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

19 Mar
9 months ago

priverop 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!
09 Mar
9 months ago

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

priverop left a reply on Get Property From Pivot Table Extra Attribute

@martinbean what do you mean?

I'm trying with this (with no success yet):

public function materiales(){
    return $this->belongsToMany('App\Material', 'material_part')
                ->withPivot('part_id', 'provider_id')
                ->join('providers', 'material_part.provider_id', '=', 'providers.id');

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

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