sevmardi

sevmardi

Member Since 4 Years Ago

Experience Points
32,185
Total
Experience

2,815 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
350
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 7
32,185 XP
24 Jan
2 years ago

sevmardi left a reply on Add Null Values To The Raw Query

Someone has an idea, please?

sevmardi started a new conversation Add Null Values To The Raw Query

Hi

I've got the following working query.


            return  DB::table('plates')
         ->join('projects', 'plates.project_id', '=', 'projects.id')
        ->join('plate_types', 'plates.plate_type_id', '=', 'plate_types.id')
        ->join('equipment_status_codes', 'plates.equipment_status_code_id', '=', 'equipment_status_codes.id')
       
        ->select( DB::raw('IFNULL(projects.name, NULL) as Project'),  DB::raw('IFNULL(plate_types.name, NULL) as PlateType'), DB::raw('IFNULL(equipment_status_codes.name, NULL) as StatusCode'), DB::raw('IFNULL(count(*), NULL) as no_of_plates'))

       

        ->groupBy('plates.project_id', 'plates.plate_type_id', 'plates.equipment_status_code_id')
        ->get();

which basically returns this.

[
  {
    "Project": "Mose Kuvalis",
    "PlateType": "Ethel Bayer",
    "StatusCode": "Uriel Reynolds",
    "no_of_plates": 1
  },
  {
    "Project": "as",
    "PlateType": "as",
    "StatusCode": "te",
    "no_of_plates": 4
  },
  {
    "Project": "possq",
    "PlateType": "as",
    "StatusCode": "te",
    "no_of_plates": 1
  }
]

I am trying to add another layer of data to it by telling me how many are there without project or status codes. Chaining this to the above array would be great.

so something like this, I am imagining.

[
  {
    "Project": "Mose Kuvalis",
    "PlateType": "Ethel Bayer",
    "StatusCode": "Uriel Reynolds",
    "no_of_plates": 1
  },
  {
    "Project": "as",
    "PlateType": "as",
    "StatusCode": "te",
    "no_of_plates": 4
  },
  {
    "Project": "possq",
    "PlateType": "as",
    "StatusCode": "te",
    "no_of_plates": 1
  }

  {
    "Project": NULL,
    "PlateType": NULL,
    "StatusCode": NULL,
    "no_of_plates": 1
  }
// I indeed have 7 records in my plates table. 
]

Would someone show me a way or two. Much appreciated.

21 Dec
2 years ago

sevmardi left a reply on Eager Loading With Custom Query

Someone has an idea what I am trying to achieve here?

20 Dec
2 years ago

sevmardi started a new conversation Eager Loading With Custom Query

Hi guys,

I need a hand with the following.

I have a tested query which looks like this

return DB::table('container_slots')
    ->where('occupied', false)
    ->join('plate_containers','container_slots.plate_container_id', '=', 'plate_containers.id')
    ->select('plate_containers.name AS Container', DB::raw('count(container_slots.slot) as    no_of_slots'))
    ->groupBy('plate_container_id')->get();

I am trying to eager load this method as soon as the index method is called.


      $plateContainers = PlateContainer::with('getSlotsCountAttribute')->paginate(10);

        return response()->success($plateContainers);


Would someone please show me a way or 2 on who to achieve this.

I did some digging and thought I would do something like this.


// PlateContainer model 

    public function containerSlots()
    {
      return $this->hasMany('App\Models\ContainerSlot');
    }


    public function slotsCount()
    {
      return $this->containerSlots()
      ->where('occupied', false)
      ->join('plate_containers','container_slots.plate_container_id', '=', 'plate_containers.id')
      ->select('plate_containers.name AS Container', DB::raw('count(container_slots.slot) as no_of_slots'))
      ->groupBy('plate_container_id');

    }

    public function getSlotsCountAttribute()
    {
      $this->load('containerSlots');

      return $this->slotsCount();
    }


This actually works I guess, but returning an empty array? I have tested the query else where and it just works.

