Screenbeetle

Screenbeetle

Member Since 4 Years Ago

Heart is still in Bristol

Freelance Web Developer at home in Norwell

Experience Points 55,420
Experience Level 12

4,580 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 307
Lessons
Completed
Best Reply Awards 37
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.

09 May
1 month ago

Screenbeetle left a reply on How Can I Decrease Stocks Base On Order Quantity

Hi @emfinanga ... what is the name of the field you want to deduct from in your $stock model?

decrement can have two args. The first arg is the field you want to deduct from and the second argument is the quantity you want to deduct. E.g.

$quantityToDeduct = 4;
$stock->decrement('fieldName', $quantityToDeduct);
29 Mar
2 months ago

Screenbeetle left a reply on Mail::to Sometime Work And Sometime Not

do you have any errors in your error log? What service are you using?

Screenbeetle left a reply on How Can I Decrease Stocks Base On Order Quantity

no problem.

You need to chain where clauses together

 ProductsAttribute::where('product_id',  $pro->product_id)->where( 'size', $pro->size)->decrement('stock', $pro->quantity)

Screenbeetle left a reply on How Can I Decrease Stocks Base On Order Quantity

ok so you mean $productDetails is returning null .... what do you see if you dd($productDetails);?

You cart query is the problem. Without seeing your structure it's hard to know but some things to consider

1 - is $user_email populated? 2 - is there a cart record matching the email address?

Also - do you have each product recorded in your carts table? It's more common to have a carts and a cart_items table for the actual products

Screenbeetle left a reply on How Can I Decrease Stocks Base On Order Quantity

You could just decrement within the loop no?

foreach( $productDetails as $pro) {
    ProductsAttribute::where('product_id',  $pro->product_id)->decrement('stock', $pro->quantity);
}
28 Mar
2 months ago

Screenbeetle left a reply on Unable To Login To Mysql Using User Created Through Laravel Forge

Yeah ok that's odd. Assuming you've double checked you're using the right password then I can only suggest some basics:

  1. Have you checked inside MySql if the test user exists? As in login as forge user and run

SELECT User FROM mysql.user;

  1. Have you tried creating the user within MySql?

Screenbeetle left a reply on Unable To Login To Mysql Using User Created Through Laravel Forge

You may be confusing your Linux / ssh user with your MySql users - by default they are both called forge. Even if you set up new database user you'll still need to use your forge user to ssh into the server.

Screenbeetle left a reply on How Can I Decrease Stocks Base On Order Quantity

Evening

Sorry what's the issue exactly? If stock is an int then ->decrement('stock',$quantity); should work. Are you getting errors?

27 Mar
3 months ago

Screenbeetle left a reply on Php Artisan Now Throwing A PHP Fatal Error On Laravel 5.7.26

Have you tried running composer update ... composer dump-autoload etc?

26 Mar
3 months ago

Screenbeetle left a reply on Routes Folder Missing

it sounds like your install went wrong. Might be best to start again with a fresh install.

22 Mar
3 months ago

Screenbeetle left a reply on Mailable Vs Notificable

yes if you set them in config it should pick them up by default. If you're using ssl do you not need to provide your username and password too?

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com #or ssl://smtp.gmail.com
MAIL_PORT=465
MAIL_USERNAME=gmail_username
MAIL_PASSWORD=gmail_password
MAIL_ENCRYPTION=ssl

or 

MAIL_DRIVER=smtp
MAIL_HOST=smtp.gmail.com #or ssl://smtp.gmail.com
MAIL_PORT=587
MAIL_USERNAME=gmail_username
MAIL_PASSWORD=gmail_password
MAIL_ENCRYPTION=tls

Screenbeetle left a reply on Mailable Vs Notificable

Are the headers the same for both mail types? Send from / reply to etc?

Screenbeetle left a reply on Auth::attempt Method Always Bind With Users Table?

@SNAPEY - yep good point - I think I knew that once .... leaky brain

Screenbeetle left a reply on Disable Url If Page Is Not Published

@LADYDEATHKZN - no problem - feel free to mark the thread as solved :-)

21 Mar
3 months ago

Screenbeetle left a reply on Mailable Vs Notificable

I would say you are using gmail SMTP with ssl enabled. I'm guessing you'll need to fiddle with your settings - maybe MAIL_ENCRYPTION=ssl and or ssl in front of the mail url - MAIL_HOST=ssl://smtp.gmail.com

might help get you started in the right direction

Screenbeetle left a reply on Nginx Laravel And Wordpress

Morning! It is easier to have Laravel in a subdomain app.website.com. This way you can have a standard Laravel install without changing paths. If you need it in a subfolder then pls read: https://laravel-news.com/subfolder-install

