zaster

zaster

Member Since 3 Years Ago

Experience Points
13,070
Total
Experience

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

Level 3
13,070 XP
Aug
17
2 months ago
Activity icon

Replied to Displaying Only Unique Values

@bobbybouwmann

I already tried that before posting my question

Example

1st sub_job->user->name = User A
2nd sub_job->user->name = User B
3rd sub_job->user->name = User B

The output should looks like

User A
User B
Activity icon

Started a new conversation Displaying Only Unique Values

JobController.php

    public function index()
    {     
        $jobs = Job::all();
        return view('jobs.job',compact('jobs'));
     }

job.blade.php

 @foreach ($job->sub_jobs as $sub_job)                                                    
            {{$sub_job->user->name}}<br>                             
@endforeach

When there are multiple sub_jobs the name of the user will be repeated I only want to display the unique names

Jun
26
3 months ago
Activity icon

Replied to 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. :)

Activity icon

Replied to Automatic Backup Is Not Working

I did a

php artisan cache:clear

but still nothing

Activity icon

Replied to 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
Jun
25
3 months ago
Activity icon

Started a new conversation Automatic Backup Is Not Working

I am using Laravel 5.5 with Spatie Backup

I need to do something like this

app\Console\Kernel.php

    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

Jun
06
4 months ago
Activity icon

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

Activity icon

Replied to Creating A Model B Inside Model A

@okusax

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

Jun
05
4 months ago
Activity icon

Started a new conversation Creating A Model B Inside Model A

In inovice.php

I have a function as below mnetioned

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

Jun
01
4 months ago
Activity icon

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() 
May
29
4 months ago
Activity icon

Replied to Snappy PDF Suddenly Stopped Working - Windows

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

Activity icon

Replied to 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.

Activity icon

Started a new conversation Snappy PDF Suddenly Stopped Working - Windows

I am using Snappy PDF(Windows 10 Local Development)

wkhtmltopdf --version
wkhtmltopdf 0.12.5 (with patched qt)

snappy.php file looks like this

<?php

return array(


    'pdf' => array(
        'enabled' => true,
        'binary' => '"C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf.exe"',
        'timeout' => false,
        'options' => array(),
        'env'     => array(),
    ),
    'image' => array(
        'enabled' => true,
        'binary' => '"C:\Program Files\wkhtmltopdf\bin\wkhtmltoimage.exe"',
        'timeout' => false,
        'options' => array(),
        'env'     => array(),
    ),

 );

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]" 
May
28
4 months ago
Activity icon

Started a new conversation How To Avoid Creating A Blank Dispatch

dispatches M------------N 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]);                           
                    }
   
                }
            }
May
24
4 months ago
Activity icon

Replied to Choose Whether To Keep The Result Of A Calculation As A Column In A Database Table

@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 because it assumes that a qty_remaining field exists in sub_jobs table

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)
Activity icon

Replied to 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);

received the below error

SQLSTATE[42S22]: Column not found: 1054 Unknown column 'qty_remaining' in 'where clause' (SQL: select * from `sub_jobs` where `qty_remaining` < 10) 
May
23
4 months ago
Activity icon

Replied to Single Code Base - Multiple Projects

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

May
22
4 months ago
Activity icon

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 upgrade B , C, and D etc.. (Upgrades can be feature upgrades, framework upgrades etc...)

What kind of approach should i take to achieve this ?

I think the below topics are related

multi tenancy

modular code

git branches

Activity icon

Replied to 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)     
{                
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(Use an Alias)

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

foreach($sub_jobs as $sub_job)     
{                              
DB::table('sub_jobs')
->where('id', $sub_job->id)
->decrement('qty_remaining', $request->dispatch_item_qty[$sub_job->id]);          
}
Activity icon

Started a new conversation Choose Whether To Keep The Result Of A Calculation As A Column 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 do you think?

May
21
4 months ago
Activity icon

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

Is there a workaround to run

->withDefault();

in

BelongsToMany

May
15
5 months ago
Activity icon

Replied to 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

Activity icon

Replied to Assign A 0 To A Null Value In A Request Array

@tykus

How can i assign a default value?

Activity icon

Replied to 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 
Activity icon

Replied to 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
Activity icon

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

I wan to do something like this, before the request goes through a validation

    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'));
        }
May
13
5 months ago
Activity icon

Replied to 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'      
            ],            

          ]);


}

Getting the below error

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

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

        $this->validate($request, [

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

          ]);

I want to replace all NULL values of the dispatch_item_qty array by 0

May
12
5 months ago
Activity icon

Replied to 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.

Activity icon

Replied to 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();
Activity icon

Started a new conversation Get All Relations Of A M To N - Before Sending To The View

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;
        }
        
May
11
5 months ago
Activity icon

Replied to 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

dispatch_subjob (represents dispatch_items)

| id  | dispatch_id | sub_job_id | qty |

| 42  | 25 | 3 | 10 
| 43  | 25 | 5 | 20 
@foreach($sub_jobs as $sub_job)
    @foreach ($sub_job->dispatches as $dispatch)      

    Dispathch No : {{$dispatch->no}} <br>
.
.           
                @foreach($dispatch->dispatch_items as $dispatch_item)
                    Dispatch Item Qty :  {{$dispatch_item->qty}} <br>
                @endforeach                                    
    @endforeach
@endforeach
Activity icon

Started a new conversation How To Pass Dispatches To The View In 1-M-N Kind Of Relation

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

I need to do a

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

in the view

How can i get the dispatches?

May
09
5 months ago
Activity icon

Replied to Where Clause - Undefined Variable

@jlrdw

Thanks for the tip

I found the issue and it was due to having similar strings

E.g. -

$comp = "PWC"

$comp = "PW"

Activity icon

Replied to 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();
Activity icon

Started a new conversation Where Clause - Undefined Variable

EDIT: This is what i am trying to achieve

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

I am getting null as the result

what i am expecting is an eloquent model

END EDIT

In order to achive the above i have tried the below




$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();

I am getting this error

Undefined variable: comp
May
08
5 months ago
Activity icon

Started a new conversation Get The First Record And Select A Given Table Column Name In One Line

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

$sub_job = $sub_jobs->first();
$comp = $sub_job->comp;
May
07
5 months ago
Activity icon

Replied to 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. The pivot table in my case represent a dispatch_item

Anyway i still have doubts with the logic and code etc... need to give some more thought to figure it out

Thank you very much for your support

Activity icon

Replied to Array To String Conversion Error

@Snapey

Spot On! :) Thank you very much

Activity icon

Replied to 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' => ???????]);
}
Activity icon

Replied to Array To String Conversion Error

@ftiersch

Each dispatch has multiple quantities

Activity icon

Replied to 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

Activity icon

Replied to 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

Activity icon

Replied to 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])]);  
Activity icon

Replied to Array To String Conversion Error

@foram

 $request->dispatch_item_qty[3]

In my code

3 is generated dynamically

Activity icon

Replied to 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?

Activity icon

Started a new conversation Array To String Conversion Error

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

controller

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

As i understand, the value of dispatch_item_qty should be converted from a string to a numerical value

May
06
5 months ago
Activity icon

Replied to 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