Any ideas?

30 Sep
2 years ago

sevmardi left a reply on Loop Through 0 Based Array

Marked! Thanks for helping out!

sevmardi left a reply on Loop Through 0 Based Array

Ok I feel like an idiot right now.

          foreach ($data['plates'] as $key => $value) {
               
                $plates = Plate::find($value['plate_id'])->plateContainer()->associate($data['container_id'])->save();

          }

Did the trick. Thanks everyone for your help.

sevmardi left a reply on Loop Through 0 Based Array

Log file is not producing any error.

sevmardi left a reply on Loop Through 0 Based Array

This dont work

What are the options?

sevmardi left a reply on Loop Through 0 Based Array

dd($data['plates']); returns

array:2 [
  0 => array:3 [
    "plate_id" => 1
    "orientation_id" => 1
    "slot_id" => array:2 [
      "slot" => array:7 [
        "id" => 16
        "slot" => 1
        "occupied" => 0
        "plate_container_id" => 16
        "user_id" => 1
        "created_by" => null
        "updated_by" => 1
      ]
      "selected" => false
    ]
  ]
  1 => array:3 [
    "plate_id" => 2
    "orientation_id" => 1
    "slot_id" => array:2 [
      "slot" => array:7 [
        "id" => 16
        "slot" => 1
        "occupied" => 0
        "plate_container_id" => 16
        "user_id" => 1
        "created_by" => null
        "updated_by" => 1
      ]
      "selected" => false
    ]
  ]
]

sevmardi left a reply on Loop Through 0 Based Array

It returns the same error as previously which is "Array to string conversion" error.

sevmardi left a reply on Loop Through 0 Based Array

It says "integer"

sevmardi left a reply on Loop Through 0 Based Array

It just returns 16. Which is the id of the container...but this doesn't make any sense to me. Why the first plate gets an update with the container id and the second.. or even third one is skipped?

sevmardi left a reply on Loop Through 0 Based Array

@tomi Hi!. Thanks for the quick one. I tried your method, but it returns "Array to string conversion" error.

sevmardi left a reply on Loop Through 0 Based Array

ok, so because it is an associative array, I wrote another foreach. This is what I got now.

        foreach ($data['plates'] as $element)
        {
          foreach ($element as $value)
           {
          $plates = Plate::find($value)->plateContainer()->associate($data['container_id'])->save();

        }
}

But here is the problem. Why only a single plate is updating its value? Checking the DB shows that plate with id of 1 was updated. The other one was not updated. Doing dd($value) shows 1. Can't seem to understand what's going on here. Anyone care's to explain?

29 Sep
2 years ago

sevmardi started a new conversation Loop Through 0 Based Array

Hi all!

I am little confused about the following.

I've got an array just like so, coming from JS side.

plates : [
0 : {plate_id: 1, orientation_id: 1}
1 : {plate_id: 2, orientation_id: 1}
...
]

