zaster

zaster

Member Since 3 Years Ago

Experience Points 12,440
Experience Level 3

2,560 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 25
Lessons
Completed
Best Reply Awards 1
Best Reply
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.

15 May
4 days ago

zaster left a reply on Assign A 0 To A Null Value In A Request Array

In Laravel

When a Form is submitted with blank fields(empty strings), those get converted to null

In my requirement, i need them to get converted in to 0

zaster left a reply on Assign A 0 To A Null Value In A Request Array

@tykus

How can i assign a default value?

zaster left a reply on Assign A 0 To A Null Value In A Request Array

@snapey

You mean like this in the database level

$table->integer('qty')->default(0);

Tried that and got this

SQLSTATE[23000]: Integrity constraint violation: 1048 Column 'qty' cannot be null 

zaster left a reply on Assign A 0 To A Null Value In A Request Array

@tykus

I have a set of input fields and some fields are supposed to be blank (depends on the situation) before submitting

But because of this validation rule

            'dispatch_item_qty.*' => [
                'required'      
            ],    

the user has to input 0 for all blank fields

To avoid this situation i am trying to pass 0 value to all my NULL assigned array items before the validation take place

dd($request->input('dispatch_item_qty'));

gives this

array:3 [▼
  9 => "1"
  10 => "2"
  11 => "3"
]

And i tried this

        if($request->input('dispatch_item_qty.9') == 1)
        {
            $request->input('dispatch_item_qty.9', 0);
            dd($request->input('dispatch_item_qty.9'));
        }

The result is

1

What i want is to make the result

0

zaster started a new conversation Assign A 0 To A Null Value In A Request Array

