zaster

zaster

Member Since 4 Years Ago

Experience Points
13,340
Total
Experience

1,660 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,340 XP
Nov
12
6 days ago
Activity icon

Replied to "Class 'App\Events\NewJobHasRegisteredEvent' Not Found"

@sinnbeck very important link. Thank you very much.

Activity icon

Replied to "Class 'App\Events\NewJobHasRegisteredEvent' Not Found"

@sinnbeck and it worked.

Thank you very much.

Activity icon

Replied to "Class 'App\Events\NewJobHasRegisteredEvent' Not Found"

@sinnbeck

yes. I think that should be the answer.

use App\Events\NewJobHasRegisteredEvent;    

should be

use App\Events\newJobHasRegisteredEvent;

I will try that. It should work.

Activity icon

Replied to "Class 'App\Events\NewJobHasRegisteredEvent' Not Found"

@nakov

That is also included

NewJobHasRegisteredEvent.php

<?php

namespace App\Events;

use Illuminate\Broadcasting\Channel;
use Illuminate\Queue\SerializesModels;
use Illuminate\Broadcasting\PrivateChannel;
use Illuminate\Broadcasting\PresenceChannel;
use Illuminate\Foundation\Events\Dispatchable;
use Illuminate\Broadcasting\InteractsWithSockets;
use Illuminate\Contracts\Broadcasting\ShouldBroadcast;

class newJobHasRegisteredEvent
{
    use Dispatchable, InteractsWithSockets, SerializesModels;

    public $job;
    /**
     * Create a new event instance.
     *
     * @return void
     */
    public function __construct($job)
    {
        $this->job = $job;
    }

    /**
     * Get the channels the event should broadcast on.
     *
     * @return \Illuminate\Broadcasting\Channel|array
     */
    public function broadcastOn()
    {
        return new PrivateChannel('channel-name');
    }
}
Activity icon

Replied to "Class 'App\Events\NewJobHasRegisteredEvent' Not Found"

EventServiceProvider.php

Looks like this

<?php

namespace App\Providers;

use App\Events\newJobHasRegisteredEvent;
use Illuminate\Support\Facades\Event;
use Illuminate\Foundation\Support\Providers\EventServiceProvider as ServiceProvider;

class EventServiceProvider extends ServiceProvider
{
    /**
     * The event listener mappings for the application.
     *
     * @var array
     */
    protected $listen = [
            newJobHasRegisteredEvent::class => [
            \App\Listeners\JobFormMailListener::class,
        ],
    ];

    /**
     * Register any events for your application.
     *
     * @return void
     */
    public function boot()
    {
        parent::boot();

        //
    }
}

Everything works perfectly fine in the development environment. When it comes to Production it gives this error

"Class 'App\Events\NewJobHasRegisteredEvent' not found"
Activity icon

Replied to "Class 'App\Events\NewJobHasRegisteredEvent' Not Found"

@sinnbeck I have already checked that. Not that either.

Activity icon

Replied to "Class 'App\Events\NewJobHasRegisteredEvent' Not Found"

@sinnbeck

Nope. I tried that , still the same error. I think it has something to with setting up queues in the production environment

Activity icon

Started a new Conversation "Class 'App\Events\NewJobHasRegisteredEvent' Not Found"

I am getting the below mentioned error only in the production environment

"Class 'App\Events\NewJobHasRegisteredEvent' not found"

jobcontroller.php

use App\Events\NewJobHasRegisteredEvent;

class JobController extends Controller
{

.
.
    public function store(Request $request)
    {

    .
    .
    event(new NewJobHasRegisteredEvent($job));
    return redirect('job');
     }
}

This runs fine in the development environment

I think its something to do with Queues in the production environment

because

php artisan queue:work 

shows nothing in the production environment

Nov
05
1 week ago
Activity icon

Started a new Conversation Is It A Good Idea To Develop All Web Based Projects Using REST API

Is it a good idea to develop all web based projects using REST API?

Nov
01
2 weeks ago
Activity icon

Started a new Conversation Php 7.2 To Php 7.3 - Upgrade

I thought of upgrading my php version from php 7.2 to php 7.3 because i need to start using the latest laravel version (Laravel 6)

Will this effect my older projects (uses Laravel 5.3 +)

Aug
17
3 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
4 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
4 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
5 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
5 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
5 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
5 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
5 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
5 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
5 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
5 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
5 months ago
Activity icon

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

Is there a workaround to run

->withDefault();

in

BelongsToMany