zaster

zaster

Member Since 3 Years Ago

Experience Points 10,010
Experience Level 3

4,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 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.

22 Mar
1 day ago

zaster started a new conversation Translate <br /> To New Lines

<td>
{{ nl2br($sub_job->note) }}
</td>

outputs content with ```<br />```

What i want is to display them with line breaks such as

Line 1 Line 2 Line 3

zaster started a new conversation Old Value Of Select Works But

<select class="form-control" name="user" id="user">
                                            <option value="0" disable="true" selected="true">Select Customer</option>                                                                                                                                               
                                            @foreach($users as $user)
                                                 <option value="{{ $user->id }}" {{ old('user',$user->id) == $user->id  ? 'selected' : '' }}>{{$user->name}}</option>                                                 
                                            @endforeach    
                                        </select>

When the page loads for the first time, the last option of the select menu is selected

Also the old value is selected only when the validation is failed

zaster started a new conversation Old Value Of Select

Old value is not selected for the below mentioned code

     <select class="form-control" name="user" id="user">                                      
         @foreach($users as $user)
             <option value="{{ $user->id }}" {{ old('user',$user->id)=='user' ? 'selected' : '' }}>{{$user->name}}</option>                                                
         @endforeach    
     </select>

21 Mar
2 days ago

zaster started a new conversation Method Delete Does Not Exist.

            if ($cost_item->status == 0) {                           
                $po_item = POItem::where('cost_item_id', $cost_item->id)->get();               
                $po_item->delete();
                $cost_item->delete();
            }

I am getting this error

Method delete does not exist.

zaster left a reply on UpdateOrCreate - Accessing A Dynamic Property

@mulugu

I think it is due to some refresh issue

Everything works fine now

20 Mar
3 days ago

zaster left a reply on UpdateOrCreate - Accessing A Dynamic Property

@mulugu

POItem Class already has

protected $guarded = [];

zaster started a new conversation UpdateOrCreate - Accessing A Dynamic Property

This works

        $cost_items = CostItem::where('status', 0)->get();
        foreach ($cost_items as $cost_item) {
            $job = $cost_item->job;
            if($job->status == "Production")
                {   
                                    
                    $po_item = POItem::updateOrCreate(
                        ['cost_item_id' => $cost_item->id],
                        ['vendor_company_id' => $cost_item->vendor_company_id, 'qty' => $cost_item->qty, 'rate' => $cost_item->rate, 'description' => $cost_item->description]
                    );
                }                
        }

This doesn't


    $cost_items = CostItem::where('status', 0)->get();
    foreach ($cost_items as $cost_item) {
        $job = $cost_item->job;
        if($job->status == "Production")
            {   
                                
                $po_item = POItem::updateOrCreate(
                    ['cost_item_id' => $cost_item->id],
                    ['vendor_company_id' => $cost_item->po_item->vendor_company_id, 'qty' => $cost_item->qty, 'rate' => $cost_item->rate, 'description' => $cost_item->description]
                );
            }                
    }

```'vendor_company_id' => $cost_item->po_item->vendor_company_id,```

zaster started a new conversation Best Database Column Type For Values From 0 To 20

I am using this

$table->tinyInteger('status')->default(1);

But i am unable to do something like this

$table->tinyInteger('status', 20)->default(1);
14 Mar
1 week ago

zaster started a new conversation Many Statuses And Many Logic

I have around 10 statuses for a job such as Pending , Completed , Delivered, Paid etc..

There are specific logic to be written for these statuses in different areas (InvoiceController, POController etc...)

Some logic should be written like

Execute these commands after any status which comes after the Pending status.

I thought of using numbers as values of status so that i could do something like

if($status > 1){
 //code
}

What do you think? What kind of approaches should i take? Any good resources that i should refer to?

13 Mar
1 week ago

zaster left a reply on Images Not Appearing In Production - Laravel Snappy

@cronix

This public_path is used only to generate the pdf.

The user clicks on the PDF button and the pdf is generated

Is it still a security risk?

As i know there is no way to get the html output am i right?

zaster left a reply on Many To Many - Creating A Model For The Pivot Table To Get More Control ?

Went through the documentation and got the answer. I was wondering about the naming convention of the pivot model

UserRole

makes sense

RoleUser

is in alphabetical order