For Wordpress I suggest two options:

  1. I use Laravel Forge which has a Wordpress install option - very easy.

  2. Digital Ocean comes with a Wordpress install: https://www.wpexplorer.com/install-wordpress-digitalocean/

Also note:

  • Htaccess doesn't work with Nginx
  • I don't think php mail works by default for Digital Ocean's Ubuntu droplets (for Wordpress password reset etc). You will have install Postfix or send mail another way in Wordpress - e.g. smtp

Good luck

Screenbeetle left a reply on How To Make A Printout In Laravel

Hi @abdulbazith ... I'll try to look at your other thread today too. Please first select and answer for this thread if your questions is fixed - you have two good answers above.

20 Mar
3 months ago

Screenbeetle left a reply on Auth Middleware Store Problem No Message

Can you show some code?

You can apply middleware to any route by adding ->middleware('auth');

Route::post('/your-route', '[email protected]')->middleware('auth')
19 Mar
3 months ago

Screenbeetle left a reply on How To Make A Printout In Laravel

Hi @abdulbazith

Using barryvdh/laravel-dompdf have you tried $pdf->stream(); instead of $pdf->download();?

This would open the purchase order as a pdf in the browser without having to download. You can then just click print (and then also save it as a download if you wanted).

My customers either do this or just use a print friendly html page like @Sergiu17 suggested

18 Mar
3 months ago

Screenbeetle left a reply on Disable Url If Page Is Not Published

You may be overthinking this.

One simple option is to have a condition in your PageController's show method (or CmsController's frontPage method as you have it) to check the draft status and have different return statements depending

Firstly its worth noting you can use a url slug as a unique identifier in your page (or cmspage) model. You just need a unique slug field in your pages table and then add this to your model:

public function getRouteKeyName()
{
    return 'slug';
}

at this point Laravel route model binding will get the model from the slug instead of id.

 // you have this as frontPage($url) but it seems like a show method
public function show(Page $page)
{ 
    if($page->status == 'draft){
        return redirect('somewhere');
    }

    return view('frontend.frontpage', compact('page')); 
} 

Screenbeetle left a reply on Should I Define Mysql Relations When Using Alequent

Hi @nikos

isn't that adding foreign keys to SQL actually, just via migrations yes that's right

Screenbeetle left a reply on Should I Define Mysql Relations When Using Alequent

Morning @kisaw88

.. @nikos is correct but just to add you can still add foreign key relations in Laravel. You do this in the migrations. You can see examples in the docs here: https://laravel.com/docs/5.8/migrations#foreign-key-constraints

Screenbeetle left a reply on Laravel Snappy PDF - Loading External/Internal CSS - Tailwindcss If Possible

I've had a nightmare with this also last year. You might find something helpful in here: https://github.com/barryvdh/laravel-snappy/issues/258

After wasting half a day on it last time I am ashamed to say I just went back to building my pdf using tables and inline css. I'm planning another go soon so I'll report back if I get anywhere. Be keen to see what solutions you come up with to

16 Mar
3 months ago

Screenbeetle left a reply on Auth::attempt Method Always Bind With Users Table?

Evening.

By default Laravel Auth uses the users table. Do you want to rename the users table? Here is a good tutorial based on Laravel 5.3 (so may be a little out of date): https://www.youtube.com/watch?v=Aso3e_lQju4

Or do you want Auth::attempt to check more than one table? That's not possible. It just lets you check extra fields on 1 users table e.g. Auth::attempt(['username' => $username, 'password' => $password, 'email_confirmed' => 1]))

Screenbeetle left a reply on Tracking Visitors Of Specific Url

I've not used it before but one option is the Google Analytics API. This Laravel Package is a wrapper for it: https://github.com/spatie/laravel-analytics

I guess you'll need data for specific urls relating to your business customers. I image this is possible but you'll need to have a play. This tool may help explore api queries: https://ga-dev-tools.appspot.com/query-explorer/

Screenbeetle left a reply on Laravel Accessor Appends Not Working As Expected / Strange Behavior

Sorry @jaheller - I'm am at a kids party so it's hard to answer ..

I don't think you need an accesser here - just a method to get the currentLevel. Can you not just define the three relations and then do the logic to return either vendor or user level in one method? Something like:

public function vendorUser()
{
    return $this->hasOne('App\VendorUser');
}

public function vendorLevel()
{
    return $this->hasOne('App\VendorLevel');
}

public function userLevel()
{
    return $this->hasOne('App\UserLevel');
}

public function currentLevel(){

    // if condition here for what comes back on $this->vendorUser
    // then return either $this->vendorLevel or $this->userLevel
 }

