zaster

zaster

Member Since 3 Years Ago

Experience Points 13,010
Experience Level 3

1,990 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-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.

26 Jun
3 weeks ago

zaster left a reply on Automatic Backup Is Not Working

@talinon

Thank you for that valuable information

My cron status was inactive

I started the service and everything works fine now. :)

zaster left a reply on Automatic Backup Is Not Working

I did a

php artisan cache:clear

but still nothing

zaster left a reply on Automatic Backup Is Not Working

@johnbraun

It seems like that is not the issue

I tried

* * * * * php /var/www/app5/artisan schedule:run >> /dev/null 2>&1

app5 is the root of my laravel project and artisan file is located inside that

app/Concole/Kernel.php

$schedule->command('backup:run')->everyMinute(); 

This works only when i go to

/var/www/app5

and run

php artisan schedule:run
25 Jun
3 weeks ago

zaster started a new conversation Automatic Backup Not Working

I am using Laravel 5.5 with Spatie Backup

I need to do something like this

    protected function schedule(Schedule $schedule)
    {
        //$schedule->command('backup:run')->everyMinute(); 
        $schedule->command('backup:clean')->dailyAt('17:30');
        $schedule->command('backup:run')->dailyAt('17:45');
    }

I have installed guzzlehttp/guzzle and have done

crontab -e

          • php /path/ schedule:run >> /dev/null 2>&1
$schedule->command('backup:run')->everyMinute(); 

works when i manually run php artisan schedule:run in the production terminal

06 Jun
1 month ago

zaster started a new conversation Project With The Highest Number Of Tables

Just curious of the highest number of table count that you have worked on

I am working on a project which is still ongoing and has 44 tables in the database

zaster left a reply on Creating A Model B Inside Model A

@okusax

I solved it, but couldn't identify what made the error

05 Jun
1 month ago

zaster started a new conversation Creating A Model B Inside Model A

inovice.php

I have a function

public function addInvoiceValue($invoice_id) {

//Other Code

//Can't i do this $transaction = new Transaction();

}

When i try to create $transaction , a $invoice is created

01 Jun
1 month ago

zaster started a new conversation WithDefault() On BelongsToMany

I want to do something like this, it's not working at the moment

use DB;

    public function sub_jobs()
    {
        return $this->belongsToMany('App\Models\Employee\SubJob', 'invoice_subjob')
        ->withPivot('qty', 'rate', 'description')
        ->withTimestamps()
        ->withDefault();
        
    }  
Call to undefined method Illuminate\Database\Query\Builder::withDefault() 
29 May
1 month ago

zaster left a reply on Snappy PDF Suddenly Stopped Working - Windows

I have assigned the port 8080 to a Physical printer. Corrected it and everything works fine now.

zaster left a reply on Snappy PDF Suddenly Stopped Working - Windows

Issue is only in the windows environment. I checked my production which is on Ubuntu 16.0.4 and it works perfectly fine.

zaster started a new conversation Snappy PDF Suddenly Stopped Working - Windows

I am using Snappy PDF

wkhtmltopdf --version
wkhtmltopdf 0.12.5 (with patched qt)

It suddenly stopped working

The exit status code '-1073740771' says something went wrong: stderr: "Loading pages (1/6) [> ] 0% [======> ] 10% [========> ] 14% [=================> ] 29% [=====================> ] 36% [========================> ] 41% QNetworkAccessFileBackendFactory: URL has no schema set, use file:// for files [==========================> ] 44% [===========================> ] 46% [=============================> ] 49% [============================================================] 100% " stdout: "" command: "C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf.exe" --lowquality --orientation "landscape" --page-size "a5" --footer-right "Page [page] of [topage]" 
28 May
1 month ago

zaster started a new conversation How To Avoid Creating A Blank Dispatch

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

dispatch_subjob represents a dispatchitem

How can i avoid creating a Dispatch with no dispatchitems with all these logic

//Create a new dispatch and assign all dispatch_items to it
            $selected_company = 0;
            $dispatch_created = 0;
            $dispatch_id = 0;
            foreach($sub_jobs as $sub_job)            
            {                
                //Check dispatch_item_qty > 0 and assign them to the dispatch
                if($request->dispatch_item_qty[$sub_job->id] > 0)   
                {
                    if($selected_company == 0 && $dispatch_created ==0) //Occurs only once when a saving is done
                    {                        
                        $dispatch = new Dispatch();                               
                        $dispatch->no = $new_dispatch_no;
                        $dispatch->user_company_id = $request->company;
                        $dispatch->delivery_address_id = $request->delivery;
                        $dispatch->date = Carbon::now(); 
                        
                        
                        $dispatch->save();

                        $selected_company = $sub_job->comp;
                        $dispatch_created = 1;
                        $dispatch_id = $dispatch->id;
                        
                    }
                    //Assign all dispatch_items to that Dispatch
                    //Qty remaining and Qty In Hand should be deducted only if each of those are higher than the dispatch_item->qty
                    $dispatch_item_qty_total[$sub_job->id] = 0;
                    foreach($sub_job->dispatch_items as $dispatch_item)
                    {
                        $dispatch_item_qty_total[$sub_job->id] = $dispatch_item_qty_total[$sub_job->id] + $dispatch_item->qty;                                                                     
                    }
                    
                    //qty remaining = $sub_job->qty - $dispatch_item_qty_total[$sub_job->id
                    if($request->dispatch_item_qty[$sub_job->id] <= ($sub_job->qty - $dispatch_item_qty_total[$sub_job->id]) &&
                    $request->dispatch_item_qty[$sub_job->id] <= $sub_job->qty_in_hand)
                    {
                        $sub_job->dispatches()->attach($dispatch_id, [  //attaches the dispatch_items
                        'qty' => $request->dispatch_item_qty[$sub_job->id], 
                        'description' => $request->dispatch_item_description[$sub_job->id]
                        ]);
                                                                        
                        DB::table('sub_jobs')
                        ->where('id', $sub_job->id)
                        ->decrement('qty_in_hand', $request->dispatch_item_qty[$sub_job->id]);                           
                    }
   
                }
            }