zaster started a new conversation Many To Many - Creating A Model For The Pivot Table To Get More Control ?

Is it ok to create a model like role_user and do things like

RoleUser::find($id);

etc...

to get more control ? Is this a better approach or am i missing something?

zaster left a reply on Images Not Appearing In Production

I was able to solve this issue by replacing asset() to public_path()

https://github.com/barryvdh/laravel-snappy/issues/276

zaster left a reply on Images Not Appearing In Production

@nanadjei2

Checked that too. No issue with that.

zaster left a reply on Images Not Appearing In Production

@johnbraun

Nope. That didn't work, i have configured the permission.

zaster left a reply on Images Not Appearing In Production

@johnbraun

What is the recommended permissions for the folder

zaster started a new conversation Images Not Appearing In Production

<img src="{{ asset('images/logo.jpg') }}" alt="logo" height="126px" width="272.5px" /> 

I am using Laravel Snappy and the above works in the Development Environment, but doesn't work in the Production Environment

Development Environment

logo.jpg is stored in

project\public\images

Production Environment

ran

php artisan storage:link
12 Mar
1 week ago

zaster started a new conversation Alternative To $loop->last At Controller

I need to get the last iteration of a foreach at the controller level. How can i do this

11 Mar
1 week ago

zaster left a reply on Getting The Address Field(textarea) As It Is

@snapey Thank you very much for that advice

zaster left a reply on Getting The Address Field(textarea) As It Is

@snapey @cronix

Both of your answers

{!! nl2br( e($textarea)) !!}
{!! nl2br($textarea) !!}

$tykus Since the original question didn't mention anything about generating pdf , i am awarding the best asnwer to you

Special Thanks goes to @snapey and @cronix for helping me out on the pdf generation part

Thank you guys :)

zaster left a reply on Changing Config File Time To Time Development Environment To Production Environment

@snapey

Tried this - The simplest

First Try - Not working

.env

PDF_BINARY="C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf.exe"   
IMAGE_BINARY="C:\Program Files\wkhtmltopdf\bin\wkhtmltoimage.exe"

config\snappy.php

        'pdf' => array(
        'enabled' => true,
        'binary' => env('PDF_BINARY'),
        'timeout' => false,
        'options' => array(),
        'env'     => array(),
    ),

    'image' => array(
        'enabled' => true,
        'binary' => env('PDF_BINARY'),
        'timeout' => false,
        'options' => array(),
        'env'     => array(),
    ),

Second Try - What you suggested - Not working

.env

PDF_BINARY="C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf.exe"   
IMAGE_BINARY="C:\Program Files\wkhtmltopdf\bin\wkhtmltoimage.exe"

config\snappy.php

        'pdf' => array(
        'enabled' => true,
        'binary' => env('PDF_BINARY'),
        'timeout' => false,
        'options' => array(),
        'env'     => array(),
    ),

    'image' => array(
        'enabled' => true,
        'binary' => env('PDF_BINARY'),
        'timeout' => false,
        'options' => array(),
        'env'     => array(),
    ),
10 Mar
1 week ago

zaster left a reply on Getting The Address Field(textarea) As It Is

@tykus or @snapey

Since i am using it on a pdf, Once the pdf is generated there are <br />

i tried this to take out the <br /> and add line breaks but only the <br /> was taken out , no line breaks were added

{{str_replace('<br />', PHP_EOL, nl2br($textarea)) }}

zaster left a reply on Getting The Address Field(textarea) As It Is

@tykus

There is a textarea field where the user should type their address.

E.g.

No 15, Some Street, Some City.

When this is submitted, it will store in the database as

No 15,\nSome Street,\nSome City.

I need to retrieve this address from the database and show it in a pdf

No 15,
Some Street,
Some City.

Should be shown in the pdf

zaster left a reply on Getting The Address Field(textarea) As It Is

@tykus

So the address field in the database will look like this

No 1\n Some street\n Some City

but how to insert a \n as a hidden field ?

zaster started a new conversation Getting The Address Field(textarea) As It Is

Is it possible to have an address field format stored in to a database and retrieve the same as it is, instead of having street, city etc..

zaster left a reply on Changing Config File Time To Time Development Environment To Production Environment

@snapey

In the Development Environment