so In the backend I foreach it like so. ..

  foreach ($data['plates'] as $index => $element) {

        // This is only grabbing the first element, not looping the entire object. 
        $plates = Plate::find($element['plate_id'])->plateContainer()->associate($data['container_id'])->save();

So what I want is to associate each plate to the given container ( as you can see ). Except this operation only applies to the first element. Checking the db shows only plate with id of 1 has been updated, the second one is still null. Any ideas what I am doing wrong?

FYI

Plate Model

    public function plateContainer()
    {
        return $this->belongsTo('App\Models\PlateContainer');
    }
 
PlateContainer Model

    public function plates()
    {
        return $this->hasMany('App\Models\Plate');
    }
06 Jan
3 years ago

sevmardi left a reply on Mixed Content Issue- Content Must Be Served As HTTPS

Any other ideas regarding this subject? I am sure not the only one having this kind of a problem.

05 Jan
3 years ago

sevmardi left a reply on Mixed Content Issue- Content Must Be Served As HTTPS

@bobbybouwmann I tried this, but could get it working.

Here is what I tried

in my app.php file

'url' => env('APP_URI', 'http://localhost'),

and in .env file

APP_ENV=production
APP_URI=https://laravelapp.domainname.com

.../

Any other ideas?

sevmardi started a new conversation Mixed Content Issue- Content Must Be Served As HTTPS

would someone please help me out with this one.

my index.blade.php is loading some css files, but it's seems on the production server this is not loading well. Local works just fine.

for instance

  <link rel="stylesheet" href="{{ asset('assets/css/app.css') }}">  // works fine locally, but not production

on the production server which is a subdomain https://laravelapp.domainname.com

is causing an error.

I have googled but couldn't find something useful regarding laravel app.

any ideas?

18 Dec
3 years ago

sevmardi left a reply on Laravel Activity Feed Question

@jbowman99 I did exactly what Jeffery did in his videos. But I don't think I can check what kind of activities on which specific id. This is what I am asking for actually.

17 Dec
3 years ago

sevmardi left a reply on Laravel Activity Feed Question

any ideas on this one?

sevmardi started a new conversation Laravel Activity Feed Question

Hi all, I have watched Jeffery's video's about how to create a simple activity feed. But the question I have now is, What if I want to know what kind of activities an article has ( assuming an article could be edited by number of other users).

For instance, I have number of hardware components and each of those has his own model. A user(s) might CRUD a component and make changes. At end what I want is to do a simple as this command ( or something similar)

$component = Model::find(1)->activity;

and get a list or array of all the activities (including user_ids) this specific id been through.

How I might achieve this?

Note: I have no relations yet setup.

11 Dec
3 years ago

sevmardi left a reply on How To Save Incoming Authenticated HTTP Users.

someone has any clue what I am asking for?

sevmardi started a new conversation How To Save Incoming Authenticated HTTP Users.

Hi All,

I need a little help with the following situation.

Our Apache server uses a php http basic auth which pops a little login panel to let the login (username, password) and afterwards has access to all the applications running behind it.

The application I am working on will serve the same way. Now I can fetch the user coming in by doing $_SERVER['PHP_AUTH_USER'] or using the laravel wrapper Request::server("PHP_AUTH_USER') both work just fine.

The problem comes when I need to track user's actions on the application. It seems to me that I have to first fetch the user and save into the database running behind laravel in order to use a simple command like $this->user_id

Note: The user needs to get saved as soon as user hits the laravel app url e.g. http://www.laravel-app.domainname.com So I thought to setup a small script somewhere in AppServiceProvider?

I am not sure If I am explaining this quite well. Please let me know if you understand the concept and I will try to explain the use case in some other way.

28 Nov
3 years ago

sevmardi left a reply on How To Fetch The Objects Coming In From AngularJS

Anyone else had this kind of issue? It's a simple form processing problem.

sevmardi left a reply on How To Fetch The Objects Coming In From AngularJS

@jlrdw the angular part is working just fine. It's making an object of the fields. The log shows that. All I want is to check if the object is reaching the method back in laravel. How can I debug this?

Any other clues?

27 Nov
3 years ago

sevmardi started a new conversation How To Fetch The Objects Coming In From AngularJS

Hai. I need some help with saving form data coming from angularjs.

I have this setup in my html.

<div class="panel-body">
    <div class="form-group form-group-lg">
        <label class="col-sm-2 control-label">Select a plate</label>
        <div class="col-sm-10">
            <select class="form-control m-t" id="plate_id"  ng-model="inspectionData.plate" ng-options="plate as (plate.serial_number) for plate in plates" required>
            <option value="">Please choose
              <span class="symbol required"></option>
            </select>
        </div>
    </div>
</div>

My js controller is this

$scope.storePlatesInspection = function() {

  PlatesInspectionFactory.inspectionUpdate($scope.inspectionData)
    .success(function(data)
    {
     $scope.ServerResponse = data;
     console.log($scope.inspectionData);
    })
    .error(function(data) {
    
        console.log($scope.inspectionData);
    });

};

I am using factory service and passing the object.

inspectionUpdate: function(inspectionData) {
    return $http({
        url: '/api/v1/plateinspection/',
        method: 'PUT',
        headers: {'Content-Type': 'application/x-www-form-urlencoded'},
        data: $.param(inspectionData)
    });
} 

All I want is to take the selected data and send it back though the API and save it.

I am confused on how to catch all the objects being send from Angular

here is what I have been trying.

public function storePlateInspectionData(Request $request){
    $plate  =   Plate::find($request->input('plate_id')); // this is not working 
    $doc    =   Document::find($request->input('document_id')); // neither this
    $plate->documents()->attach($doc->id);
}

Should I use Input::all() or $request->all() ?

Angularjs is sending the data just fine. I did console.log and everything seems okay. But I think the problem is at the back-end. Is there a way to debug this?

Someone please show me a good practice for this, please.

Not sure how to post a screenshot here (for the console.log)

23 Nov
3 years ago

sevmardi left a reply on Quick Help With Eloquent

@anzze Is there a better way to check for both occupied and not occupied slots otherwise return number_of_slots?

sevmardi left a reply on Quick Help With Eloquent

@anzze Thanks for helping out. your suggested exists() method works. What I meant by number of slots is integer is that the following.

A plate container has slots in it. Let's say in this case 6 slots. Each slot has it's own id.. so when I ask for a plate container with slots available the if statement triggers. if there is any it will return. otherwise I want to return number_of_slots a plate container has.

e.g.

A plate container with id 1 has 6 slots. 5 slots ( I mean 1,2,3,4,5) are occupied, so the above if statement should return only slot 6. Now if all the slots are not occupied ( 1,2,3,4,5,6 are all not occupied) it's should return all the slots [1,2,3,4,5,6].

This is what I have now.

   $plateCont = \App\Models\PlateContainer::find(1);

        $freeslots = $plateCont->containerSlots();

        if($freeslots->where('occupied', false)->exists())
        {
            return  $freeslots->lists('slot');
        }
        if(!$freeslots->where('occupied', true)->exists())
        {
            return $plateCont->number_of_slots;
        }

The second statement is simply saying if they are no slots which are equal to true I want you to return the number_of_slots a container has which I like it to be so [1,2,3,4,5,6]. So the question is how can I make the return of number_of_slots looks like this [1,2,3,4,5,6] return $plateCont->number_of_slots;

22 Nov
3 years ago

sevmardi left a reply on Quick Help With Eloquent

I don't understand why it's returning an empty array after the if statement.

this is all i get if there are no slots [] it's not returning the number_of_slots which a container has.. I do have data there.

sevmardi left a reply on Quick Help With Eloquent

Someone has an idea?

20 Nov
3 years ago

sevmardi started a new conversation Quick Help With Eloquent

This is properly a quick one.. I have relations setup and all working just fine.

I am trying to figure out a way to check if the selected plate container has any slots available, otherwise return all the slots the plate container has.

 $plateCont = \App\Models\PlateContainer::find(20);

        $freeslots = $plateCont->containerSlots();

        if($freeslots->where('occupied', false))
        {
          return  $freeslots->lists('slot');
        }

        $p =   $plateCont->number_of_slots; // number of slots is integer. How Can I push this into an array?

        return $p;



As I said I simply want to know if in the db are any slots which have the boolean false, if not, return the number of slots the plate container has. Someone show me a way to do this please.

19 Nov
3 years ago

sevmardi left a reply on Laravel Relations Question

I gave this a try! It worked! Thanks a lot ( I marked @pmall as a good answer, I wasn't able to understand the rest.. I am sorry)

sevmardi left a reply on Laravel Relations Question

So what should I have in my book model in this case? the normal.. A book has one status code?

sevmardi started a new conversation Laravel Relations Question

I am having some hard time understanding the following:

for example

I have book model which has a statuscode ( good, new, not-so-good, etc..)

In this case the relation is in the book model is "A book has one status code".

But what if I want to fetch all the books which have statuscode "good" what kind of relations I should put in my statuscode model?

I searched the term in laravel docs, but could't find it.

17 Nov
3 years ago

sevmardi left a reply on HELP! Determining Which Slots Are Available And Which Are Taken.

@squigg I think its a good idea what you suggested. This is my setup now.

    public function up()
    {
        Schema::create('plates', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('serial_number');
            $table->string('crc-code', 50);
            $table->string('reason', 50)->nullable();

            $table->integer('plate_container_id')->nullable()->unsigned()->index();
            $table->integer('container_slot_id')->nullable()->unsigned()->index();

           
            $table->foreign('plate_container_id')->references('id')->on('plate_containers')->onDelete('cascade');
            $table->foreign('container_slot_id')->references('id')->on('container_slots')->onDelete('cascade');

            $table->softDeletes();

            $table->timestamps();
        });
    }
    public function up()
    {
        Schema::create('plate_containers', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name', 25)->unique();
            $table->tinyInteger('number_of_slots')->default(15);
            $table->text('description')->nullable();
            $table->string('material', 50);

            $table->timestamps();
        });
    }
    public function up()
    {
        Schema::create('container_slots', function (Blueprint $table) {
            $table->increments('id');
            $table->tinyInteger('slot');
            $table->boolean('taken');
            $table->integer('plate_container_id')->unsigned()->index();

            $table->foreign('plate_container_id')->references('id')->on('plate_containers')->onDelete('cascade');

            $table->timestamps();
        });
    }

The question is now, how I might mark the slot taken after the user has selected it and assigned it ? using the boolean doesn't seem a good idea. Is there a way to do it using the eloquent relations?

This is the relations I have now. Plate Model

    public function plateContainer()
    {
        return $this->belongsTo('App\Models\PlateContainer');
    }
    public function containerSlot()
    {
      return $this->belongsTo('App\Models\ContainerSlot');
    }

PlateContainer model

    public function plates()
    {
        return $this->hasMany('App\Models\Plate');
    }

    public function containerSlots()
    {
      return $this->hasMany('App\Models\ContainerSlot');
    }

Containerslot model

    public function plateContainer()
    {
      return $this->belongsTo('App\Models\PlateContainer');
    }

    public function plate()
    {
        return $this->hasOne('App\Models\Plate');
    }
13 Nov
3 years ago

sevmardi left a reply on HTTP Authentication

@bobbybouwmann Thanks! I know Laravel has one. But.. the problem is.. the users ( and their passwords) are not in database which laravel is connected to. They are on a apache server which has it's own database. I this case I thought I might need LDAP driver instead of eloquent in order to validate the user and get the usernames. The system administrator done this so that the user has only 1 password which can visit different applications ( after the Auth is validated). Do you get an idea which I am trying to explain here?

11 Nov
3 years ago

sevmardi left a reply on HELP! Determining Which Slots Are Available And Which Are Taken.

@squigg Thanks again. I have set up the relations as you suggested. I have the 'taken' column as an extra, But I am willing to use the relations approach to fetch all the slots which they have no plates assigned to.

So, when the user selects a platecontainer, the database should filter which slots are already assigned to a plate (taken) and which not. How I might achieve this?

return   $p = \App\Models\PlateContainer::with('containerSlots.plate')->find(21);
{
    "id": 21,
    "name": "Prof. Odell Ritchie Sr.",
    "description": "Ut iste voluptatem et deleniti maxime vitae odit.",
    "material": "silicon",
    "created_at": "2015-11-11 09:44:47",
    "updated_at": "2015-11-11 09:44:47",
    "container_slots": [
        {
            "id": 9,
            "slots": 8,
            "taken": 0,
            "plate_container_id": 21,
            "created_at": "2015-11-11 09:44:47",
            "updated_at": "2015-11-11 09:44:47",
            "plate": {
                "id": 23,
                "serial_number": 748546964,
                "crc-code": "1",
                "reason": null,
                "stack_id": 8,
                "plate_container_id": 14,
                "container_slot_id": 9,
                "deleted_at": null,
                "created_at": "2015-11-11 09:44:48",
                "updated_at": "2015-11-11 09:44:48"
            }
        },
        {
            "id": 22,
            "slots": 2,
            "taken": 1,
            "plate_container_id": 21,
            "created_at": "2015-11-11 09:44:47",
            "updated_at": "2015-11-11 09:44:47",
            "plate": null
        }
    ]
}

This will only return the plate(s) associated with containerslot, but still don't know which plate in which slot

10 Nov
3 years ago

sevmardi left a reply on HELP! Determining Which Slots Are Available And Which Are Taken.

@squigg Thanks for your answer.

So I am not sure I understand the concept of 'taken' should be a string? a boolean?

    public function up()
    {
        Schema::create('container_slots', function (Blueprint $table) {
            $table->increments('id');
            $table->tinyInteger('slots');
            $table->string('taken'); // should this be a string? 
            $table->integer('plate_container_id')->unsigned()->index();

            $table->foreign('plate_container_id')->references('id')->on('plate_containers');

            $table->timestamps();
        });
    }

When you put a plate into a slot, you then associate that plate with the specific ID of that slot (using a foreign key relationship). >You would need to update your plates table accordingly. You could then add a relation to the containerSlot to get the >associated plate.

In containerslot model I should have

  public function plate()
    {
        return $this->hasOne('App\Models\Plate'); // Or many??  sorry I am confused.
    }
// Plate model
  public function slots()
    {
      return $this->belongsTo('App\Models\ContainerSlot');
    }
 

// plates table

    public function up()
    {
        Schema::create('plates', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('serial_number');
            $table->string('crc-code', 50);
            $table->string('reason', 50)->nullable();
            //$table->tinyInteger('plate_container_slot')->nullable();

            $table->integer('stack_id')->nullable()->unsigned()->index();
            $table->integer('plate_container_id')->unsigned()->index();
            $table->integer('container_slot_id')->unsigned()->index();
            $table->foreign('stack_id')->references('id')->on('stacks')->onDelete('cascade')->onUpdate('cascade');
            $table->foreign('plate_container_id')->references('id')->on('plate_containers')->onDelete('cascade')->onUpdate('cascade');
            $table->foreign('container_slot_id')->references('id')->on('container_slots')->onDelete('cascade')->onUpdate('cascade');
            $table->softDeletes();


            $table->timestamps();
        });
    }
 