Screenbeetle left a reply on Laravel Accessor Appends Not Working As Expected / Strange Behavior

Passing a value like that is just the laralavel suggested way of doing it: https://laravel.com/docs/5.8/eloquent-mutators#defining-an-accessor

Things do look overly complicated in your model there. Your accessor is returning the hasOne relation at the moment where it should be returning a simple field value. Is the field you want to get on VendorUser? If so then your accessor should be on that VendorUser model not user.

15 Mar
3 months ago

Screenbeetle left a reply on Where To Put Workflow Code

Hi @christiant

I think you'll struggle to get many replies with questions as broad as this - it's a lot to take in!

You'll be better off breaking questions into smaller bite-sized pieces and showing some code. A lot of the weirdos on this forum can make more sense of code than big blocks of text - myself included :-)

Screenbeetle left a reply on Error Messages In Request Validation

It looks like you have two error loops. There is one in the code above. Is there another loop above this code - maybe in the parent view if this is a partial?

Screenbeetle left a reply on Laravel-snappy And Many Different Views

Sorry @cemcminn - the question is a bit unclear

When you say

The tutorial shows building the data from one source by finding it again in the above method call and it works for the first document I tried, but I won't always need just that one table.

Can you rephrase that - maybe with example code? Do you mean how to pass different table data to the loadView method?

Screenbeetle left a reply on Throw New MethodNotAllowedHttpException($others)

Maybe unrelated but I don't think the form facade needs the separate {{method_field('PATCH')}} statement. You can just add patch instead of Post here:'method' => 'PATCH',

Laravel Collective no longer support the Form facade and pulled the docs .. which makes it a little tricky to cross reference your code.

I do vaguely recall having similar oddball issues with the Forms facade in the past though. My fall back approach is to just rewrite the form not using the facade. Even if this doesn't fix the issue it often helps to rethink and reveal what's going wrong.

Screenbeetle left a reply on Tracking Visitors Of Specific Url

Sorry - why not just use Google Analytics? Or are you asking how to set it up?

Can you add more detail about what you need exactly

Screenbeetle left a reply on Laravel 5.7 Files Merge

Why don't you just zip and download the files using a package like Laravel Zip?

https://github.com/zanysoft/laravel-zip

14 Mar
3 months ago

Screenbeetle left a reply on How Do You Manage A View That Is Getting Big Like This Going Out Of Control?

Yes indeed - use more partials with @includes.

I would start by extracting out your forms. Then also your breadcrumbs and alerts. Remember you can use @yield in partials too - for example to add the current page in your breadcrumb trail.

Screenbeetle left a reply on Career As A Software Developer

If you get the model right you can always become a freelancer later on - or even a small business of your own with a friend or two. Don't expect bliss but you can build up a decent income and be in more control of how and who you work for.

If you want to give the sector a good go I'd personally suggest: -getting the industry expected 2 years working in a job/s first -and then contract for a bit with an Agency.

Contracting is good money but more importantly you get a diverse amount of exposure with different practices. It can still occasionally be mindbogglingly frustrating with indifferent co-workers but it's invaluable experience to help guide you in the direction you want to go in. It may well put you off forever but at least you'll properly know you gave it a good go

I intend to be in the worm cozy womb of retirement in 15years time - but I'm 44 now so probably not a good role model.

12 Mar
3 months ago

Screenbeetle left a reply on Adding Multiple Github Accounts To Forge

Hi @nickdavies07 - did you get a resolution to this by any chance?

Screenbeetle left a reply on Apply Middleware When URL Pattern Matches

Hi @akogler

As you are assuming a logged in user - Auth::user()->id - you ought to Authenticate the UserProjectFit routes as well. At the moment it looks like non logged in users can hit those routes which will throw a property 'id' of error non object error.

If you auth the routes first it will nicely redirect non logged in users without error. You can add multiple middleware by comma separating: ->middleware('Auth', 'UserProjectFit')

11 Mar
3 months ago

Screenbeetle left a reply on Nova Saves File As .bin File

Hello again @emotality - we fixed our project.

For us it was a file upload issue outside of Nova but I think the two issues are the same.

When uploading a file the ->store() method uses Illuminate\Http\UploadedFile. By default this hashes the name and then tries to add back the extension by working out the mime type from the contents of the file itself - which doesn't always work. The docs explain it like this:

The UploadedFile class also contains methods for accessing the file's fully-qualified path and its extension. The extension method will attempt to guess the file's extension based on its contents. This extension may be different from the extension that was supplied by the client

https://laravel.com/docs/5.8/requests#files