24 May
1 month ago

zaster left a reply on Choose Whether To Keep The Result Of A Calculation As A Column In A Database Table

@willjohnathan

@willjohnathan

SubJob.php

protected static function boot() {
    parent::boot();

    static::saving(function($model){
        $model->qty_remaining = $model->qty - $model->qty_in_hand;
    }); 
}

DispatchController.php store method

        $shortage = SubJob::where('job_id', $request->job_id)->get()->where('qty_remaining',  '<', 1)->all();
        //dd($shortage);

but i am unable to do something like this

DispatchController.php store method

foreach($sub_jobs as $sub_job)
{
//Select each sub_job and use the dispatch_item_qty to decrease the qty remaining of each sub_job                
DB::table('sub_jobs')
->where('id', $sub_job->id)
->decrement('qty_remaining', $request->dispatch_item_qty[$sub_job->id]);    
}

getting this error

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'qty_remaining' in 'field list' (SQL: update `sub_jobs` set `qty_remaining` = `qty_remaining` - 1 where `id` = 3)

zaster left a reply on Choose Whether To Keep The Result Of A Calculation As A Column In A Database Table

@willjohnathan

I did that and

        $shortage = SubJob::all()->where('qty_remaining',  '<', 10)->all();
        dd($shortage);

but i am unable to something like this

DispatchController.php

foreach($sub_jobs as $sub_job)
{
//Select each sub_job and use the dispatch_item_qty to decrease the qty remaining of each sub_job                
DB::table('sub_jobs')
->where('id', $sub_job->id)
->decrement('qty_remaining', $request->dispatch_item_qty[$sub_job->id]);    
}

getting this error

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'qty_remaining' in 'field list' (SQL: update `sub_jobs` set `qty_remaining` = `qty_remaining` - 1 where `id` = 3)

zaster left a reply on Choose Whether To Keep The Result Of A Calculation As A Column In A Database Table

@willjohnathan

Tried the above as

        $shortage = SubJob::where('qty_remaining',  '<', 10)->get();
        dd($shortage);
SQLSTATE[42S22]: Column not found: 1054 Unknown column 'qty_remaining' in 'where clause' (SQL: select * from `sub_jobs` where `qty_remaining` < 10) 
23 May
1 month ago

zaster left a reply on Single Code Base - Multiple Projects

What about maintaining the modular structure. As i read , it seems important

22 May
1 month ago

zaster started a new conversation Single Code Base - Multiple Projects

Assume that i have developed a large application using laravel (A)

Now there are smaller projects which i need to create(B, C, D) and i need to re-use the codebase of A to create them

With time i will be upgrading my single code base (A)

at the same time i will have to do the upgrade B , C, and D etc..

What kind of approach should i take to achieve this ?

I think the below topics are related multi tenancy modular code git branches

zaster left a reply on Choose Whether To Keep The Result Of A Calculation As A Column In A Database Table

@tykus

I am doing something like this (Already having qty_remaining field in the table)

foreach($sub_jobs as $sub_job)     
            {                
                                
                //Select each sub_job and use the dispatch_item_qty to decrease the qty remaining of each sub_job                
                DB::table('sub_jobs')
                ->where('id', $sub_job->id)
                ->decrement('qty_remaining', $request->dispatch_item_qty[$sub_job->id]);
                
            }

So what you are saying is to avoid having the qty_remaining field and instead do something like this


$orders = DB::table('sub_jobs')
                ->selectRaw('*, qty - qty_in_hand` AS qty_remaining)
                ->get();

foreach($sub_jobs as $sub_job)     
            {             
                                
                //Select each sub_job and use the dispatch_item_qty to decrease the qty remaining of each sub_job                
                DB::table('sub_jobs')
                ->where('id', $sub_job->id)
                ->decrement('qty_remaining', $request->dispatch_item_qty[$sub_job->id]);
                
            }

zaster started a new conversation Choose Whether To Keep The Result Of A Calculation In A Database Table

qty_remaining = qty - qty_in_hand

Usually qty_remaining field is not supposed to be in a table

But what if i need to access it easily and i prefer to see the value of qty_remaining when i look at the table data

I like to keep the qty_remaining field

What are your thoughts on this

21 May
1 month ago

zaster started a new conversation ->withDefault(); Belongs To Many - Workaround ?

Is there a workaround to run

->withDefault();

in

BelongsToMany

15 May
2 months 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
2 months 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
2 months 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
2 months 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
2 months 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
2 months 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
2 months 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
2 months 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