Is this what you meant? Sorry :( things are getting a little confusing

sevmardi left a reply on HELP! Determining Which Slots Are Available And Which Are Taken.

@awwang10 I am not sure about your solution. I might think you got things the wrong way?

So here is it again.

Many plate can be set into One container

So I thought the relation might be something along these lines

// Plate model

    public function plateContainer()
    {
        return $this->belongsTo('App\Models\PlateContainer');
    }

// platecontainer model 

  public function plate()
    {
        return $this->hasMany('App\Models\Plate');
    }
//PlateContainer Model
// Platecontainer has many slots

public function containerSlot()
    {
      return $this->hasMany('App\Models\ContainerSlot');
    }

// containerslot model

  public function plateContainer()
    {
      return $this->belongsTo('App\Models\PlateContainer');
    }

class CreateContainerSlotsTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('container_slots', function (Blueprint $table) {
            $table->increments('id');
            $table->tinyInteger('slots');
            $table->integer('plate_container_id')->unsigned()->index();

            $table->foreign('plate_container_id')->references('id')->on('plate_containers');

            $table->timestamps();
        });
    }
class CreatePlatesTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('plates', function (Blueprint $table) {
            $table->increments('id');
            $table->integer('serial_number');
            $table->string('crc-code', 50);
            $table->string('reason', 50)->nullable();
            $table->tinyInteger('plate_container_slot')->nullable();

            $table->integer('stack_id')->nullable()->unsigned()->index();
            $table->integer('plate_container_id')->unsigned()->index();

            $table->foreign('stack_id')->references('id')->on('stacks')->onDelete('cascade')->onUpdate('cascade');
            $table->foreign('plate_container_id')->references('id')->on('plate_containers')->onDelete('cascade')->onUpdate('cascade');

            $table->softDeletes();


            $table->timestamps();
        });
    }