The fix for us was to use the storeAs method instead and use the original extensions as part of the name:

->storeAs(
                'files',
                sha1(time()) . '.' . $file->getClientOriginalExtension()
            );

As Nova also uses Illuminate\Http\UploadedFile you should be able to add an override in your model to use storeAs in the same way - something like:

public function fields(Request $request)
{
        return [
          
            File::make('File')
                ->storeAs(function (Request $request) {
                    // something similar to the above
                })
        ];
}

I should credit @edoc for this as he mainly figured it out!

08 Mar
3 months ago

Screenbeetle left a reply on Change Email Template

You'll need to explain more. For example?

Screenbeetle left a reply on Nova Saves File As .bin File

I've got a customer reporting the same issue but only occasionally - 3 cases out of a couple of hundred uploads and all in the last month. In case it helps someone spot a pattern my customer has so far reported 3 issues as follows:

1 Mac Pages document saving as .bin 1 MS Word for Mac saving as .bin 1 PDF saving as a .zip (not quite sure if the user uploaded this by mistake but they swear they didn't :-)

I'll report back if I work out what's happening

07 Mar
3 months ago

Screenbeetle left a reply on Adding Multiple Github Accounts To Forge

@nickdavies07 - I'm going to help bump this as I've been having the same issue this week on Forge / Digital Ocean. I've tried all that suggestions that come up in searches - as you seem to have - but nothing gives .. I get the same error as you.

My work around at the moment is just to ssh into the server and do a https based git clone to set up the repo and then git pull to deploy. That works but it's a hassle

Screenbeetle left a reply on Cloning Repo On Forge Error - Sed: -e Expression #1, Char 42: Unknown Option To `s'

Possible long shot but I wonder if it's related to this: https://laracasts.com/discuss/channels/laravel/beware-in-env-files

It seems to be failing at the point where it encounters a #

Screenbeetle left a reply on Move A File From Public/upload Folder To S3 Server

If you want to automate your backups then you can use [https://github.com/spatie/laravel-backup].

This will zip and store your database and/or directories to S3. Once set up you you can set several backup routines through theapp/Console/Kernal.php -> schedule method. For example once an hour for your database and once a day for your files

06 Mar
3 months ago

Screenbeetle left a reply on What's The Difference Between @yield And @include

Morning

@yield specifies an area in your layout like @yield('content') which your view uses to insert content @section('content') ... @endsection

@include is used to include partials within your views (e.g. @include('layouts.partials.header')

Screenbeetle left a reply on Getting A Collection From A Relationship

if you have the one to one relation set up in your cost item model:

public function poItem()
{
        return $this->hasOne(PoItem::class);
}

then you can loop through cost_items and get the po_item like this:

foreeach($cost_items as $cost_item){
$po_item = $cost_item->poItem->id; // or other field
}

Screenbeetle left a reply on How To Edit Laravel Field Validation Message ?

going down the rabbit hole now :-)

My final comment is to remove the old validation:

public function reponse(CustomRequest $request)
    {
    /* REMOVE THIS - you don't need it now
        $validation = Validator::make($request->all(), [
            'reponse' => 'required',
        ]);
        
        $error_array = array();
        $success_output = '';
        if ($validation->fails())
        {
            foreach ($validation->messages()->getMessages() as $field_name => $messages)
            {
                $error_array[] = $messages; 
            }
        }*/
...

I can't help with debugging the JS error output. I only like to suffer my own JS issues

Screenbeetle left a reply on How To Edit Laravel Field Validation Message ?

this is a classic Laravel / PHP issues. Check:

  • Does it existing in the Http\Requests\CustomRequest?
  • Have you name spaced it correctly?
  • Have you included it in the controller use App\Http\Requests\CustomRequest

etc

Screenbeetle left a reply on How To Edit Laravel Field Validation Message ?

Sorry @PhoeniX5 - this is a little rushed but something like this:

// This approach validates outside the controller so take out all validation from your controller
// and just replace with a CustomRequest

public function reponse(CustomRequest $request)
{
    // method stuff
}

then run php artisan make:request CustomRequest:

class CustomRequest extends FormRequest
{
    
    public function authorize()
    {
        return true; 
    }

    /**
     * Get the validation rules that apply to the request.
     *
     * @return array
     */
    public function rules()
    {
        return [
            'reponse' => 'required',
        ];
    }

    public function messages()
    {
        return [
            'reponse.required' => 'The reponse field is required etc',
        ];
    }
}

Any errors are put into the$errors variable. You can then check and display in your view:

@if ($errors->any())
    @foreach ($errors->all() as $error)
        {{ $error }}<br>
    @endforeach
@endif