PDF_BINARY="C:\Program Files\wkhtmltopdf\bin\wkhtmltopdf.exe"
IMAGE_BINARY="C:\Program Files\wkhtmltopdf\bin\wkhtmltoimage.exe"

then in Production Environment

PDF_BINARY=base_path('vendor/h4cc/wkhtmltopdf-amd64/bin/wkhtmltopdf-amd64')
IMAGE_BINARY=base_path('vendor/h4cc/wkhtmltopdf-amd64/bin/wkhtmltopdf-amd64')

zaster left a reply on Changing Config File Time To Time Development Environment To Production Environment

@snapey

```.env````

PDF_BINARY=           
IMAGE_BINARY=

snappy.php

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

Tried this but couldn't get it to work.

zaster started a new conversation Changing Config File Time To Time Development Environment To Production Environment

I am using laravel-snappy to generate pdfs

When i shift from production to development environment vice versa, i have to change its configuration file time to time (snappy.php which is located in the config folder)

Is there a method to have the .env file setup or any other way so that i don't need to change the config file time to time?

08 Mar
2 weeks ago

zaster started a new conversation Date Format Issue

{{$po->date}}

works fine but

{{$po->date->format('m/d/Y')}}

Gives this error

Call to a member function format() on string 

zaster left a reply on Getting The Sum Of Qty * Rate

@dragoneyes96

and in the view

                        {{$po_totals[$po->id]}}

zaster left a reply on Getting The Sum Of Qty * Rate

@snapey

It worked in the view

How can i do this at the Controller

Tried something like this

        //Calculate the total of each po
        $po_totals = [];
                foreach ($pos as $po) { 
                    $po_total = 0;
                    foreach ($po->po_items as $po_item) {
                        $item_total = $po_item->qty * $po_item->rate; 
                        $po_total += $item_total;
                    }
                    $po_totals = $po_total;
                }
                //dd($po_total);
                //dd($po_totals);
        return view('employees.pos.po', compact('pos', 'po_totals'));

zaster left a reply on Cannot Use A Scalar Value As An Array

@resin Thank you very much :)

zaster left a reply on Cannot Use A Scalar Value As An Array

@resin

$po_items = [];
        foreach($cost_items as $cost_item){
            if ($cost_item->status == 0) {
                $po_items[] = $cost_item->po_item;                
             }
        }
        
        if (count($po_items) == 0) {
            return redirect()->route('employee.poitem.pending');
        }
 if (count($po_items) == 0) {   

Will also work right ? I tested , and no issue

zaster started a new conversation Getting The Sum Of Qty * Rate

                        @foreach ($po->po_items as $po_item)                                                                        
                          {{$po_item->qty * $po_item->rate}}             
                        @endforeach   

How can i get the total value of a po , which is equal to the sum of $po_item->qty * and $po_item->rate

zaster started a new conversation Cannot Use A Scalar Value As An Array

I want to do something like this

$po_items = 0;
        foreach($cost_items as $cost_item){
            if ($cost_item->status == 0) {
                $po_items[] = $cost_item->po_item;                
             }
        }
        
        if ($po_items == 0) {
            return redirect()->route('employee.poitem.pending');
        }

When nothing is there in $po_items[] is empty i need to redirect to the below named route

The error comes when it goes through the first if statement

07 Mar
2 weeks ago

zaster left a reply on Remove Null From A Collection

@talinon

oops! sorry about that.

It works nicely :)

Thank you very much

zaster left a reply on Remove Null From A Collection

@talinon

tried it still the same

$po_items->filter(function ($value) { return !is_null($value); });

         dd($po_items);

results

Collection {#475 ▼
  #items: array:3 [▼
    0 => POItem {#620 ▶}
    1 => null
    2 => POItem {#681 ▶}
  ]
}   

zaster started a new conversation Remove Null From A Collection

My Collection looks like this

Collection {#475 ▼
  #items: array:3 [▼
    0 => POItem {#620 ▶}
    1 => null
    2 => POItem {#681 ▶}
  ]
}

I need to take out the nullentry

zaster left a reply on Trying To Get Property 'qty' Of Non-object

Collection {#475 ▼
  #items: array:3 [▼
    0 => POItem {#620 ▶}
    1 => null
    2 => POItem {#681 ▶}
  ]
}

the issue comes when there is a null record in the array

zaster started a new conversation Trying To Get Property 'qty' Of Non-object

  $total_po_value = $po_items->sum(function($item){
            return $item->qty * $item->rate;
        });

Sometimes returns this error

Trying to get property 'qty' of non-object

zaster left a reply on Getting Latest Entries In A Collection

Try this

File::latest()->get();

zaster left a reply on Pass A Collection From View To Controller Through Post Method

@tray2

I was overdoing things , this code really doesn't make sense.

I am sorry for wasting your time

06 Mar
2 weeks ago

zaster left a reply on Trying To Get Property 'cost_item' Of Non-object

@roerjo

That didn't work out. I thought of making it go through one iteration like this. Problem solved

@foreach ($po->po_items as $po_item)
                        @if ($loop->first)
                          {{$po_item->cost_item->vendor_company->name}}                        
                        @endif
                      @endforeach   

zaster started a new conversation Pass A Collection From View To Controller Through Post Method

The below view only displays values. I need to pass $po_items collection through post method Is this possible?

<form action="{{route('employee.po.store')}}" method="post">
            {{ csrf_field() }} 
            <table class="table">
                    <thead>
                        <tr>
                            <th>Vendor</th>
                            <th>Item</th>
                            <th>Qty</th>
                            <th>Rate</th>
                            <th>Total</th>
                            <th>Description</th>
                            <th>Job No</th>
                        </tr>

                    </thead>
                    <tbody>

                        @foreach ($po_items as $po_item)
                            <tr>
                                <td>{{$po_item->cost_item->vendor_company->name}}</td>
                                <td>{{$po_item->cost_item->item->name}}</td>
                                <td>{{$po_item->qty}}</td>
                                <td>{{$po_item->rate}}</td>
                                <td>{{$po_item->qty * $po_item->rate}}</td>
                                <td>{{$po_item->description}}</td>
                                <td>{{$po_item->cost_item->job_id}}     
                            </tr>
                        @endforeach 
                    </tbody>                                
                </table>                
                <button type="submit" class="btn btn-primary">Submit</button>                                           
        </form>  

zaster started a new conversation A Better Way To Access Values Of Far Away Tables

                        @foreach ($po->po_items as $po_item)
                          @foreach ($po_item->cost_item->job->sub_jobs as $sub_job)
                            @foreach($sub_job->user->companies as $company)
                            {{$company->name}}
                             @endforeach
                          @endforeach                          
                        @endforeach 

This is done in the view, we can have the logic inside the controller instead of view to get better readability as i understand. But is there any other ways of accessing values of far away tables ?

zaster left a reply on Trying To Get Property 'cost_item' Of Non-object

ok. This worked!

    @foreach ($po->po_items as $po_item)
                          {{$po_item->cost_item->vendor_company->name}}
                      @endforeach  

zaster left a reply on Sum Of Two Fields In A Collection Array

@cronix

Thank you very much. Your answer worked :)

My issue is that i am confuse with the below

collection of arrays, or a collection of objects?

also

The way you have used $item

zaster started a new conversation Trying To Get Property 'cost_item' Of Non-object

POController.php

     $pos = PO::all();
     $pos->load(['po_items.cost_item.vendor_company']);
     //dd($pos);

po.blade.php

 @foreach ($pos as $po)                      
                  <tr>
                    <td>{{$po->id}}</td>
                    <td>{{$po->date}}</td>
                    <td>{{$po->po_item->cost_item->vendor_company->id}}</td>
..
..
@endforeach

dd($pos) shows all the collections with relations without any issue

but when i try to view this page. I am getting this error

Trying to get property 'cost_item' of non-object

Relationships are as below mentioned

po hasMany po_items po_item belongsTo cost_item cost_item belongsTo vendor_company

zaster left a reply on Updating A Table Property Through A Relationship

         foreach ($po_items as $po_item) {
            $po_item->status = 1;
            $po_item->cost_item()->update(['status' => 1]);
            $po_item->save();
        }

Worked! Thank you @

zaster started a new conversation Updating A Table Property Through A Relationship

I have tried this and it worked for po_items but not for cost_items. I didn't try the regular way for cost_items yet

         foreach ($po_items as $po_item) {
            $po_item->status = 1;
            $po_item->cost_item->status = 1;
            $cost_item->save();
            $po_item->save();
        }

is there any easy way of doing something like the above mentioned

##po_item and cost_item has a one to one relationship##