class CreatePlateContainersTable extends Migration
{
    /**
     * Run the migrations.
     *
     * @return void
     */
    public function up()
    {
        Schema::create('plate_containers', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name', 25)->unique();
            $table->tinyInteger('number_of_slots');
            $table->text('description')->nullable();
            $table->string('material', 50);


            $table->timestamps();
        });
    }

Any suggestions or ideas?

30 Oct
3 years ago

sevmardi left a reply on HELP! Determining Which Slots Are Available And Which Are Taken.

Come on guys. Just a little help here, please. If you don't understand the question, I will try to give you other examples.

sevmardi started a new conversation HELP! Determining Which Slots Are Available And Which Are Taken.

I need some desperate help here. Dealing with this for a week now!!

So this is the case. When a user selects a platecontainer for the plate, the platecontainer object presents a list of its slots ( number_of_slots in this case). This object query's the containerslots and returns which slots are already taken ( you can't assign a plate to ) and which are free to use.

I have the setup like this A plate, plate_container and container_slots tables

Schema::create('plates', function (Blueprint $table) {
            $table->increments('id');

            $table->tinyInteger('plate_container_slot')->nullable();

            $table->integer('plate_container_id')->nullable()->unsigned();
      $table->foreign('plate_container_id')->references('id')->on('plate_containers')-     >onDelete('cascade');


//Platecontainers table

  Schema::create('plate_containers', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name', 25)->unique();
            $table->tinyInteger('number_of_slots');

            $table->string('material', 50);

            $table->integer('container_slot_id')->unsigned()->index();

            $table->foreign('container_slot_id')->references('id')->on('container_slots')->onDelete('cascade');

            $table->timestamps();
        });

// And Containerslots table 

        Schema::create('container_slots', function (Blueprint $table) {
            $table->increments('id');
            $table->tinyInteger('slots');
            $table->timestamps();
        });

I have the relations setup like this.

Plate Model

    public function plateContainer()
    {
        return $this->belongsTo('App\Models\PlateContainer');
    }

PlateContainer model

    public function containerSlot()
    {
      return $this->belongsTo('App\Models\ContainerSlot');
    }

And Containerslot model

    public function plateContainer()
    {
      return $this->hasMany('App\Models\PlateContainer');
    }

To check which slots are available I use this structure.

     $plateContainerwithAvialableSlots = PlateContainer::with(['containerSlot' => function ($q)
        {
        $q->join('plates', 'plates.plate_container_id', '<>', 'container_slots.id');

      }])->find(2);

       dd($plateContainerwithAvialableSlots->containerSlot);

The first question is: Am I doing things right here? I know something isn't right . But I am confused and can't figure things out anymore. If you have any other ideas or different structure on how to implement this, please let me know.

29 Oct
3 years ago

sevmardi left a reply on Update Relations In Eloquent

@mstnorris I had my reverse models setup. A plate has many documents. How I might deal with that? When the user selects two different documents from a selection.

sevmardi started a new conversation Update Relations In Eloquent

I have model setup like this.

  public function equipmentStatusCode()
    {
       return $this->hasOne('App\Models\EquipmentStatusCode');
    }

    public function documents()
    {
        return $this->hasMany('App\Models\Document');
    }


    public function plateQuality()
    {
        return $this->hasOne('App\Models\PlateQuality');
    }

    public function orientation()
    {
      return $this->hasOne('App\Models\Orientation');
    }

Now In my controller I am willing to update the id's of all those relations. How I might I do that?

In controller I tried this. But of course this will only update a certain relation.

public function update($id)
{
    $p = Plate::find($id)
        ->documents()->update(['plate_id' => 5 ]);
        // how about the other relations?? 
}

Would someone show me a video or a sample on how to do this all at once?

28 Oct
3 years ago

sevmardi left a reply on Are My Relations Good?

@mstnorris I know this has nothing to do with my question. But how might I go updating the id of the equipmentstatuscode while I am updating the plate. Example

public function updatePlate(ExampleRequest $request, $id)
    {   
$plate = Plate::find($id);
 $plate->equipmentStatusCode = Config::get('EquipmentStatusCodes.PlateReadyToBeCleaned'); // this won't work naturally 
  $data = $request->all();

    if ($plate->update($data))
       {
            return response()->json([
                'Success' => [
                    'message' => 'Plate is updated!'
                ]
            ], 201);
        }
        else
        {
            return response()->json([
                'Error' => [
                    'message' => 'Plate is not updated, something went wrong!'
                ]
            ], 400);
        }
    }

sevmardi left a reply on Are My Relations Good?

@mstnorris Great! So each time a model has belongsTo means that the integer and foreign key get setup on that migration?

sevmardi started a new conversation Are My Relations Good?

This is properly a quick one.

I followed Jeffery's video regarding eloquent. A user has many articles and an article belongs to an user..

In my example I have it this way.

A plate model (which is in this case the user) has one statuscode.

    public function equipmentStatusCode()
    {
       return $this->hasOne('App\Models\EquipmentStatusCode');
    }

and an statuscode (which is the article in this case) belongsTo a plate

public function plate()
{
     return $this->belongsTo('App\Models\Plate');
}

I have got the migration setup like this.

    Schema::create('equipment_status_codes', function (Blueprint $table) {
            $table->increments('id');
            $table->string('name', 25)->unique();

            $table->integer('plate_id')->unsigned();
    $table->foreign('plate_id')->references('id')->on('plates')->onDelete('cascade')->onUpdate('cascade');

Am I good to go?

sevmardi started a new conversation Laravel Eloquent Relations In AngularJS

I am having some difficulties in way Laravel Eloquent relations works in AngularJS..

for example

Let's say I have a bookshelf which has many books. And a book belongsto bookshelf in this case.

How I might access this relation in my front-end using AngularJS.

I had this in mind

Bookshelf::with('book')->find($id);

But to me this is not a best case scenario, because I have other relations willing to access as well.

What I am willing to do is-- simply, when a user selects a bookshelf, a dropdown shows all the books this particular bookshelf has.

How I might go about this?

21 Oct
3 years ago

sevmardi started a new conversation Filtering And Showing Which Integers Are Already Taken And Which Are Available

I am having some difficulties implementing a method which can see what number(s) are already taken and what not.

I have a table called Books

//..

$table->integer('bookshelf_id')->nullable()->unsigned();
$table->foreign('bookshelf_id')->references('id')->on('bookshelves')->onDelete('cascade')->onUpdate('cascade');
$table->tinyInteger('bookshelf_number')->nullable();

And I have another table called bookshelves

//..

 $table->tinyInteger('number_of_slots');

so the steps are like this

  • The user selects a book
  • Select a shelf for the book to assign to
  • The shelf should filter which slots are already taken and which are available.
  • The user selects available slot and saves the book.

Here comes the problem.

I want to, when the user selects a bookshelf, the db filters which slots the selected bookshelf has available and which slots are occupied .

Would someone tell me what's the best way to implement this?

I was thinking to write a function which takes the id of the selected bookshelf and get the attribute 'number_of_slots' .. but now what? How I can make sure those slots are taken by some other book?

20 Oct
3 years ago

sevmardi left a reply on Eloquent Relations Confusion

is there sometimes a reason I get a white page and nothing more than that If I make a call to id 1 from the plates. It just does return anything. If I use dd I get null on the screen.

sevmardi left a reply on Eloquent Relations Confusion

Great tip! Does it hurt if I leave (for time being) my models name like they are now. Or I should make those singular?