I wan to do something like this

    public function store(Request $request)
    {
        if($request->input('dispatch_item_qty.9') == null)
        {
            $request->input('dispatch_item_qty.9') = 0;
            dd($request->input('dispatch_item_qty.9'));
        }
13 May
6 days ago

zaster left a reply on Assign 0 To All Null Values Of An Array

@snapey

Tried this

public function store(Request $request)
{

    //Get the sub_jobs of the given job, based on user_company_id and the comp
    $sub_jobs = SubJob::where('job_id', $request->job_id)
    ->where('user_company_id', $request->company)
    ->where('comp', $request->comp)
    ->get();            

    foreach($sub_jobs as $sub_job)
    {
        if($request->dispatch_item_qty[$sub_job->id] == null)
        {
            $request->dispatch_item_qty[$sub_job->id] = 0;
        }
    }
     
    //dd($dispatch_item_qty);

        $this->validate($request, [
            
            'dispatch_item_qty.*' => [
                'required'      
            ],            

          ]);
.
.
.

}

and getting the below error

Indirect modification of overloaded property Illuminate\Http\Request::$dispatch_item_qty has no effect

zaster started a new conversation Assign 0 To All Null Values Of An Array

        $this->validate($request, [

            'dispatch_item_qty.*' => [
                'required'      
            ],            

          ]);

How can i assign a **0** to all Quantities which are Null

12 May
1 week ago

zaster left a reply on How To Pass Dispatches To The View In 1-M-N Kind Of Relation

 $sub_jobs = $job->sub_jobs;
                       
$dispatches = $sub_jobs->load('dispatches')
->pluck('dispatches')->flatten()->unique('id');

This worked.

zaster left a reply on Get All Relations Of A M To N - Before Sending To The View

@staudenmeir

What if you want to get the $sub_jobs are taken as

$sub_jobs = $job->sub_jobs; 

How can i get the dispatches of a specific job?

Something like

$dispatches = $sub_jobs::with('dispatches')->get()
    ->pluck('dispatches')->flatten();

zaster left a reply on How To Pass Dispatches To The View In 1-M-N Kind Of Relation

 $dispatches = SubJob::with('dispatches')->get()
        ->pluck('dispatches')->flatten()->unique('id');

zaster started a new conversation Get All Relations Of A M To N

SubJob and Dispatch has a Many to Many relationship

I need to do something like this

      foreach($sub_jobs as $sub_job)
        {
            $dispatches = $dispatches + $sub_job->dispatches;
        }
        
11 May
1 week ago

zaster left a reply on How To Pass Dispatches To The View In 1-M-N Kind Of Relation

@bobbybouwmann

Yes. This is correct.

Taking the question a bit further

Since SubJob and Dispatch has a Many to Many relationship

I need to show only the unique dispatches

The pivot table looks like this

id | dispatch_id | sub_job_id | qty | ------------ | ------------- 42 | 25 | 3 | 10 43 | 25 | 5 | 20

zaster started a new conversation $job->load(['sub_jobs.dispatches']); - How To Pass Dispatches To The View

$job->load(['sub_jobs.dispatches']);

I need to do a

@foreach($dispatches as $dispatch)
{
    ...
}
@endforeach

in the view

How can i get the dispatches?

09 May
1 week ago

zaster left a reply on Where Clause - Undefined Variable

@jlrdw

Thanks for the tip

I found the issue and it was about having similar strings

E.g. -

$comp = "PWC" $comp = "PW"

This issue is solved

zaster left a reply on Where Clause - Undefined Variable

@jlrdw

dd($comp)   

gives a string (Initials of the company name)

PWC

This is what i wanted to do in the first place

            $last_dispatch = Dispatch::where('no', 'like', '%.'.$comp.'.%')     
            ->orderBy('id', 'desc')->first();

zaster started a new conversation Where Clause - Undefined Variable


$comp = $sub_jobs->first()->comp;

//get the last dispatch_no of that comp
$last_dispatch = Dispatch::where(function($query)
{
 $query->where('no', 'LIKE', '%'.$comp.'%');
})
 ->orderBy('id', 'desc')->first();

Gets

Undefined variable: comp
08 May
1 week ago

zaster started a new conversation Get The First Record And Select The Given Table Column In One Line

Is there a way to do the below mentioned in one line?

$sub_job = $sub_jobs->first();
$comp = $sub_job->comp;
07 May
1 week ago

zaster left a reply on Array To String Conversion Error

@ftiersch

I think i have mislead you with this

Each dispatch has multiple quantities

I am sorry about that

Each dispatch has multiple dispatch_items and each dispatch_item has one qty

Anyway i am still have doubts with logic and code etc... need to give some time and figure it out

Thank you very much for your support

zaster left a reply on Array To String Conversion Error

form

{{-- <th>Dispatch Item Qty</th> --}}
<td class="col-md-2">                                          
  <input type="text" class="form-control" name="dispatch_item_qty[{{$sub_job->id}}]">
 </td>  

dd($request);

+request: ParameterBag {#43 ▼
    #parameters: array:6 [▼
      "_token" => "cQQv8KMaPeskjVq6GmspJz3SO4gh7PTe5yj0psrz"
      "dispatch_item_qty" => array:3 [▼
        3 => "5"
        4 => "10"
        5 => "100"
      ]

controller

foreach($sub_jobs as $sub_job)
{
$sub_job->dispatches()->attach($dispatch_id, ['qty' => ???????]);
}

zaster left a reply on Array To String Conversion Error

@ftiersch

Each dispatch has multiple quantities

zaster left a reply on Array To String Conversion Error

@ftiersch @foram

The pivot table should be updated with this extra qty field and those quantities are inputted by a form and passed through an array (dispatch_item_qty)

I need to get the values from this array and insert in to the pivot table

Tried this

foreach($sub_jobs as $sub_job)
{
   $sub_job->dispatches()->attach($dispatch_id, ['qty' => implode(',',$request->dispatch_item_qty)]);
}

and received this error

SQLSTATE[01000]: Warning: 1265 Data truncated for column 'qty' at row 1

zaster left a reply on Array To String Conversion Error

@foram

SQLSTATE[42S22]: Column not found: 1054 Unknown column '0' in 'field list'      

Please note that in my real requirement, there can be multiple values in the dispatch_item_qty array

zaster left a reply on Array To String Conversion Error

@ftiersch

SQLSTATE[42S22]: Column not found: 1054 Unknown column '0' in 'field list'  
$sub_job->dispatches()->attach($dispatch_id, [array('qty'=> array_values($request->dispatch_item_qty)[0])]);  

zaster left a reply on Array To String Conversion Error

@foram

 $request->dispatch_item_qty[3]

In my code

3 is generated dynamically

zaster left a reply on Array To String Conversion Error

@ftiersch Is there a function that i could use at once?

Or should i try to do that in a longer way?

zaster started a new conversation Array To String Conversion Error

+request: ParameterBag {#43 ▼
    #parameters: array:6 [▼
      "_token" => "cQQv8KMaPeskjVq6GmspJz3SO4gh7PTe5yj0psrz"
      "dispatch_item_qty" => array:1 [▼
        3 => "5"
      ]

foreach($sub_jobs as $sub_job) { $sub_job->dispatches()->attach($dispatch_id, [array('qty'=> $request->dispatch_item_qty)]); }

As i understand, the value ofdispatch_item_qty``` should be converted from a string to a numerical value

06 May
1 week ago

zaster left a reply on Table Structure Issue - Many To Many

I think i was confused with the core database concepts

According to my understanding, i thought of using Only dispatch_subjob pivot table with below columns

id
dispatch_id
sub_job_id
qty
description

also i thought of naming the pivot table ->as('dispatch_items')

I hope this is the correct answer for my question

zaster started a new conversation Table Structure Issue - Many To Many

dispatches 1------M dispatch_items

sub_jobs 1-------M dispatch_items

dispatches M-----N sub_jobs

I need to have all of these relationships

dispatch_subjob table (Is the intermediary table between dispatches and sub_jobs) and it has below mentioned columns

id

dispatch_id

sub_job_id

dispatch_items table has below mentioned columns

id

dispatch_id

sub_job_id

qty

description

My issue is that i see dispatch_id and sub_job_id is repeated in both tables(Table structure looks wrong)

Practically i need to have both these tables like above mentioned to get results in a much practical way E.g.: - sub_jobs table has a qty field and i need to do some caculations with dispatch_items table qty

zaster left a reply on Table Structure Issue - Many To Many

As i see there is no requirement for a dispatch_subjob table

becuase dispatch_items table is already having the columns for dispatch_subjob

05 May
2 weeks ago

zaster started a new conversation .gitignore - Doesn't Work As Expected

I am using the Snappy PDF/Image Wrapper for Laravel 5 package and want to ignore it's config file at the production level because the config file varies in production and local

The package config file is located

/config/snappy.php

therefore i added it to the .gitignore file

My .gitignore file looks like this

/node_modules
/public/hot
/public/storage
/storage/*.key
/vendor
/.idea
/.vagrant
/config/snappy.php
Homestead.json
Homestead.yaml
npm-debug.log
yarn-error.log
.env

Unfortunately this file is not getting ignored. As a result i have to change the /config/snappy.php each time i update the production

04 May
2 weeks ago

zaster left a reply on Table Structure Issue - Many To Many

@snapey

dispatch_subjob table id dispatch_id sub_job_id

dispatch_items table id dispatch_id sub_job_id qty description

03 May
2 weeks ago

zaster left a reply on Table Structure Issue - Many To Many

My issue here is that dispatch_id and subjob_id columns are repeated in the intermediary table as well as the dispatch_items table

zaster started a new conversation Table Structure Issue - Many To Many

dispatches 1------M dispatch_items sub_jobs 1-------M dispatch_items

dispatches M-----N sub_jobs

Should i need to have the relationship between dispatches table and sub_jobs table ?

zaster started a new conversation Referencing All Models At Once In A Controller?

use App\Http\Models\CarModel;
..
..
..

The relevant models are used in a controller file as mentioned above

Is it possible to, like have a template kind of a thing to include all those models in a project and then import only that in a controller (Assuming all models have unique names)?

Is this practical ?

Are there any performance issues ?

zaster started a new conversation Array Issue

I have two arrays

    "subjob_id" => array:2 [▼
        0 => "3"
        1 => "4"
      ]
      "dispatch_qty" => array:2 [▼
        0 => "22"
        1 => "33"
      ]

What i want is to achieve a result like below mentioned

3=>"22"
4=>"33"
28 Apr
3 weeks ago

zaster started a new conversation Resourceful Route Order - Does It Matter?

Route::resource('photos', 'PhotoController');

Give the below order

photos.store
photos.index
photos.create
photos.show
photos.update
photos.destroy
photos.edit

But should we organize our routes as below mentioned ? Does the order matter ?

photos.edit   //photos/{photo}/edit
photos.update //photos/{photo}/update
photos.create //photos/create
photos.show   //photos/{photo}
photos.destroy//photos/{photo}
photos.index  //photos
photos.store  //photos

zaster left a reply on Querying Relationship Existence

@neeonline

Yes.

$job->sub_jobs; 

returns all sub_jobs of $job

and there is a 1 to Many relationship between Job and SubJob

27 Apr
3 weeks ago

zaster left a reply on Querying Relationship Existence

@BEKASKAKI - ``` Method with does not exist.

zaster left a reply on Querying Relationship Existence

@JACEY - Dispatch is a model

Sub_Job and Dispatch has a Many to Many relationship

zaster left a reply on Querying Relationship Existence

@patrickadvance

So how can i achieve the result i want

zaster started a new conversation Querying Relationship Existence

$sub_jobs = $job->sub_jobs; // No Issue

I want to do something like this

 $sub_jobs = $sub_jobs::has('dispatches')->get(); // Wrong

zaster left a reply on Querying Relations ( 1 To M , M To N)

@pramanadiputra

Sub_Job and Dispatch has a Many to Many relationship

zaster started a new conversation Querying Relations ( 1 To M , M To N)

Job and Sub_Job has a 1 to M relationship

Sub_Jobs and Dispatches has a M to N relationship

I want to get all the dispatches of a given job if they exists

Should i use HasManyThrough

26 Apr
3 weeks ago

zaster started a new conversation Querying Relations

$job->load('sub_jobs.company');

foreach($job->sub_jobs as $sub_job){
    dd(sub__job->company);
}

Works

What i want is to do something like this

$companies = $job->sub_jobs->company;

24 Apr
3 weeks ago

zaster left a reply on Accessing A Relation In A Collection

@mattsplat

Thank you very much for your guidance

To cater my requirement i did the below and it works, though i feel that there can be a better way of doing it

        $sub_jobs = $job->load(['sub_jobs' => function ($query) {
            $query->with('company');
        }])
        ->sub_jobs
        ->unique('user_companies_id');
 <select class="form-control" name="user" id="user">
  <option value="0" disable="true" selected="true">Select Company</option>
    @foreach($sub_jobs as $sub_job)                                            
      <option value="{{$sub_job->company->id}}">{{$sub_job->company->name}}</option>                                            
    @endforeach
  </select>
23 Apr
3 weeks ago

zaster started a new conversation Accessing A Relation In A Collection

Collection {#617 ▼
  #items: array:1 [▼
    0 => SubJob {#619 ▼
..
..

      #relations: array:1 [▼
        "company" => Company {#651 ▶}
      ]

I want to do something like this

  $companies = $job->sub_jobs->company()->distinct('name')->pluck('name');   

I am getting this error

Method company does not exist.

zaster started a new conversation Many To Many Table Name Suggestion

I have vendor_companies and item_categories tables

These two tables has a Many to Many relationship between them

What should i use as the table name?

22 Apr
3 weeks ago

zaster started a new conversation Is It Ok To Have Multiple Models For 1 Table

When employees log in through

site.com/employee/login

They get to access the vendor_companies table through App\Models\Employee\VendorCompany Model

When vendors log in through

site.com/vendor/login

They get to access the vendor_companies table through App\Models\Vendor\VendorCompany

Is this approach ok?

zaster started a new conversation Including Routes With A Variable {id} To A Menu

I have a sidebar and all the menus looks like

<li><a href="{{route('employee.job.create')}}"><i class="fa fa-link"></i> <span>Add Job</span></a></li>

<li><a href="{{route('employee.quotation.create')}}"><i class="fa fa-link"></i> <span>Add Quotation</span></a></li>

etc...

How can i represent something like

<li><a href="{{route('vendor.profile.edit', $vendor_company->id)}}"><i class="fa fa-link"></i> <span>Profile</span></a></li>

There should be a way of passing the $vendor_company->id in an easy way

Or should i pass $vendor_company thorough each and every controller ?